首页 新闻 会员 周边 捐助

URAL 1332 Genie Bomber(挺简单的一道题,可就是不知道错哪儿)

0
悬赏园豆:100 [已关闭问题] 关闭于 2016-04-12 10:23

Description

 

The last survivor was a certain Pitirim Schwartz, an erstwhile monk and inventor of the forked musket rest, who was selflessly laboring on the genie-bomber project. The essence of the project was to drop on the enemy cities bottles with genies who had been held imprisoned no less than three thousand years. It is well known that genies in their free state are capable only of destroying cities or constructing palaces. A thoroughly aged genie, reasoned Schwartz, was not about to start building palaces, and therefore things would go badly for the enemy. A definite obstacle to the realization of this concept was an insufficient supply of bottled genies, but Schwartz counted on overcoming this through the deep dragging of the Red and Mediterranean Seas.

 

The genie-bomber project has eventually entered the experimentation stage. Research fellows’ doubles have constructed N cities in the testing area. Each of these cities is a circle with a radius of r. As M. M. Kamnoedov provided only one bottled genie for the experiment, experimenters decided to demolish as many cities as possible for the sake of science. It is generally known that a genie demolishes everything in the range of R around the bottle’s touchdown point. Any city contained completely within this demolition area is ruined. Before the experiment is conducted, you are required to find the maximum possible number of cities that one genie can ruin.
 
Input
The first line contains the number N of cities (1 ≤ N ≤ 100). The following N lines contain the coordinates x i, y i of city centers (x i, y iare integers, |x i|, |y i| ≤ 10000). City centers don’t coincide with each other.
The last line contains radius R of the genie’s area of destruction and the city radius r (1 ≤ R, r ≤ 10000). R and r are integers.
 
Output
Output the maximum number of cities that can be destroyed by one bottled genie.
 
Sample Input
input        
3
0 0
0 4
4 0
3 1
Output
2

我的思路是先算出两个城市之间的距离以及城市与炸弹的最大圆心距,通过角的关系求出炸弹和其他城市的圆心距,
比较一下,判断能否炸掉
#include <iostream>
#include <algorithm>
#include <string.h> 
#include <math.h>
using namespace std;
int a[105],b[105];
int main()
{
    int n;
    int R,r;
    int i,j,t;
    cin>>n;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(i=1;i<=n;i++)
            cin>>a[i]>>b[i];
        cin>>R>>r;
        int s = R-r;
        int ma;
        if(s<0) ma=0;
        else if(s==0) ma=1;
        else
        {
            int ans;
            ma=1;
            for(i=1;i<n;i++)
            {
                for(j=i+1;j<=n;j++)
                {
                    ans=1;
                    __int64 a1 = (a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]); 
                    double p = (sqrt(a1*1.0)*1.0)/2;
                    if(s*1.0<p) continue;
                    else if(s*1.0>= p && ans==1) 
                    {
                        ans=2;
                        for(t = 1;t<=n;t++)
                        {
                            if(t==i || t==j) continue;
                            else 
                            {
                                __int64 b1 = (a[i]-a[t])*(a[i]-a[t])+(b[i]-b[t])*(b[i]-b[t]);
                                __int64 c1 = (a[j]-a[t])*(a[j]-a[t])+(b[j]-b[t])*(b[j]-b[t]);
                                __int64 m1 = b1+a1-c1;
                                __int64 m2 = 2*sqrt(b1*1.0)*sqrt(a1*1.0);
                                double cosA = (m1*1.0)/m2;
                                double sinA = (sqrt((m2*m2-m1*m1)*1.0)*1.0)/m2;
                                double cosB = (sqrt(a1*1.0)*1.0)/2/s;
                                double sinB = (sqrt((s*s-(a1*1.0)/4)*1.0)*1.0)/s;
                                double cosC = cosA*cosB+sinA*sinB;
                                if(cosC<=0)  continue;
                                else 
                                {
                                    double x = b1+s*s-cosC*2*s*sqrt(b1*1.0);
                                    if(x<=s*s*1.0) ans++;
                                }
                            }
                        }
                        ma = max(ma,ans);
                    }
                }
            }
        }
        cout<<ma<<endl;
    return 0;
}

 

穿破石的主页 穿破石 | 初学一级 | 园豆:102
提问于:2015-03-23 22:56
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册