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 ...
随机推荐
- nginx配置浅析
一.nginx的介绍 nginx是由俄罗斯人开发的一款高性能的http和反向代理服务器,也可以用来作为邮件代理.相比较于其他的服务器,具有占用内存少,稳定性高等优势 二.nginx的配置 nginx的 ...
- Method for balancing binary search trees
Method for balancing a binary search tree. A computer implemented method for balancing a binary sear ...
- 虚拟环境pipenv的使用
安装虚拟环境 安装python3.6 python -m site --user-base 找到 用户基础目录 指定python版本的方式 pipenv --python 3.8 安装 用户范围内安装 ...
- c# CTS 基础数据类型笔记
C#中的基础数据类型并没有内置于c#语言中,而内置于.net freamework. C#有15个预定义类型,其中13个是值类型,两个是引用类型(string和object) 一.值类型 值类型 数据 ...
- Python2和Python3同时安装到Windows
上月已经把Python2安装好了,安装目录和及其下的Scripts也在安装时添加到了环境变量PATH中,可以使用python命令执行程序. 安装包:python-2.7.14.amd64.msi(没有 ...
- Python全局变量和局部变量
全局变量和局部变量 定义在函数内部的变量拥有一个局部作用域,定义在函数外的拥有全局作用域. 局部变量只能在其被声明的函数内部访问,而全局变量可以在整个程序范围内访问.调用函数时,所有在函数内声明的变量 ...
- html元素分类
目录 块级元素 内联元素 内联块级元素 总结 一.块级元素(block) 定义:默认情况下,独占一行的元素就是块级元素. 特点: 每个块级元素都从新的一行开始,并且其后的元素也另起一行.(真霸道,一 ...
- 使用html+css+js实现计算器
使用html+css+js实现计算器,开启你的计算之旅吧 效果图: 代码如下,复制即可使用: <!DOCTYPE html><html lang="en"> ...
- 【[SDOI2009]Bill的挑战】
一看题解好像全是状压DP,那么我就来补充一个容斥写法吧 乍一看,好像是水题,枚举选哪k个串,然后判断 1,如果这k个串中至少两个串某位置确定且不相同,答案显然为02,如果这个位置只被有且仅有一个串确定 ...
- C++静态成员的应用
当在类外部定义静态成员时,不能重复使用static关键字 静态成员函数不包含this指针(无论是显示还是隐式使用) 静态成员可以通过类对象进行访问,也可以通过类进行访问 静态成员不是由构造函数初始化的 ...