Codeforces Round #365 (Div. 2) C 计算几何
2016-08-05 18:21
399 查看
链接:戳这里
C. Chris and Road
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction
of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight
line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by
the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
output
5.0000000000
Note
Following image describes initial position in the first sample case:
![](http://codeforces.com/predownloaded/63/6b/636b3a29deae4428cbf36211370e1e33bfcaeeff.png)
题意:
一辆n个点组成的凸包汽车,以速度v行驶在路上,现在人在(0,0)点以<=u的速度过马路
人是会躲避大巴的,现在问通过街道到达(0,w)最少需要多少时间
思路:
大巴行驶如果拦住了行人,则行人要停下来等待或者擦着大巴的边走。
我们这样分析,相对运动大巴静止不动,行人的以(v,u)的方向行驶。
如果会碰到大巴,则直接等待大巴行驶一段时间(也就是左移一段距离),在过马路
现在二分这个等待的时间,使得大巴正好过去,行人可以擦着边过去
代码:
C. Chris and Road
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction
of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight
line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by
the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
output
5.0000000000
Note
Following image describes initial position in the first sample case:
![](http://codeforces.com/predownloaded/63/6b/636b3a29deae4428cbf36211370e1e33bfcaeeff.png)
题意:
一辆n个点组成的凸包汽车,以速度v行驶在路上,现在人在(0,0)点以<=u的速度过马路
人是会躲避大巴的,现在问通过街道到达(0,w)最少需要多少时间
思路:
大巴行驶如果拦住了行人,则行人要停下来等待或者擦着大巴的边走。
我们这样分析,相对运动大巴静止不动,行人的以(v,u)的方向行驶。
如果会碰到大巴,则直接等待大巴行驶一段时间(也就是左移一段距离),在过马路
现在二分这个等待的时间,使得大巴正好过去,行人可以擦着边过去
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string> #include<vector> #include <ctime> #include<queue> #include<set> #include<map> #include<stack> #include<iomanip> #include<cmath> #include<bitset> #define mst(ss,b) memset((ss),(b),sizeof(ss)) ///#pragma comment(linker, "/STACK:102400000,102400000") typedef long long ll; typedef long double ld; #define INF (1ll<<60)-1 #define Max 1e9 using namespace std; int n; struct point{ ld x,y; }s[10010]; const ld eps=1e-8; int dcmp(ld x){ if(fabs(x)<=eps) return 0; return x<0?-1:1; } bool check(ld v,ld u,ld t,int ty){ for(int i=0;i<n;i++){ if(ty*dcmp(v*s[i].y-u*(s[i].x-t*v))<0) return false; } return true; } ld w,v,u; int main(){ scanf("%d",&n); cin>>w>>v>>u; for(int i=0;i<n;i++) cin>>s[i].x>>s[i].y; cout<<fixed<<setprecision(12); if(check(v,u,0,-1)) cout<<w/u<<endl; else { ld l=0,r=1e10,mid; for(int i=1;i<=100;i++){ mid=(l+r)/2; if(check(v,u,mid,1)) r=mid; else l=mid; } cout<<w/u+(l+r)/2<<endl; } return 0; }
相关文章推荐
- 手机归属地
- HDU 5802 Windows 10
- mysql 添加远程访问
- iOS开发内存优化之自动检测内存泄露,检查是否有循环引用,检查内存为何如此大,Block循环引用的检查
- 设计模式-行为型-模板方法模式(Template Method Pattern)
- 基于zookeeper的分布式锁实现
- java内存模型-重排序
- 元启发式算法相关文献
- Java RTTI和反射的区别?
- LINUX文本处理工具讲解
- java.awt.Graphics2D 图片缩放
- test 20160805
- Jedis简单使用
- 测试时间的评估【搬运】
- Struts2 OGNL
- Android-管理应用内多个Activity思路
- 什么是awt ?
- 自己上传的ICON
- redis数据类型以及常用的命令
- Redis介绍及环境搭建