Shooting Game
Description
Fat brother and Maze are 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 that the playground is a kind of three-dimensional space and there are N mosquitoes in the playground. Each of them is a kind of point in the space which is doing the uniform linear motion. (匀速直线运动) Fat brother is standing at (0, 0, 0) and once he shoot, the mosquito who’s distance from Fat brother is no large than R will be shot down. You can assume that the area which Fat brother shoot is a kind of a sphere with radio R and the mosquito inside this sphere will 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 if he is really enjoying this. So in addition to that, Fat brother wants to shoot as less time as he can.
You can (have to) assume that Fat brother is strong enough and he don’t need to rest after shooting which means that can shoot at ANY TIME.
Input
The first line of the date is an integer T, which is the number of the text cases.
Then T cases follow, each case starts with two 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 that at time 0, the ith mosquito is at (ax, ay, az) and it’s moving direction is (dx, dy, dz) which means that after time t this mosquito will be at (ax+dx*t, ay+dy*t, ax+dz*t). You can assume that dx*dx + dy*dy+ dz*dz > 0.
1 <= T <= 50, 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 the case number first, then output two 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
Sample Output
解题思路:
题目大意:
在立体的空间上,有n只蚊子,给出蚊子的坐标,以及蚊子的移动方向(向量的方式给出), 然后人的攻击范围为半径为r的球体。
问说人最多可以打几只蚊子,以及需要花多少时间。
算法思想:
按照进入球形区域的时间排序,之后就是贪心区域覆盖的问题了。
AC代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1000005;
struct node{
double s,t;
}no[N];
bool cmp(node a,node b){
return a.t < b.t;
}
int main(){
int T,icase = 1;
scanf("%d",&T);
while(T--){
int n;
ll x,y,z,dx,dy,dz,r;
scanf("%d%I64d",&n,&r);
int len = 0,ans = 0;
for(int i = 0; i < n; ++i){
scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&x,&y,&z,&dx,&dy,&dz);
ll a = dx*dx+dy*dy+dz*dz;
ll b = 2*(dx*x+dy*y+dz*z);
ll c = x*x+y*y+z*z-r*r;
ll delta = b*b-4*a*c;
if(delta >= 0){
double s = (-b+sqrt(delta*1.0))/(2.0*a);
double t = (-b-sqrt(delta*1.0))/(2.0*a);
if(s > t)
swap(s,t);
if(t >= 0){
if(s < 0)
s = 0;
no[len].s = s;
no[len].t = t;
++len;
}
}
}
sort(no,no+len,cmp);
double tmp = -1;
for(int i = 0; i < len; ++i){
if(no[i].s > tmp){
tmp = no[i].t;
++ans;
}
}
printf("Case %d: %d %d\n",icase++,len,ans);
}
return 0;
}