【23.15%】【codeforces 703C】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:

【题解】
题意:你要从(0,0)走到(0,w),右方有一部多边形的车从右往左走过来;你要花最少的时间走到(0,w),且不被车撞。
做法:
对于所有的点。获取->当你和车上的这个点(px,py)的坐标的纵坐标相同的时候,车上的这个点的横坐标为多少;
设你和这个点的纵坐标相同时所花的时间为t=py/u
则车上这个点的横坐标px’变为px-t*v
获取车上的所有点的px’中的max和min值
分类讨论:
1.最简单的。就是直接高速走过去都不会被车撞->即到达(0,0)->(0,w)这条线段上的所有点的时候。车子的所有点都在你到达之前就全都走过了。或者全都还没到达.
->对应min >=0 || (min <0 && max <=0)的情况
答案当然就是w/u了
2.可能会被撞.
即min <0 but max >0
就需要减速了。
需要怎么减速呢?我们把它理解为停顿一下;
对于我们求出来的max,它对应上图的情况。(车子从右往左移动对应人从左下往左上);
即我们全速前进和从下往上数第二个波峰的纵坐标相同的时候.横坐标的差值.因为这个差值的存在,所以我们会被车撞。
当前第一个波峰的时候也会被车撞。
但是显然第二个波峰造成的影响需要修正的地方更大;
那么要怎么修正呢?
首先我们可以确定。我们到达第二个波峰的时候(虽然会被撞)但是时间是最短的。因为是全速前进的。
那么我们想保留这个最快的过程应该要怎么样呢.
这样理解:
即把这条线段往右平移一段。这样我们全速前进到和第二个波峰的纵坐标相同的时候。刚好碰到那个波峰(题目设定这样不算被撞)。到了波峰之后只要全速前进就可以到终点了。
那这个平移代表什么呢?
当然就是在起点等了一段时间->max/v
所以总的时间就是
max/v+w/u;
这里你们可能会想到:那第一个波峰呢?
实际上我们是不会碰到第一个波峰的。因为我们在处理的时候已经知道AB这段长度max是大于d1的了。
而我们和W和B点的纵坐标相同的时候,经过的点分别是Q和A
如果我们向右平移了max个单位。max>d1则肯定我们走平移过的路线之后和W的纵坐标相同的时候,肯定是在W的右边的.也就是说W这个点肯定已经走到x=0的左边去了。
多想想吧.
可能有人会想到这种情况。
这样不就不对了吗???
但是注意车的点的纵坐标是大于0的!
所以图中的A点是不合法的.
再多说几句吧:
设max对应的点,即倒数第二张图的B点。
我们肯定是要到那个坐标的;
而我们得知到那个坐标之后你得等那个B点从你身前走过去,而你是全速前进的,所以到达B点的最短时间肯定就是yb/u了但是你得等这个B点走过去;这又是不得不等的一段时间;所以我们干脆就在起点等这段时间过去,然后马上以最高时速到达这个B点,这样肯定满足时间最短,且这个B点刚好走到左边去了,过后就是康庄大道了。可以一直以高速前进.
综上这个方法是可行的。
别想了,我的脑子。就是这样了。睡觉吧。
(博主是强迫症患者TAT)
#include <cstdio>
#include <algorithm>
using namespace std;
const double INF = 1e15;
int n;
double w, v, u;
double mi=INF, ma = 0,ans;
int main()
{
scanf("%d%lf%lf%lf", &n, &w, &v, &u);
for (int i = 1; i <= n; i++)
{
int x, y;
scanf("%d%d", &x, &y);
double dis = x - y/u*v;
ma = max(ma, dis);
mi = min(mi, dis);
}
if (mi >= 0)
ans = w / u;
else//mi <0
if (ma<= 0)
ans = w / u;
else//ma > 0
ans = ma / v + w / u;
printf("%.10lf\n", ans);
return 0;
}
【23.15%】【codeforces 703C】Chris and Road的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【23. 合并K个排序链表】【困难】【优先队列/堆排序】
合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6] 输出: 1->1-> ...
- 【20.23%】【codeforces 740A】Alyona and copybooks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.33%】【codeforces 557B】Pasha and Tea
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.39%】【codeforces 558C】Amr and Chemistry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【15.07%】【codeforces 625A】Guest From the Past
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【30.23%】【codeforces 552C】Vanya and Scales
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【16.23%】【codeforces 586C】Gennady the Dentist
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.26%】【codeforces 747D】Winter Is Coming
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- 微信小程序常见的UI框架/组件库总结
想要开发出一套高质量的小程序,运用框架,组件库是省时省力省心必不可少一部分,随着小程序日渐火爆,各种不同类型的小程序也渐渐更新,其中不乏一些优秀好用的框架/组件库. 1:WeUI 小程序–使用教程 h ...
- 【Codeforces Round #431 (Div. 1) B】
[链接]h在这里写链接 [题意] 场上有 n 个点,它们分别向上与向右在不同时刻开始运动,相遇则改变移动方向,求最终这些点到达的坐标. [题解] 先把每个点的坐标都往它本该移动的方向相反的方向退ti个 ...
- 动词 + to do、动词 + doing
1. 含义有重大区别 动词+to do 与 动词 + doing,具有较大含义上的差别的动词主要有: stop finish forget 在这些单词的后面,自然 to do 表示未做的事,doing ...
- 使用DNSCrypt解决Dropbox污染问题
作者:半点闲 时间:2014-6-27 18:27 博客:blog.csdn.net/cg_i 邮箱:b_dx@sohu.com 背景知识:防火长城(GFW) keyword:DNSCrypt ...
- 2.CCGridAction(3D效果),3D反转特效,凸透镜特效,液体特效,3D翻页特效,水波纹特效,3D晃动的特效,扭曲旋转特效,波动特效,3D波动特效
1 类图组织 2 实例 CCSprite * spr = CCSprite::create("HelloWorld.png"); spr->setPosition(cc ...
- UI 06 ScrollView 的手动循环播放 与 自己主动循环播放
假设想要循环播放的话, scrollView的照片前要加上最后一张图片, 最后要加上第一张图片. - (void)viewDidLoad { [super viewDidLoad]; // Do an ...
- DOS命令具体解释
net use $">\\ip\ipc$Content$nbsp;" " /user:" " 建立IPC空链接 net use $" ...
- Opencv距离变换distanceTransform应用——细化字符轮廓&&查找物体质心
Opencv中distanceTransform方法用于计算图像中每一个非零点距离离自己最近的零点的距离,distanceTransform的第二个Mat矩阵参数dst保存了每一个点与最近的零点的距离 ...
- Jedis 源代码阅读一 —— Jedis
这是jedis 源代码文件夹,我们接下来选择性阅读重要的接口以及实现. └─redis └─clients ├─jedis │ │ BinaryClient.java │ │ BinaryJedis. ...
- 从0開始学习 GitHub 系列之「07.GitHub 常见的几种操作」
之前写了一个 GitHub 系列,反响非常不错,突然发现居然还落下点东西没写,前段时间 GitHub 也改版了,借此机会补充下. 我们都说开源社区最大的魅力是人人多能够參与进去,发挥众人的力量,让一个 ...