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

题目大意是求在射程内能射死几个mosquito,而且要求射击次数最少,因为一次射击能射死射程内所有mosquito。

一开始反应是先求出mosquito运动直线与射击者的最近距离,虽然最后算出了最近坐标和距离,发现多次一举。

其实直接设能射击的时刻是t。

那么

其中a、b、c是加速度矢量的三个分量。

然后取临界等号,就能算出进入射击范围的时间from和出射击范围的时间to。

先判断方程是否有解。

然后再判断from和to的正负性。

于是就能得到一系列的mosquito的时间序列。(需要注意的是from小于0的需要设置为0)

最后就是优先按照to时间进行排序,其次按照from排序。

然后进行一次贪心,对于当前标记点的to,所有后面的from小于等于当前点to的点都可以与当前点在同一时间射击。因为保证了后面的点的to时间比当前时间的to时间大。

PS:如果按照double型直接输入会报超时。。。。

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <algorithm>
  7. #include <set>
  8. #include <map>
  9. #include <queue>
  10. #include <string>
  11.  
  12. using namespace std;
  13.  
  14. inline double pow2(double x)
  15. {
  16. return x*x;
  17. }
  18.  
  19. struct node
  20. {
  21. double from, to;
  22. }t[];
  23.  
  24. bool cmp(node a, node b)
  25. {
  26. if (a.to != b.to)
  27. return a.to < b.to;
  28. else
  29. return a.from < b.from;
  30. }
  31.  
  32. int n, r, cnt, ans;
  33. int px, py, pz;
  34.  
  35. void Work()
  36. {
  37. scanf("%d%d", &n, &r);
  38. int a, b, c;
  39. double A, B, C, t1, t2, deta;
  40. cnt = ;
  41. ans = ;
  42. for (int i = ; i < n; ++i)
  43. {
  44. scanf("%d%d%d", &px, &py, &pz);
  45. scanf("%d%d%d", &a, &b, &c);
  46. A = pow2(a) + pow2(b) + pow2(c);
  47. B = *(a*px + b*py + c*pz);
  48. C = pow2(px) + pow2(py) + pow2(pz) - pow2(r);
  49. deta = pow2(B) - *A*C;
  50. if (deta >= )
  51. {
  52. t1 = (-B-sqrt(deta))/A/;
  53. t2 = (-B+sqrt(deta))/A/;
  54. if (t1 < )
  55. t1 = ;
  56. }
  57.  
  58. if (deta >= && t2 >= )
  59. {
  60. t[cnt].from = t1;
  61. t[cnt].to = t2;
  62. cnt++;
  63. }
  64. }
  65. printf("%d ", cnt);
  66.  
  67. sort(t, t+cnt, cmp);
  68. int i, j;
  69. for (i = ; i < cnt;)
  70. {
  71. j = i+;
  72. while (t[j].from <= t[i].to && j < cnt)
  73. {
  74. j++;
  75. }
  76. ans++;
  77. i = j;
  78. }
  79. printf("%d\n", ans);
  80. }
  81.  
  82. int main()
  83. {
  84. //freopen("test.in", "r", stdin);
  85. int T;
  86. scanf("%d", &T);
  87. for (int times = ; times <= T; ++times)
  88. {
  89. printf("Case %d: ", times);
  90. Work();
  91. }
  92. return ;
  93. }

ACM学习历程—FZU 2144 Shooting Game(计算几何 && 贪心 && 排序)的更多相关文章

  1. FZU 2144 Shooting Game (贪心区域划分)

    Problem 2144 Shooting Game Accept: 370 Submit: 1902 Time Limit: 1000 mSec Memory Limit : 32768 KB Pr ...

  2. ACM学习历程—FZU 2140 Forever 0.5(计算几何 && 构造)

    Description   Given an integer N, your task is to judge whether there exist N points in the plane su ...

  3. ACM学习历程—FZU2148 Moon Game(计算几何)

    Moon Game Description Fat brother and Maze are playing a kind of special (hentai) game in the clearl ...

  4. ACM学习历程——UVA10112 Myacm Triangles(计算几何,多边形与点的包含关系)

    Description   Problem B: Myacm Triangles Problem B: Myacm Triangles Source file: triangle.{c, cpp, j ...

  5. ACM学习历程—HDU4415 Assassin’s Creed(贪心)

    Problem Description Ezio Auditore is a great master as an assassin. Now he has prowled in the enemie ...

  6. ACM学习历程——HDU 5014 Number Sequence (贪心)(2014西安网赛)

    Description There is a special number sequence which has n+1 integers. For each number in sequence, ...

  7. ACM学习历程——POJ 1700 Crossing River(贪心)

    Description A group of N people wishes to go across a river with only one boat, which can at most ca ...

  8. ACM学习历程——POJ 2376 Cleaning Shifts(贪心)

    Description Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning ...

  9. FZU 2144 Shooting Game

    Shooting Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

随机推荐

  1. js嵌套Struts2标签

    在页面中如果想要在js代码块里面获取到某些值,而这些值是通过Struts的标签取到的, 如: var operatorType = '<s:property value="#sessi ...

  2. hdu 1068 Girls and Boys 二分图的最大匹配

    题目链接:pid=1068">http://acm.hdu.edu.cn/showproblem.php? pid=1068 #include <iostream> #in ...

  3. C#里类的get和set方法编写和调用

    using System; class Date { int day; int month; int year; public int Day{ get { return day; } set { d ...

  4. mapreduce代码实现入门

    mapreduce代码主要包括三个类,map类.reduce类以及测试类! 以wordcount为例, map类为: static class WordMapper extends Mapper< ...

  5. c# 根据枚举Value 获得名称

    // 定义枚举类型enum sotype : int { book=1, pen=2, other=3 } // 输出名称 switch (Enum.GetName(typeof(sotype), 1 ...

  6. Android 事件分发机制 图解

    在Android 开发中事件分发是比较重要的,也是比较难理解的,之前看过这方面的东西,以为自己弄懂了,也就没太注意,最近面试呢,想着肯定要问到这一块的东西,回顾的时候发现又忘了,真是好记性不如烂笔头啊 ...

  7. Android 异常解决方法【汇总】

    (1)异常:Android中引入第三方Jar包的方法(Java.lang.NoClassDefFoundError解决办法) 1.在工程下新建lib文件夹,将需要的第三方包拷贝进来.2.将引用的第三方 ...

  8. EasyDSS RTMP流媒体解决方案之Windows服务安装方案

    Windows服务安装 EasyDSS_Solution流媒体解决方案,可以通过start一键启动.在实际应用中,我们希望可以设置成系统服务,那么下面我将会介绍,如何在windows中将流媒体解决方案 ...

  9. 网页直播、微信直播技术解决方案:EasyNVR与EasyDSS流媒体服务器组合之区分不同场景下的easynvr

    近期遇到好多客户咨询关于实现微信直播.或者是将直播页面集成进入自己项目中. 该方案的主要目的:完成在公网一直进行内网摄像头的RTMP/HLS直播! 实现方案的具体实现: EasyNVR+EasyDSS ...

  10. redis启动错误-- Creating Server TCP listening socket *:6379: listen: UnKnown error

    前提:windows server 2008.redis 3.x 今天给服务器部署redis环境,文件配置.服务安装都很顺利,可就在启动服务的时候提示 百度老半天也没找到个说到点子上的. 这里记录下解 ...