# Shooting Game FZU - 2144 区间覆盖贪心

## Shooting Game

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
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

(x - 0)^2 + (y - 0)^2 + (z - 0)^2  <= r，把r移到不等式左边，xyz代入进行化简，就是一条一元二次不等式

(dx^2 + dy^2 + dz^2) * t^2  +  2 * (ax * dx+ay * dy+az * dz) * t + ax^2 + ay^2 + az^2 - r^2 <= 0

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100005;
const double eps = 1e-8;
struct node{
double x,y,z;
double dx,dy,dz;
}mosq[maxn];//蚊子的初始坐标和移动方位坐标
struct Time{
double l,r;
}times[maxn];//蚊子在射击范围内的时间段
int n,cnt;
ll r;//射击半径
bool cmp(const Time &a,const Time &b){
if(fabs(a.r - b.r) > eps)
return a.r < b.r;
return a.l > b.l;

}//先按照右边界从小到大排序，如果右边界近似相等按左边界从大到小排序
void cal(node mos,double &a,double &b,double &c){
a = mos.dx * mos.dx + mos.dy * mos.dy + mos.dz * mos.dz;
b = 2 * (mos.x * mos.dx + mos.y * mos.dy + mos.z * mos.dz);
c = mos.x * mos.x + mos.y * mos.y + mos.z * mos.z - r * r;
}
double diat(double a,double b,double c){//判别式
return b * b - 4 * a * c;
}
void solve(node mos){//solve函数是求解方程的解即蚊子在射程内的时间边界
double a,b,c;
cal(mos,a,b,c);//求一元二次方程系数abc
double del = diat(a,b,c);
if(del < 0) return; //无解，说明蚊子不会经过射程区域
else if(del > 0){//判别式大于零两个解
double x1 = (-1.0 * b - sqrt(del * 1.0)) / (2.0 * a);
double x2 = (-1.0 * b + sqrt(del * 1.0)) / (2.0 * a);
if(x2 < 0) return;//时间必须大于0;
if(x1 < 0)
times[cnt].l = 0.0;
else
times[cnt].l = x1;
times[cnt++].r = x2;
}
else{//一个解
double x = -1.0 * b / (2.0 * a);
if(x < 0) return;
times[cnt].l = x;
times[cnt++].r = x;
}
}
int main(){
int t,cas = 0;
scanf("%d",&t);
while(t--){
scanf("%d%I64d",&n,&r);
ll x,y,z,dx,dy,dz;
for(int i = 0; i < n; i++){
scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&x,&y,&z,&dx,&dy,&dz);
mosq[i].x = x * 1.0;
mosq[i].y = y * 1.0;
mosq[i].z = z * 1.0;
mosq[i].dx = dx * 1.0;
mosq[i].dy = dy * 1.0;
mosq[i].dz = dz * 1.0;
}
cnt = 0;//能进入区域的蚊子数
for(int i = 0; i < n; i++){
solve(mosq[i]);
}
sort(times,times+cnt,cmp);
int ans = 1;
double bound = times[0].r;
for(int i = 1; i < cnt; i++){
if(times[i].l > bound){
ans++;
bound = times[i].r;
}
}
if(cnt == 0)
printf("Case %d: 0 0\n",++cas);
else
printf("Case %d: %d %d\n",++cas,cnt,ans);
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120