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

    非连续子串匹配题,直接模拟 /** \brief poj 1936 * * \param date 2014/8/5 * \param state AC * \return memory 804k t ...

  2. spring 学习资料备份

    易百教程  https://www.yiibai.com/spring/spring-autowiring-by-name.html

  3. web.py+fastcgi+nginx 502错误解决

    用web.py照着官网在服务器上搭好了后台.这次很奇怪地出现了一个Nginx 502 Bad Gateway的错误. 执行上面的kill `pgrep -f "python /path/to ...

  4. 新建一个用户,让他只能看到某一个视图(View),如何设置

    新建一个用户,让他只能看到某一个视图(View),怎么设置? 新建一个用户,让他只能看到某一个视图(View),怎么设置? 如果做不到“只能看到指定视图”,最好能做到“对指定表或视图只有查询的权限”. ...

  5. 在编写JSP的时候出现XXX cannot be resolved to a type

    今天遇到这个情况,却发现是eclipse抽风,说javax.servlet.http.Cookie找不到定义,但是经过浏览器测试,可以运行,而JSP源文件中eclipse死活要报错.表示无语. 关于e ...

  6. Android开发日记(七)

    trim()方法返回调用字符串对象的一个副本,但是所有起始和结尾的空格都被删除了,例子如下:String s="  Hello World   ".trim();就是把" ...

  7. ldap temp

    #http://www.openldap.org/software/man.cgi?query=slapcat&apropos=0&sektion=0&manpath=Open ...

  8. 在linux跑xenomai vkworks skin的测试

    1 代码 ############################################################## /* * Copyright (C) 2001,2002,200 ...

  9. JavaScript的gzip静态压缩方法记录

    传统的JS压缩(删除注释,删除多余空格等)提供的压缩率有时还是不尽不意,幸亏现在的浏览器都支持压缩传输(通过设置http header的Content-Encoding=gzip),可以通过服务器的配 ...

  10. sql 使用整理

    今天使用视图查询东西,为了方便直接select * 查出来的都行全部都错乱了,看来sql 超过20个以上的字段为了效率和安全,禁止用select * -------------查一个表的所有字段的-- ...