Codeforces Round #365 (Div. 2) C题(线性约束)
来源:互联网 发布:stc单片机iap选型 编辑:程序博客网 时间:2024/05/16 19:51
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 andy = w, there is a bus moving, presented as a convex polygon ofn vertices. The bus moves continuously with a constant speed ofv in a straight Ox line in direction of decreasingx coordinates, thus in time only x coordinates of its points are changing. Formally, after timet each of x coordinates of its points will be decreased byvt.
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 exceedingu. Thus the pedestrian can move only in a straight lineOy in any direction with any speed not exceedingu 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.
The first line of the input contains four integersn, 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 ofi-th polygon point. It is guaranteed that the polygon is non-degenerate.
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 exceed10 - 6.
5 5 1 21 23 14 33 41 4
5.0000000000
Following image describes initial position in the first sample case:
题意:有一个N边形的车,车速为v,你在原点,你的速度为u,想要到达(0,w),问人最快到达(0,w)点的时间。显然,车如果挡住你,你就不能走。
题解:
你走过去的情况就分两种:车对你没造成影响,车对你造成影响。
当车对你没造成影响又分两种情况:你的速度太快了,车的速度太快了。
分析这些情况1:你的速度太快了。车的任意一点都到达不了你的位置。既 xi/v>yi/u。
2:车的速度太快了,你到达 车任意一点在y轴的投影时,车已经过去了。既xi/v<yi/u.
3:车对你造成影响,此时你需要调整速度来躲车,我们可以换一种角度看,当车最后一个点通过的时候,你在内个点上,此时需要的时间就是车走xi 速度为v所需要的时间,再后面的路程(w-yi),你以速度u走。
1,2两种情况人都可以以最大速度u走。
代码:
#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <cmath>#include <set>#include <map>#include <vector>#include <queue>#include <algorithm>#define LL long long#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define maxn 300100using namespace std;int n;double v,u,x,y,w,ans;int main(){ cin>>n>>w>>v>>u; bool flag,flagg; flag=flagg=false; ans=0; for(int i=0;i<n;i++) { cin>>x>>y; if(x/v>y/u) flag=true; if(x/v<y/u) flagg=true; ans=max(ans,x/v+(w-y)/u); } if(flag&&flagg) printf("%.10lf\n",ans); else printf("%.10lf\n",w/u);}
- Codeforces Round #365 (Div. 2) C题(线性约束)
- Codeforces Round #448 (Div. 2): C. Square Subsets(线性基)
- Codeforces Round #365 (Div. 2) A~C
- codeforces round #365 (div.2) C
- Codeforces Round #365 (Div. 2) C
- Codeforces Round 134 div 2 C题
- Codeforces Round #153 (Div. 2) C题
- Codeforces Round #158 (Div. 2) C题
- Codeforces Round #257 (Div. 2) C题
- Codeforces Round #277.5 (Div. 2)(C题)
- Codeforces Round #404 (Div. 2) C题
- Codeforces Round #287 (Div. 2) C
- Codeforces Round #291 (Div. 2)(C)
- Codeforces Round #261 (Div. 2)C题(思维题)
- Codeforces Round #279 (Div. 2) (C题)
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #365 (Div. 2) -- C. Chris and Road (思路水题)
- Codeforces Round #367 (Div. 2) C. Hard problem 朴素dp、线性dp
- 数据结构 环形单链表的约瑟夫问题
- 一位ACMer过来人的心得
- fir.im Weekly - Mobile developer 利器分享
- android 6.0权限申请
- 创建桌面快捷方式
- Codeforces Round #365 (Div. 2) C题(线性约束)
- 进制转换中1的个数--E
- 每日一linux命令(46)-------telnet命令
- Python 遍历文件夹的方法:
- ./ ../ /之间的区别
- 关于Android 签名的问题
- 为什么我们应该尽快升级到 HTTPS?
- DataCastle[用户人品预测竞赛]——获奖团队分享
- mysql与oracle中时间函数