Problem 2144 Shooting Game

Accept: 370 Submit: 1902

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

可以根据出去的时间对蚊子进行排序,然后统计后面有多少蚊子进去的时间是小于这个蚊子的出去时间,这些蚊子可以同时杀死。

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <math.h> using namespace std;
#define MAX 100000
int t;
int n,r;
struct Node
{
double leftime;
double getime;
}a[MAX+5];
int cmp(Node a,Node b)
{
if(a.leftime==b.leftime)
return a.getime<b.getime;
return a.leftime<b.leftime;
}
int ans;
int res;
int tag[MAX+5];
int main()
{
int x1,y1,z1,x2,y2,z2;
scanf("%d",&t);
int cas=0;
while(t--)
{
ans=0;
res=0;
scanf("%d%d",&n,&r);
int cnt=0;
for(int i=1;i<=n;i++)
{
scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
double a1=(x2*1.0)*(x2*1.0)+(y2*1.0)*(y2*1.0)+(z2*1.0)*(z2*1.0);
double b=2*(x1*1.0)*(x2*1.0)+2*(y1*1.0)*(y2*1.0)+2*(z1*1.0)*(z2*1.0);
double c=(x1*1.0)*(x1*1.0)+(y1*1.0)*(y1*1.0)+(z1*1.0)*(z1*1.0)-(r*1.0)*(r*1.0);
double d=b*b-4*a1*c;
if(d<0) continue;
double xx=(-b+sqrt(d))/(2*a1);
double yy=(-b-sqrt(d))/(2*a1);
if(xx<0&&yy<0) continue;
a[cnt].getime=min(xx,yy);
if(a[cnt].getime<0) a[cnt].getime=0;;
a[cnt++].leftime=max(xx,yy);
}
sort(a,a+cnt,cmp);
ans=cnt;
res=0;
int k;
for(int i=0;i<cnt;i=k)
{
k=i+1;
for(int j=i+1;k<cnt;j++)
{
if(a[j].getime<=a[i].leftime)
k=j+1;
else
break;
}
res++; }
printf("Case %d: %d %d\n",++cas,ans,res);
}
return 0;
}

FZU 2144 Shooting Game (贪心区域划分)的更多相关文章

  1. FZU 2144 Shooting Game

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

  2. ACM学习历程—FZU 2144 Shooting Game(计算几何 && 贪心 && 排序)

    Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (May ...

  3. FZU 2144 Shooting Game(数学+贪心)

    主要思路:求出蚊子到达球的时间区间(用方程得解),对区间做一个贪心的选择,选择尽可能多的区间有交集的区间段(结构体排序即可),然后计数. #include <cstdio> #includ ...

  4. Problem 2144 Shooting Game fzu

    Problem 2144 Shooting Game Accept: 99    Submit: 465Time Limit: 1000 mSec    Memory Limit : 32768 KB ...

  5. Java 内存区域划分

            JVM的内存区域划分 学过C语言的朋友都知道C编译器在划分内存区域的时候经常将管理的区域划分为数据段和代码段,数据段包括堆.栈以及静态数据区.那么在Java语言当中,内存又是如何划分的 ...

  6. 3,SFDC 管理员篇 - 区域划分

    1,销售区域划分 Setup | Administrator | Manage Territory Territory Type : 帮助用户建立大的销售区域分类,分类顺序按照Priority进行显示 ...

  7. JVM的内存区域划分

            JVM的内存区域划分 学过C语言的朋友都知道C编译器在划分内存区域的时候经常将管理的区域划分为数据段和代码段,数据段包括堆.栈以及静态数据区.那么在Java语言当中,内存又是如何划分的 ...

  8. JVM的内存区域划分以及垃圾回收机制详解

    在我们写Java代码时,大部分情况下是不用关心你New的对象是否被释放掉,或者什么时候被释放掉.因为JVM中有垃圾自动回收机制.在之前的博客中我们聊过Objective-C中的MRC(手动引用计数)以 ...

  9. Java 内存区域划分 备忘录

    最近看了<深入理解虚拟机>的内存分配与管理这部分的内容,这里做一个的总结,以加深我对知识点的理解,如有错误的地方,还望大神们指出,我及时更正:  内存区域划分 首先是下面这幅图: 图 1. ...

随机推荐

  1. 每日英语:Online Education a New Frontier in China

    In a country as obsessed with education as China, it makes sense that online teaching has huge poten ...

  2. js控制伪元素样式

    //获取伪元素// CSS代码 #myId:before { content: "hello world!"; display: block; width: 100px; heig ...

  3. swift学习经验和错误记录

    1.selector 和action 直接用字符串,后面要加冒号":" 2.StoryBoard 连接后改名又重新连接出现了找不到符号的诡异错误,unknow class xxxx ...

  4. UCOS2系统内核讲述(四)_创建任务

    Ⅰ.写在前面 学习本文之前可以参看我前面的文章: UCOS2_STM32移植详细过程(汇总文章) UCOS2系统内核讲述(一)_总体描述 UCOS2系统内核讲述(二)_初始化调用函数 UCOS2系统内 ...

  5. java 错误汇总

    一.怎么处理警告:编码 GBK 的不可映射字符 解决办法是:应该使用-encoding参数指明编码方式:javac -encoding UTF-8 XX.java,这下没警告了,运行也正确了在JCre ...

  6. jQuery:(一)jQuery简介

    一.jQuery简介jQuery由美国人John Resig于2006年创建jQuery是目前最流行的JavaScript程序库,它是对JavaScript对象和函数的封装. 二.jQuery的优势1 ...

  7. Lifecycle for overriding binding, validation, etc,易于同其它View框架(Tiles等)无缝集成,采用IOC便于测试。

    Lifecycle for overriding binding, validation, etc,易于同其它View框架(Tiles等)无缝集成,采用IOC便于测试. 它是一个典型的教科书式的mvc ...

  8. 【openwrt+arduion】案例

    http://www.geek-workshop.com/thread-4950-1-1.html http://www.guokr.com/article/319356/ http://www.gu ...

  9. 解析IE, FireFox, Opera 浏览器支持Alpha透明的方法

    先请看如下代码: filter:alpha(opacity=50);       /* IE */  -moz-opacity:0.5;              /* Moz + FF */  op ...

  10. Eclipse & Visual Studio

    VS中的解决方案 vs Eclipse中的workspace Maven包管理 vs  Nuget类库管理 build path  vs