Codeforces Round #357 (Div. 2) E. Runaway to a Shadow 计算几何
E. Runaway to a Shadow
题目连接:
http://www.codeforces.com/contest/681/problem/E
Description
Dima is living in a dormitory, as well as some cockroaches.
At the moment 0 Dima saw a cockroach running on a table and decided to kill it. Dima needs exactly T seconds for aiming, and after that he will precisely strike the cockroach and finish it.
To survive the cockroach has to run into a shadow, cast by round plates standing on the table, in T seconds. Shadow casted by any of the plates has the shape of a circle. Shadow circles may intersect, nest or overlap arbitrarily.
The cockroach uses the following strategy: first he equiprobably picks a direction to run towards and then runs towards it with the constant speed v. If at some moment t ≤ T it reaches any shadow circle, it immediately stops in the shadow and thus will stay alive. Otherwise the cockroach is killed by the Dima's precise strike. Consider that the Dima's precise strike is instant.
Determine the probability of that the cockroach will stay alive.
Input
In the first line of the input the four integers x0, y0, v, T (|x0|, |y0| ≤ 109, 0 ≤ v, T ≤ 109) are given — the cockroach initial position on the table in the Cartesian system at the moment 0, the cockroach's constant speed and the time in seconds Dima needs for aiming respectively.
In the next line the only number n (1 ≤ n ≤ 100 000) is given — the number of shadow circles casted by plates.
In the next n lines shadow circle description is given: the ith of them consists of three integers xi, yi, ri (|xi|, |yi| ≤ 109, 0 ≤ r ≤ 109) — the ith shadow circle on-table position in the Cartesian system and its radius respectively.
Consider that the table is big enough for the cockroach not to run to the table edges and avoid Dima's precise strike.
Output
Print the only real number p — the probability of that the cockroach will stay alive.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Sample Input
0 0 1 1
3
1 1 1
-1 -1 1
-2 2 1
Sample Output
0.50000000000
Hint
题意
有一个蟑螂,在x0,y0点,每秒移动,可以移动T秒,T秒后不在阴影中就会被拍死
阴影都是圆,现在给你圆心坐标和圆的半径。
这个蟑螂是随机选择一个方向走的
问你这个蟑螂活下来的概率是多少
题解:
蟑螂和圆都会有一个角度的区间,表示在T秒内能够到达这个阴影中
然后把所有区间拿出来,取并集
然后再除以2pi就好了
思路很简单。
取区间的这个东西,用简单的初中几何知识就能得到。
然后这道题就结束了。
代码
#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
double sqr(double x)
{
return x*x;
}
double dis(double x,double y,double x1,double y1)
{
return sqrt(sqr(x-x1)+sqr(y-y1));
}
vector<pair<double,int> >a;
double x,y,v,t,r;
int n;
int main()
{
scanf("%lf%lf%lf%lf",&x,&y,&v,&t);
r=v*t;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
double x0,y0,r0;
scanf("%lf%lf%lf",&x0,&y0,&r0);
double D=dis(x,y,x0,y0);
if(D<=r0)
{
cout<<"1.000000000"<<endl;
return 0;
}
if(r+r0+eps<D)continue;
double angl,angr,ang;
double angm=atan2(y0-y,x0-x);
if(angm<0)angm+=2*pi;
double len1 = sqrt(D*D-r0*r0);
if(len1<r+eps){
ang=asin(r0/D);
}
else{
ang=acos((D*D+r*r-r0*r0)/(2.0*D*r));
}
angl=angm-ang;
angr=angm+ang;
if(angl<0){
a.push_back(make_pair(angl+2*pi,1));
a.push_back(make_pair(2*pi,-1));
a.push_back(make_pair(0,1));
a.push_back(make_pair(angr,-1));
}
else if(angr>2*pi){
a.push_back(make_pair(angl,1));
a.push_back(make_pair(2*pi,-1));
a.push_back(make_pair(0,1));
a.push_back(make_pair(angr-2*pi,-1));
}
else{
a.push_back(make_pair(angl,1));
a.push_back(make_pair(angr,-1));
}
}
sort(a.begin(),a.end());
double ans = 0;
double last = 0;
int now = 0;
for(int i=0;i<a.size();i++)
{
if(now>0)
ans+=a[i].first-last;
last=a[i].first;
now+=a[i].second;
}
printf("%.12f\n",ans/(2*pi));
}
Codeforces Round #357 (Div. 2) E. Runaway to a Shadow 计算几何的更多相关文章
- Codeforces Round #357 (Div. 2) D. Gifts by the List 水题
D. Gifts by the List 题目连接: http://www.codeforces.com/contest/681/problem/D Description Sasha lives i ...
- Codeforces Round #357 (Div. 2) C. Heap Operations 模拟
C. Heap Operations 题目连接: http://www.codeforces.com/contest/681/problem/C Description Petya has recen ...
- Codeforces Round #357 (Div. 2) B. Economy Game 水题
B. Economy Game 题目连接: http://www.codeforces.com/contest/681/problem/B Description Kolya is developin ...
- Codeforces Round #357 (Div. 2) A. A Good Contest 水题
A. A Good Contest 题目连接: http://www.codeforces.com/contest/681/problem/A Description Codeforces user' ...
- Codeforces Round #357 (Div. 2) A
A. A Good Contest time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #357 (Div. 2) E 计算几何
传说中做cf不补题等于没做 于是第一次补...这次的cf没有做出来DE D题的描述神奇 到现在也没有看懂 于是只补了E 每次div2都是hack前2~3题 终于打出一次hack后的三题了...希望以后 ...
- Codeforces Round #357 (Div. 2) 优先队列+模拟
C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #357 (Div. 2) C
C. Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #357 (Div. 2) B
B. Economy Game time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
随机推荐
- 金蝶K3物料选择问题(感觉Ctrl被按住了一样)
金蝶K3在进入物料选择时,有时需要用Ctrl才可以进行多选,为什么有时不用Ctrl也可以进行多选,就像Ctrl被按住了一样? 解决:在物料选择界面按2次ctrl键单击物料可实现多选,再按2次ctrl则 ...
- SELinux 入门【转】
一.前言 安全增强型 Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统.SELinux 主要由美国国 ...
- oracle11g的冷热备份
1.冷备份 如果数据库可以正常关闭,而且允许关闭足够长的时间,那么就可以采用冷备份(脱机备份),可以是归档冷备份,也可以是非归档冷备份.其方法是首先关闭数据库,然后备份所有的物理文件,包括数据文件.控 ...
- Javascript中的Callback方法浅析
什么是callback? 回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用为调用它所指向的函数时,我们就说这是回调函数.回调函数不是由该函数 ...
- TF-搞不懂的TF矩阵加法
看谷歌的demo mnist,卷积后加偏执量的代码 h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)h_pool1 = max_pool ...
- node项目中用到的一些模块
1.http模块,用来搭建服务器 代码,简单服务器实现 var http = require('http'); http.createServer(function (request, respons ...
- java基础65 JavaScript中的Window对象(网页知识)
1.javaScript组成部分 1.EMCAScript(基本语法) 2.BOM(Browser Object Model):浏览器对象模型 浏览器对象模型中的浏览器的各 ...
- 20165333 2017-2018-2《Java程序设计》课程总结
一.每周作业链接汇总 1.预备作业一:我期望的师生关系 简要内容: 印象深刻的老师 我期望的师生关系 关于JAVA学习 2.预备作业二:学习基础和C语言学习基础 简要内容: 技能学习 C语言学习 关于 ...
- Drawable子类之——StateListDrawable (选择器)
Drawable子类之——StateListDrawable (选择器) https://www.jianshu.com/p/7257ce82c762 本文出自 “阿敏其人” 简书博客,转载或引用请注 ...
- sicily 1176. Two Ends (Top-down 动态规划+记忆化搜索 v.s. Bottom-up 动态规划)
Description In the two-player game "Two Ends", an even number of cards is laid out in a ro ...