Codeforces 703C(计算几何)
2 seconds
256 megabytes
standard input
standard 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 linesy = 0 and y = 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 liesstrictly 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 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 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 2
1 2
3 1
4 3
3 4
1 4
5.0000000000
Following image describes initial position in the first sample case:
题目大意:
人从原点出发,可以以小于等于u的任意速度向上或向下运动,一个n边型的车以恒定的速度v向左运动(竟然有车长得这么奇葩),给出车各个点的初始坐标。求人在不被车撞的前提下最快到达对面的时间。
解题思路:
一共有两种情况。
第一种情况、人开始就一直以u的速度往前走,没有被车撞。那么时间最短就是w/u。
第二种情况,人要在车后面过去。那么为了时间最短人一定要安全的前提下尽量贴着车走才能时间最短。
我们可以将问题看成车不动,人先水平移动一段距离,再沿着斜率为u/v的直线运动。那么就变成了平移直线使其与车相切。由于车的每条边都是直线,那么切点一定在顶点上。我们只要枚举全部顶点,一个点和一个斜率就可以确定一条直线。我们只要找到最左边和最右边一条直线则这两条直线与车一定是相切的。这时切线与x轴交点如果在原点左边,那么就是第一种情况。否则是第二种情况。在我们新建的模型下时间就非常好求。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
int n,w,v,u;
int main()
{
scanf("%d%d%d%d",&n,&w,&v,&u);
double k=u*1.0/v,l=(double)(<<)-,r=;
int i;
//cout<<l<<endl;
for (i=;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
l=min(l,x-y/k);
r=max(r,x-y/k);
}
printf("%.10lf\n",l>?w*1.0/u:r/v+w*1.0/u);
return ;
}
Codeforces 703C(计算几何)的更多相关文章
- CodeForces 703C Chris and Road
数学,递推. 不知道有没有更加神奇的做法,我是这样想的: 首先,如果多边形完全在$y$轴左侧,那么答案为$\frac{w}{u}$. 剩下的情况就要先判断是否能在车开过之前跑过去,如果跑不过去,要在车 ...
- Codeforces Gym100543B 计算几何 凸包 线段树 二分/三分 卡常
原文链接https://www.cnblogs.com/zhouzhendong/p/CF-Gym100543B.html 题目传送门 - CF-Gym100543B 题意 给定一个折线图,对于每一条 ...
- CodeForces 703C Chris and Road (简单几何)
题意:有一个n边形的汽车向以速度v向x轴负方向移动,给出零时时其n个点的坐标.并且有一个人在(0,0)点,可以以最大速度u通过w宽的马路,到达(0,w)点.现在要求人不能碰到汽车,人可以自己调节速度. ...
- 【23.15%】【codeforces 703C】Chris and Road
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #335 (Div. 1) C. Freelancer's Dreams 计算几何
C. Freelancer's Dreams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contes ...
- Codeforces 749B:Parallelogram is Back(计算几何)
http://codeforces.com/problemset/problem/749/B 题意:已知平行四边形三个顶点,求另外一个顶点可能的位置. 思路:用向量来做. #include <c ...
- Codeforces Round #339 (Div. 1) A. Peter and Snow Blower 计算几何
A. Peter and Snow Blower 题目连接: http://www.codeforces.com/contest/613/problem/A Description Peter got ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends(思维+计算几何?)
传送门 https://www.cnblogs.com/violet-acmer/p/10146350.html 题意: 有一块 n*m 的棋盘,初始,黑白块相间排列,且左下角为白块. 给出两个区间[ ...
- Codeforces 528E Triangles 3000 - 计算几何
题目传送门 传送点I 传送点II 传送点III 题目大意 给定$n$的平面上的直线,保证没有三条直线共点,两条直线平行.问随机选出3条直线交成的三角形面积的期望. 显然$S=\frac{1}{2}ah ...
随机推荐
- B树、B+树、红黑树、AVL树
定义及概念 B树 二叉树的深度较大,在查找时会造成I/O读写频繁,查询效率低下,所以引入了多叉树的结构,也就是B树.阶为M的B树具有以下性质: 1.根节点在不为叶子节点的情况下儿子数为 2 ~ M2. ...
- -bash: mysql: command not found 之 MAC
第一次尝试: ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql 提示:Operation not permitted 再次,加sudo附上管理员权限,依旧 ...
- webapi参数处理get过个参数
// GET api/values/5 [HttpGet("{logInName}/{pwd}/{orgId}")] public LogInOutPut Get(string l ...
- vba,自定义公式,农历互转公历,excel ,wps
'vba 模块内容如下 自定义公式 '公历转农历模块 '原创:互联网 '修正: '// 农历数据定义 // '先以 H2B 函数还原成长度为 18 的字符串,其定义如下: '前12个字节代表1-12月 ...
- Eclipse被卡死了或者失去响应了后分析根源的一个小技巧
提升程序员工作效率的工具/技巧推荐系列 推荐一个功能强大的文件搜索工具SearchMyFiles 介绍一个好用的免费流程图和UML绘制软件-Diagram Designer 介绍Windows任务管理 ...
- Android(java)学习笔记155:中文乱码的问题处理(qq登录案例)
1. 我们在之前的笔记中LoginServlet.java中,我们Tomcat服务器回复给客户端的数据是英文的"Login Success","Login Failed& ...
- EasyX库进行图片绘制函数
引用函数:loadimage参数: // 从图片文件获取图像(bmp/jpg/gif/emf/wmf/ico)void loadimage( IMAGE* pDstImg, // 保存图像的 IMAG ...
- iview modal 弹框 模板
iview modal 弹框 模板 <!-- * @description 上传图片 * @fileName camera.vue * @author 彭成刚 * @date // :: * @ ...
- WebGL 绘制Line的bug(一)
今天说点跟WebGL相关的事儿,不知道大家有没有碰到过类似的烦恼. 熟悉WebGL的同学都知道,WebGL绘制模式有点.线.面三种:通过点的绘制可以实现粒子系统等,通过线可以绘制一些连线关系:面就强大 ...
- 约束RMQ
不知道为什么网上找不到太多相关的资料,所以写一个小总结,并附有能用的代码,抛砖引玉. 约束RMQ,就是RMQ区间必须满足两项之差最大为1,采用ST表的话,这时候有O(n)建表,O(1)查询的优秀复杂度 ...