您的位置:首页 > 其它

HDU 1140 War on Weather(简单的三维距离)

2014-04-18 10:54 363 查看
理解题意的话就很简单了啊,就是求一个点的距离。注意所有的点保证在圆上。

War on Weather

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 311    Accepted Submission(s): 170


[align=left]Problem Description[/align]
After an unprovoked hurricane attack on the south shore, Glorious Warrior has declared war on weather. The first salvo in this campaign will be a coordinated pre-emptive attack on as many tropical depressions as possible. GW reckons
that the attack will neutralize the tropical depressions before they become storms, and dissuade others from forming.

GW has at his disposal k space-to-earth killer satellites at various locations in space. m tropical depressions are known to exist at various locations on the earth's surface. Each satellite can attack any number of targets on the earth provided there is line
of sight between the satellite and each target. How many different targets can be hit?

 

[align=left]Input[/align]
The input consists of several test cases. Each case begins with a line containing integers 0 < k, m &le 100 as defined above. k lines follow, each giving x,y,z - the location in space of a satellite at the scheduled time of attack.
m lines then follow, each giving x,y,z - the location of a target tropical depression. Assume the earth is a sphere centred at (0,0,0) with circumference 40,000 km. All targets will be on the surface of the earth (within 10-9 km) and all satellites will be
at least 50 km above the surface. A line containing 0 0 follows the last test case.

 

[align=left]Output[/align]
For each test case, output a line giving the total number of targets that can be hit. If a particular target falls within 10-8 km of the boundary between being within line-of-sight and not, it may be counted either way. (That is,
you need not consider rounding error so long as it does not exceed 10-8 km.)

 

[align=left]Sample Input[/align]

3 2
-10.82404031 -1594.10929753 -6239.77925152
692.58497298 -5291.64700245 4116.92402298
3006.49210582 2844.61925179 5274.03201053
2151.03635167 2255.29684503 5551.13972186
-1000.08700886 -4770.25497971 4095.48127333
3 4
0 0 6466.197723676
0 6466.197723676 0
6466.197723676 0 0
6366.197723676 0 0
6365.197723676 112.833485488 0
0 0 6366.197723676
0 -6366.197723676 0
0 0

 

[align=left]Sample Output[/align]

2
3

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
#define M 1000100
//#define LL __int64
#define LL long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535898

const int maxn = 1010;
using namespace std;

struct point1
{
double x, y, z;
};

point1 f[maxn], p[maxn];

const double R = 20000/PI;
double Distance(point1 a, point1 b)
{
double s = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z));
return s;
}

double Lenth(double a, double b)
{
double c = sqrt(a*a - b*b);
return c;
}

bool vis[maxn];
int main()
{
int n, m;
while(cin >>n>>m)
{
if(!n && !m)
break;
memset(vis, false, sizeof(vis));
for(int i = 0; i < n; i++)
cin >>f[i].x>>f[i].y>>f[i].z;
for(int i = 0; i < m; i++)
cin >>p[i].x>>p[i].y>>p[i].z;
point1 t;
t.x = 0.0;
t.y = 0.0;
t.z = 0.0;
for(int i = 0; i < n; i++)
{
double d = Distance(f[i], t);
double dd = Lenth(d, R);
for(int j = 0; j < m; j++)
{
if(!vis[j])
{
double s;
s = Distance(f[i], p[j]);
if(s <= dd)
vis[j] = true;
}
}
}
int cnt = 0;
for(int i = 0; i < m; i++)
if(vis[i])
cnt ++;
cout<<cnt<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: