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 Input
6
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 Output
Case 1:2 1
Case 2:2 1
Case 3:2 2
Case 4:0 0
Case 5:1 1
Case 6:3 2
The main idea is to seek to kill several mosquito in range, and require the least number of shots, because a shot can kill all the mosquito in range.
The first reaction is to find out the mosquito motion line and the shooter's nearest distance, although finally calculated the nearest coordinates and distance, found several times in one swoop.
In fact, the moment is directly set to fire is T.
So
Where a, B, and C are the three components of an acceleration vector.
Then take the critical equals sign to calculate the time from and out of the firing range to enter the range of the shot.
First, determine whether the equation has a solution.
Then judge the positive and negative nature of the from and to.
So we can get a series of mosquito time series. (Note that the from less than 0 needs to be set to 0)
The final priority is to sort by to time, followed by from.
Then make a greedy, for the current point of the to, all subsequent from less than equal to the current point to the point can be fired at the same time as the current points. Because the to time of the subsequent point is guaranteed to be greater than the to time of the current time.
PS: If the direct input according to double type will be reported time-out ....
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<Set>#include<map>#include<queue>#include<string>using namespaceStd;inlineDoublePow2 (Doublex) { returnx*x;}structnode{Double from, to;} t[100005];BOOLCMP (Node A, Node B) {if(A.to! =b.to)returnA.to <b.to; Else returnA. from< b. from;}intN, R, CNT, ans;intpx, py, PZ;voidWork () {scanf ("%d%d", &n, &R); intA, B, C; DoubleA, B, C, T1, T2, Deta; CNT=0; Ans=0; for(inti =0; I < n; ++i) {scanf ("%d%d%d", &px, &py, &PZ); scanf ("%d%d%d", &a, &b, &c); A= Pow2 (a) + Pow2 (b) +Pow2 (c); B=2* (a*px + b*py + c*PZ); C= Pow2 (px) + pow2 (py) + pow2 (PZ)-Pow2 (R); Deta= Pow2 (B)-4*a*C; if(Deta >=0) {T1= (-b-sqrt (deta))/a/2; T2= (-b+sqrt (deta))/a/2; if(T1 <0) T1=0; } if(Deta >=0&& T2 >=0) {t[cnt]. from=T1; T[cnt].to=T2; CNT++; }} printf ("%d", CNT); Sort (T, T+CNT, CMP); intI, J; for(i =0; I <CNT;) {J= i+1; while(T[j]. from<= t[i].to && J <CNT) {J++; } ans++; I=J; } printf ("%d\n", ans);}intMain () {//freopen ("test.in", "R", stdin); intT; scanf ("%d", &T); for(intTimes =1; Times <= T; ++Times ) {printf ("Case %d:", times); Work (); } return 0;}
ACM Learning History-fzu 2144 Shooting Game (calculate geometry && Greed && sort)