• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

FOJ Problem 2144 Shooting Game

Problem 2144 Shooting Game

Accept: 6    Submit: 40 Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem 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

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
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define INF 0x7fffffff
11 #define mod 1000000007
12 #define ll long long
13 #define maxn 100025
14 #define pi acos(-1.0)
15 int n, m, x,y;
16 ll r;
17 int t;
18 struct point{
19     ll x, y, z,dx,dy,dz;
20     point(ll x = 0, ll y = 0, ll z = 0, ll dx = 0, ll dy = 0, ll dz = 0) :x(x), y(y), z(z){}
21 }a[maxn];
22 ll dis(point p1,point p2){
23     return (p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y) + (p1.z - p2.z)*(p1.z - p2.z);
24 }
25 int b[maxn];
26 double c[maxn];
27 struct node{
28     double lf, ri;
29 }lr[maxn];
30 bool cmp(node a, node b){return a.lf < b.lf; }
31 int main(){
32     int cas = 1;
33     scanf("%d", &t);
34     while (t--){
35         scanf("%d%d", &n, &r);
36         int k = 0;
37         point a;
38         for (int i = 0; i < n; i++){
39             scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &a.x, &a.y, &a.z, &a.dx, &a.dy, &a.dz);
40             ll bb = 2 * (a.x*a.dx + a.y*a.dy + a.z*a.dz);
41             ll aa = a.dx*a.dx + a.dy*a.dy + a.dz*a.dz;
42             ll cc = a.x*a.x + a.y*a.y + a.z*a.z - r*r;
43             if (bb*bb - 4 * aa*cc >= 0){
44                 if (dis(a, point(0, 0, 0))>r*r&&a.x*a.dx + a.y*a.dy +a.z*a.dz >= 0)continue;
45                 double m1 = max(0.0, (-bb - sqrt((double)bb*bb - 4 * (double)aa*cc)) / 2 / aa);
46                 double m2 = max(0.0, (-bb + sqrt((double)bb*bb - 4 * (double)aa*cc)) / 2 / aa);
47                 lr[k].lf = min(m1, m2), lr[k++].ri = max(m1, m2);
48             }
49         }
50         sort(lr, lr + k,cmp);
51         c[k - 1] = lr[k-1].ri;
52         for (int i = k - 2; i >= 0; i--)c[i] = min(c[i + 1], lr[i].ri);
53         printf("Case %d: ", cas++);
54         double temp;
55         m = 0;
56         for (int i = 0; i < k;){
57             temp = c[i]; m++;
58             while (i<k&&lr[i].lf <= temp)i++;
59         }
60         printf("%d %d\n", k, m);
61     }
62 }
View Code


 

posted @ 2013-12-23 17:28  HaibaraAi  阅读(224)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3