War on Weather
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 470 Accepted Submission(s): 256
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?
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
2 3
先求st^2和so^2,so^2 - R^2即为s出发到球面一切点的切线的长度的平方maxl,只要st <= maxl,就可以在s攻击范围内,cou++
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
struct Point {
double x, y, z;
Point() {}
Point(double x, double y, double z) : x(x), y(y), z(z) {}
};
const int MAXN = 150;
const double R = 20000.0 / acos(-1);
const double R2 = R * R;
Point s[MAXN], t[MAXN];
bool vis[MAXN];
bool InSight(Point s, Point t) {
double st = (s.x - t.x) * (s.x - t.x) + (s.y - t.y) * (s.y - t.y) + (s.z - t.z) * (s.z - t.z);
double so = s.x * s.x + s.y * s.y + s.z * s.z;
double maxl = so - R2;
return st > maxl ? false : true;
}
int main()
{
int N, M;
while (~scanf("%d%d", &N, &M) && (N || M)) {
memset(vis, false, sizeof(vis));
double nx, ny, nz;
for (int i = 0; i < N; i++) {
scanf("%lf%lf%lf", &nx, &ny, &nz);
s[i] = Point(nx, ny, nz);
}
for (int j = 0; j < M; j++) {
scanf("%lf%lf%lf", &nx, &ny, &nz);
t[j] = Point(nx, ny, nz);
}
int cou = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (!vis[j] && InSight(s[i], t[j])) {
vis[j] = true;
cou++;
}
}
}
printf("%d\n", cou);
}
return 0;
}
1644



被折叠的 条评论
为什么被折叠?



