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 ...
随机推荐
- 安装scount的es驱动,composer require tamayo/laravel-scout-elastic报错解决
执行 composer require tamayo/laravel-scout-elastic 报错信息如下: Problem 1 - Installation request for tamayo ...
- C# 调用第三方DLL缓冲区溢出导致的异常
这个倒是少见的错误,纪录一下大佬. 先上异常 错误一:尝试读取或写入受保护的内存 错误二:未将对象引用设置到对象的实例 错误三: 托管调试助手“FatalExecutionEngineError”( ...
- vue2.0组件生命周期探讨
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- android开发中设置字体
转自:http://segmentfault.com/q/1010000000494116 http://ryanhoo.github.io/blog/2014/05/05/android-bette ...
- SAP云平台架构概述
在我们开始SAP云平台的架构之旅之前,让我们先看看SAP已经发布的一些其他云产品.这些云产品方案可以分为公有云和私有云两种. SAP公有云解决方案见下图最右侧,比较著名的有SAP SuccessFac ...
- python程序的编辑和运行、变量
第一个python程序 python是解释型弱类型高级语言 常见的python解释器CPython.IPython.pypy.JPython.IronPython 方法一.python程序可以写在命令 ...
- COM技术开发(一)
COM :基本的接口(IX,IY), 组件的实现(CA),以及对组件的调用 #include "pch.h" #include <iostream> #include ...
- Node.js快速生成26个字母
const buf1 = Buffer.allocUnsafe(26); for (let i = 0; i < 26; i++) { // 97 是 'a' 的十进制 ASCII 值. buf ...
- 8. Truncate undo表空间
8. Truncate undo表空间 要Truncate Undo 表空间,必须为MySQL实例配置至少两个undo表空间(两个undo表空间可确保一个undo表空间保持活动状态,另一个处于脱机状态 ...
- npm start问题
问题:在执行命令npm start 是出现下列问题: npm [] WARN invalid config loglevel="notice" [] npm WARN invali ...