problem 2144 Shooting Gameaccept:267 submit:1368
Time limit:1000 mSec Memory limit:32768 KB Problem Description
Fat brother and Maze is playing a kind of special (hentai) game in the playground. (Maybe it ' s the Ooxx game which decrypted in the last problem, who knows.) But as they don ' t like using repellent while playing this kind of special (hentai) game, they really suffer a lot from the Mosquito. So they decide to use antiaircraft gun to shoot the mosquito. You can assume this playground is a kind of three-dimensional space and there are N mosquitoes in the playground. Each of the them are a kind of point in the space which is doing the uniform linear motion. Uniform motion Fat brother is standing @ (0, 0, 0) and once he shoot, the mosquito who's distance from fat Brother is no large than R WI ll be shot down. You can assume, the area which Fat brother shoot are a kind of a sphere with radio R and the mosquito inside this spher E'll be shot down. As Fat brother hate these mosquito very much, he wants to shoot as much mosquito as he can. But as we all know, it's tired for a man to shoot even ifHe is really enjoying this. So in addition to, Fat brother wants to shoot as less time as he can.
You can (with to) assume this Fat brother is strong enough and he don ' t need to rest after shooting which means that can s Hoot at any time.
Input
The first line of the date is a integer T, which is the number of the text cases.
Then T-cases follow, each case starts with the integers N and R which describe above.
Then N lines follow, the ith line contains six integers ax, ay, AZ, dx, dy, dz. It means at time 0, the ith mosquito are at (ax, Ay, AZ) and it's moving direction is (dx, dy, dz) which means that AF ter time t This mosquito would be is at (ax+dx*t, Ay+dy*t, ax+dz*t). You can assume that DX*DX + dy*dy+ dz*dz > 0.
1 <= T <=, 1 <= N <= 100000, 1 <= R <= 1000000
-1000000 <= ax, ay, AZ <= 1000000
-100 <= dx, dy, dz <= 100
The range of each coordinate is [-10086, 10086]
Output
For each case, output of the case number first, then output of numbers A and B.
A is the number of mosquito Fat brother can shoot down.
B is the number of times Fat brother need to shoot.
Sample INPUT6
2 1
2 0 0-1) 0 0
-2 0 0 1 0 0
2 1
4 0 0-1) 0 0
-2 0 0 1 0 0
2 1
4 0 0-1) 0 0
1 0 0 1 0 0
2 1
1 1 1 1 1 1
-1-1-1-1-1-1
1 1
0 0 0 1 0 0
3 1
-1 0 0 1 0 0
-2 0 0 1 0 0
4 0 0-1) 0 0 Sample outputcase 1:2 1
Case 2:2 1
Case 3:2 2
Case 4:0 0
Case 5:1 1
Case 6:3 2
In the three-dimensional space, there are n mosquitoes, the coordinates of the mosquito, and the direction of the mosquito's movement (vector), the attack range of each anti-aircraft cannon (0,0,0) Radius is the sphere of R. Ask how many mosquitoes you can hit
Is the interval of the problem (interval coverage problem) deformation, by the Mosquito's motion equation (X+DX) ^2+ (y+dy) ^2+ (Z+DZ) ^2=r*r can get the mosquitoes fly into and out of the attack range of time, and thus become a one-dimensional interval point of issue,
The idea is not very complex but still stuck for a long time, the first coordinate and vector set to double input will timeout, and then with the integer word is a long long, CIN will also time out. Or experience is not enough AH.
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < cmath>using namespace std; #define MAXN 100005struct qujian{double t1, T2;} Qj[maxn];bool CMP (Qujian A, Qujian b) {if (A.t2 < B.T2) return True;else return false; int main () {Long long Casen;long long N;long long R;long long x, y, z;long long dx, dy, Dz;long long A, B, C;long long Beit a;double T1, T2, temp;scanf ("%i64d", &casen); for (long long cas = 1; CAs <= casen; cas++) {scanf ("%i64d%i64d", & n, &r); long Long Jishu = 0;for (Long long i = 0; i < n; i++) {scanf ("%i64d%i64d%i64d%i64d%i64d%i64d", &x, &y , &z, &DX, &dy, &dz); a = Dx*dx + dy*dy + dz*dz;b = 2 * (dx*x + dy*y + dz*z); c = x*x + Y*y + Z*z-r*r;beit A = b*b-4 * a*c;if (beita >= 0) {T1 = (-B + sqrt (beita*1.0))/(2.0 * a); t2 = (-b-sqrt (beita*1.0))/(2.0 * a); if (t 1 > T2) {temp = T1;T1 = T2;t2 = temp;} if (T2 >= 0) {if (T1 < 0) T1 = 0;qj[jishu].t1 = T1;qj[jishu].t2 = T2;jishu++;}}} Sort (QJ, QJ + Jishu, CMP); long long time = 0;double Hou = -1;for (long long i = 0; i < Jishu; i++) {if (Qj[i].t1>hou) {hou = qj[i].t2;time++;}} printf ("Case%i64d:%i64d%i64d\n", CAs, Jishu, Time);}}
FZU-2144 Shooting Game