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型直接输入会报超时。。。。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string> using namespace std; inline double pow2(double x)
{
return x*x;
} struct node
{
double from, to;
}t[]; bool cmp(node a, node b)
{
if (a.to != b.to)
return a.to < b.to;
else
return a.from < b.from;
} int n, r, cnt, ans;
int px, py, pz; void Work()
{
scanf("%d%d", &n, &r);
int a, b, c;
double A, B, C, t1, t2, deta;
cnt = ;
ans = ;
for (int i = ; i < n; ++i)
{
scanf("%d%d%d", &px, &py, &pz);
scanf("%d%d%d", &a, &b, &c);
A = pow2(a) + pow2(b) + pow2(c);
B = *(a*px + b*py + c*pz);
C = pow2(px) + pow2(py) + pow2(pz) - pow2(r);
deta = pow2(B) - *A*C;
if (deta >= )
{
t1 = (-B-sqrt(deta))/A/;
t2 = (-B+sqrt(deta))/A/;
if (t1 < )
t1 = ;
} if (deta >= && t2 >= )
{
t[cnt].from = t1;
t[cnt].to = t2;
cnt++;
}
}
printf("%d ", cnt); sort(t, t+cnt, cmp);
int i, j;
for (i = ; i < cnt;)
{
j = i+;
while (t[j].from <= t[i].to && j < cnt)
{
j++;
}
ans++;
i = j;
}
printf("%d\n", ans);
} int main()
{
//freopen("test.in", "r", stdin);
int T;
scanf("%d", &T);
for (int times = ; times <= T; ++times)
{
printf("Case %d: ", times);
Work();
}
return ;
}

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. 转:几款主流pcb软件比较

      原理图设计软件:会ORCAD就可以了,支持的Netlist超多,基本是业界标准. PCB Layout 软件 1.Protel,现在推AltiumDesigner.国内低端设计的主流,国外基本没人 ...

  2. keras----resnet-vgg-xception-inception

    来源: https://www.pyimagesearch.com/2017/03/20/imagenet-vggnet-resnet-inception-xception-keras/ classi ...

  3. 果园里有一堆苹果,一共n头(n大于1小于9)熊来分,第一头为小东,它把苹果均分n份后,多出了一个,它扔掉了这一个,拿走了自己的一份苹果,接着第二头熊重复这一过程,即先均分n份,扔掉一个然后拿走一份,以此类推直到最后一头熊都是这样(最后一头熊扔掉后可以拿走0个,也算是n份均分)。问最初这堆苹果最少有多少个。

    include "stdafx.h" // ConsoleApplication12.cpp : 定义控制台应用程序的入口点. // #include<iostream> ...

  4. hibernate QBC查询

    HQL运算符 QBC运算符 含义 = Restrictions.eq() 等于equal <>  Restrictions.ne() 不等于not equal >  Restrict ...

  5. Selenium3 Python3 Web自动化测试从基础到项目实战之一启动不同的浏览器及配置

    在web自动化中目前selenium作为底层的自动化测试是目前运用最广的,但是各个公司都会在这个基础之上进行修改.从今天开始我们就慢慢从low代码一步一步的学习框架知识. 首先当我们测试环境有了之后我 ...

  6. 【demo练习四】:WPF用户控件案例

    首先,新建vs中“用户控件(WPF)”,右键项目名 =>"添加"按钮 => 选择“新建项”. 然后选择“用户控件(WPF)” => 起名字 => 点击“添加 ...

  7. SSH 使用密钥登录并禁止口令登录

    小结:修改下sshd配置文件,把公钥传上去就好了 先生成公钥和私钥,默认在/root/.ssh/目录,可以先看一下有没有这个目录. 生成公钥后,以后其它服务器也都可以复用这个公钥 最好生成时输入密码! ...

  8. 下面哪个进制能表述 13*16=244是正确的?)[中国台湾某计算机硬件公司V2010年5月面试题]

    A.5B.7C.9D.11解析:13如果是一个十进制的话,它可以用13=1*101+3*100来表示.现在我们不知道13是几进制,那我们姑且称其X进制.X进制下的13转化为十进制可以用13=1*X1+ ...

  9. EntityFramework走马观花之CRUD(下)

    我在Entity Framework系列文章的CRUD上篇中介绍了EF的数据查询,中篇谈到了EF的数据更新,下篇则聊聊EF实现CRUD的内部原理. 跟踪实体对象状态 在CRUD上篇和中篇谈到,为了实现 ...

  10. jquery在网页实时显示时间;

    1.定义一个显示时间的位置 <div id="shijian"> </div> 2.jquery代码 function showTime() { var c ...