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

#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define maxn 100025
int n, m, x,y;
ll r;
int t;
struct point
{
ll x, y, z,dx,dy,dz;
point(ll x = , ll y = , ll z = , ll dx = , ll dy = , ll dz = ) :x(x), y(y), z(z) {}
} a[maxn];
ll dis(point p1,point p2)
{
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);
}
int b[maxn];
double c[maxn];
struct node
{
double lf, ri;
} lr[maxn];
bool cmp(node a, node b)
{
return a.lf < b.lf;
}
int main()
{
int cas = ;
scanf("%d", &t);
while (t--)
{
scanf("%d%ld", &n, &r);
int k = ;
point a;
for (int i = ; i < n; i++)
{
scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &a.x, &a.y, &a.z, &a.dx, &a.dy, &a.dz);
ll bb = * (a.x*a.dx + a.y*a.dy + a.z*a.dz);
ll aa = a.dx*a.dx + a.dy*a.dy + a.dz*a.dz;
ll cc = a.x*a.x + a.y*a.y + a.z*a.z - r*r;
if (bb*bb - * aa*cc >= )
{
if (dis(a, point(, , ))>r*r&&a.x*a.dx + a.y*a.dy +a.z*a.dz >= )continue;
double m1 = max(0.0, (-bb - sqrt((double)bb*bb - * (double)aa*cc)) / / aa);
double m2 = max(0.0, (-bb + sqrt((double)bb*bb - * (double)aa*cc)) / / aa);
lr[k].lf = min(m1, m2), lr[k++].ri = max(m1, m2);
}
}
sort(lr, lr + k,cmp);
c[k - ] = lr[k-].ri;
for (int i = k - ; i >= ; i--)c[i] = min(c[i + ], lr[i].ri);
printf("Case %d: ", cas++);
double temp;
m = ;
for (int i = ; i < k;)
{
temp = c[i];
m++;
while (i<k&&lr[i].lf <= temp)i++;
}
printf("%d %d\n", k, m);
}
}

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. FZU 2144 Shooting Game

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

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

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

  4. Problem 2144 Shooting Game fzu

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

  5. 洛谷3月月赛div2 题解(模拟+数学+贪心+数学)

    由于本人太蒻了,div1的没有参加,胡乱写了写div2的代码就赶过来了. T1 苏联人 题目背景 题目名称是吸引你点进来的. 这是一道正常的题,和苏联没有任何关系. 题目描述 你在打 EE Round ...

  6. UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  7. HDOJ 5073 Galaxy 数学 贪心

    贪心: 保存连续的n-k个数,求最小的一段方差... .预处理O1算期望. .. Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  8. FZU Problem 2221 RunningMan(贪心)

    一开始就跑偏了,耽误了很长时间,我和队友都想到博弈上去了...我严重怀疑自己被前几个博弈题给洗脑了...贪心的做法其实就是我们分两种情况,因为A先出,所以B在第一组可以选择是赢或输,如果要输,那直接不 ...

  9. hdu 3573(数学+贪心)

    Buy Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. JedisConnectionException: Unexpected end of stream.

    在实际项目中遇到redis读取时报错. 报错是 [ERROR]  redis.clients.jedis.exceptions.JedisConnectionException: Unexpected ...

  2. java对象和json对象之间互相转换

    import java.util.ArrayList;import java.util.Collection;import java.util.Iterator;import java.util.Li ...

  3. hdu_5762_Teacher Bo(鸽笼原理)

    题目链接:hdu_5762_Teacher Bo 题意: 给你n个点,问你能否找到两对点的曼哈顿距离相等 题解: 最开始看到这题,看数据以为要向nlogn的复杂度发展,结果经验误导了自己,我们仔细观察 ...

  4. Lotto

    Lotto Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submiss ...

  5. windowSoftInputMode键盘把输入框挡住了

    android:windowSoftInputMode="stateHidden|adjustResize" >

  6. 获取Excel数据(或部分数据)并导出成txt文本格式

    运行代码前先导入jxl架包,以下代码仅供参考: 测试excel文件(我要获取该excel的内容为省.县.乡.村.组和PH的值): ExcelTest01类代码如下: // 读取Excel的类 impo ...

  7. Too Much Money

    Too Much Money time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  8. CentOS下载及版本选择-CentOS LiveCD、LiveDVD和BinDVD区别

    1.CentOS系统镜像有两个,安装系统只用到第一个镜像即CentOS-6.x-i386-bin-DVD1.iso(32位)或者CentOS-6.x-x86_64-bin-DVD1.iso(64位), ...

  9. php ajax 下拉加载数据

    视图 <html> <head> <title>健康知识</title> <script type="text/javascript&q ...

  10. Loadrunner VuGen实战---基本组成、录制流程、协议、脚本优化、参数化(三)

    一.3大基本组件:VuGen.Controller.Analysis 1.VuGen:录制.编写脚本. 2.Controller:性能测试场景设计以及监控的地方. 3.Analysis:生成图表报告的 ...