FZU 2144 Shooting Game(数学+贪心)
主要思路:求出蚊子到达球的时间区间(用方程得解),对区间做一个贪心的选择,选择尽可能多的区间有交集的区间段(结构体排序即可),然后计数.
#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(数学+贪心)的更多相关文章
- FZU 2144 Shooting Game (贪心区域划分)
Problem 2144 Shooting Game Accept: 370 Submit: 1902 Time Limit: 1000 mSec Memory Limit : 32768 KB Pr ...
- FZU 2144 Shooting Game
Shooting Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- ACM学习历程—FZU 2144 Shooting Game(计算几何 && 贪心 && 排序)
Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (May ...
- Problem 2144 Shooting Game fzu
Problem 2144 Shooting Game Accept: 99 Submit: 465Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- 洛谷3月月赛div2 题解(模拟+数学+贪心+数学)
由于本人太蒻了,div1的没有参加,胡乱写了写div2的代码就赶过来了. T1 苏联人 题目背景 题目名称是吸引你点进来的. 这是一道正常的题,和苏联没有任何关系. 题目描述 你在打 EE Round ...
- UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- HDOJ 5073 Galaxy 数学 贪心
贪心: 保存连续的n-k个数,求最小的一段方差... .预处理O1算期望. .. Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- FZU Problem 2221 RunningMan(贪心)
一开始就跑偏了,耽误了很长时间,我和队友都想到博弈上去了...我严重怀疑自己被前几个博弈题给洗脑了...贪心的做法其实就是我们分两种情况,因为A先出,所以B在第一组可以选择是赢或输,如果要输,那直接不 ...
- hdu 3573(数学+贪心)
Buy Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- OpenCV中Mat的列向量归一化
OpenCV中Mat的列向量归一化 http://blog.csdn.net/shaoxiaohu1/article/details/8287528 OpenCV中Mat的列向量归一化 标签: Ope ...
- CSS样式与选择器
CSS构造块的样式: 1. h1{color:red;background-color:yellow} 其中:h1是选择器,花括号内是声明部分.多个声明之间用分号隔开. 2.为样式规则添加注释:/* ...
- hdu_3555_Bomb(数位DP)
题目连接:hdu_3555_Bomb 题意:和2089一样,只是数据大了点,不过道理是一样的 #include<cstdio> #include<cstring> #defin ...
- IntelliJ IDEA 7.0 正式版注册机代码
好神奇,第一次看见注册机的源代码,自己运行一下.可以是java IDE环境,也可以是配置好jdk的dos环境. 然后输入自己的用户名就可以获得相对应的注册码,输入到软件中即可. 仅供参考,请购买正版. ...
- 修改一个Label上字体的大小(富文本)
假如修改上面的Label上价格30000的大小,那么需要用到富文本 上代码 // 字符串30000 NSString * priceNumber = @"30000"; [pric ...
- jquery checkbox 操作
1.jquery 获取所有选中和未选中的checkbox 未选中 var unCheckedBoxs = $("input[name='myCheckbox']").not(&qu ...
- flowers
问题大全 Do you like flowers?(Why?) What flowers do you like?(why?) What is your favorite flower? Are fl ...
- http請求瀏覽器的緩存機制
轉載自:http://kb.cnblogs.com/page/73901/ 流程 当资源第一次被访问的时候,HTTP头部如下 (Request-Line) GET /a.html HTTP/1.1 H ...
- 学习笔记:GLSL Core Tutorial – Vertex Shader(内置变量说明)
1.每个Vertex Shader都有用户定义的输入属性,例如:位置,法线向量和纹理坐标等.Vertex Shaders也接收一致变量(uniform variables). uniform vari ...
- php 图片压缩处理
<?php require dirname(__FILE__).'/../includes/common.inc.php'; $_clean = array(); $_info = array( ...