【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 ...
随机推荐
- oled的一套stm32实验2(自己的实验)
stm32与OLED屏接口的引脚介绍: CS————GPIOD3: RST————GPIOD4: DC—————GPIOD5: D0——————GPIOD6: D1——————GPIOD7; 上是我参 ...
- kafka集群原理介绍
目录 kafka集群原理介绍 (一)基础理论 二.配置文件 三.错误处理 kafka集群原理介绍 @(博客文章)[kafka|大数据] 本系统文章共三篇,分别为 1.kafka集群原理介绍了以下几个方 ...
- js课程 2-8 js内置对象有哪些
js课程 2-8 js内置对象有哪些 一.总结 一句话总结:JS中内置了17个对象,常用的是Array对象.Date对象.正则表达式对象.string对象.Global对象. 1.js常用对象有哪些? ...
- MySQL启动关闭添加到 /etc/init.d/mysqld
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld 然后就可以使用此命令启动/关闭 mysql: /etc/ini ...
- POJ 3090 Visible Lattice Points (ZOJ 2777)
http://poj.org/problem?id=3090 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1777 题目大意: ...
- php用两个栈来实现队列
php用两个栈来实现队列 一.总结 我主要的问题是不知道的是题目描述,题目和贵的代码之间的关系,以及返回值 思路:A栈做入队操作,B栈做出队操作,入队的时候元素直接入A,出队的时候判断B栈是否为空,如 ...
- 魔兽争霸war3心得体会(四):不死族vs人族1本火魔塔
QQ对战平台上玩随机的人特别多,为了应对对方的"出其不意",我最近一直用小狗去探路,小狗在家采集30个木头-摆放商店,就可以去探路了.主要有几个好处:知道对方的种族-出生点位-开局 ...
- 【41.43%】【codeforces 560C】Gerald's Hexagon
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- [JS Compose] 6. Semigroup examples
Let's we want to combine two account accidently have the same name. , friends: ['Franklin'] } , frie ...
- Linux下图形界面调试工具kdbg安装及測试
1.Ubuntu系统下安装 Ubuntu系统安装比較方便,直接apt-get即可 apt-get install kdbg 2.centos 安装 首先,在这个地址下下载rpm包.然后使用rpm命令安 ...