CodeForces 703C Chris and Road
数学,递推。
不知道有没有更加神奇的做法,我是这样想的:
首先,如果多边形完全在$y$轴左侧,那么答案为$\frac{w}{u}$。
剩下的情况就要先判断是否能在车开过之前跑过去,如果跑不过去,要在车慢慢开过$y$轴的时候,一起慢慢跑上去。

那么先来判断是否能在车开过之前跑过去:
如上图所示,如果要在车来车前跑过去,那么等价于要求:对于凸包左侧蓝色链上的每一个点$L[i]$,满足$\frac{{L[i].y}}{u} ≤ \frac{{L[i].x}}{v}$,即人要比点先到。如果有一个点不满足,那么就人就无法在车来前跑过去。如果可以的话,答案为$\frac{w}{u}$。
剩下的情况就是凸包右侧黄色链开过$y$轴时,人同时走上去。这种情况的答案,递推一下就能算出来了,如果人走到$(0,R[i].y)$所花的时间为$ans$,那么人走到$(0,R[i+1].y)$的时间$ans$更新为$\max (ans + \frac{{\left( {R\left[ {i + 1} \right].y-R\left[ i \right].y } \right)}}{u},\frac{{R[i].x}}{v})$,想一想也能想明白吧~
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
} const int INF=;
const int maxn=;
int n,w,v,u,len1,len2;
struct X { int x,y; }p[maxn],L[maxn],R[maxn]; int main()
{
scanf("%d%d%d%d",&n,&w,&v,&u);
for(int i=;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y); int ymin=INF,ymax=-INF,f,p1,p2; bool flag;
for(int i=;i<=n;i++) ymin=min(ymin,p[i].y), ymax=max(ymax,p[i].y);
f=INF; for(int i=;i<=n;i++) if(p[i].y==ymin&&p[i].x<f) f=p[i].x,p1=i;
f=INF; for(int i=;i<=n;i++) if(p[i].y==ymax&&p[i].x<f) f=p[i].x,p2=i; flag=; for(int i=p1;i>=;i--) { L[len1++]=p[i]; if(i==p2) { flag=; break; } }
if(flag==) for(int i=n;i>=p2;i--) L[len1++]=p[i]; f=-INF; for(int i=;i<=n;i++) if(p[i].y==ymin&&p[i].x>f) f=p[i].x,p2=i;
f=-INF; for(int i=;i<=n;i++) if(p[i].y==ymax&&p[i].x>f) f=p[i].x,p1=i; flag=; for(int i=p1;i>=;i--) { R[len2++]=p[i]; if(i==p2) { flag=; break; } }
if(flag==) for(int i=n;i>=p2;i--) R[len2++]=p[i]; for(int i=;i<len2/;i++) swap(R[i],R[len2-i-]);
bool fail=; for(int i=;i<len1;i++) if((LL)L[i].y*(LL)v>(LL)L[i].x*(LL)u) { fail=; break; } int xmax=-INF; for(int i=;i<=n;i++) xmax=max(xmax,p[i].x);
if(xmax<=) fail=;
if(fail==) printf("%.6lf\n",1.0*w/u);
else
{
double ans=; int pre=;
for(int i=;i<len2;i++)
{
ans=ans+1.0*(R[i].y-pre)/u; pre=R[i].y;
ans=max(ans,1.0*R[i].x/v);
}
ans=ans+1.0*(w-pre)/u;
printf("%.6lf\n",ans);
}
return ;
}
CodeForces 703C Chris and Road的更多相关文章
- CodeForces 703C Chris and Road (简单几何)
题意:有一个n边形的汽车向以速度v向x轴负方向移动,给出零时时其n个点的坐标.并且有一个人在(0,0)点,可以以最大速度u通过w宽的马路,到达(0,w)点.现在要求人不能碰到汽车,人可以自己调节速度. ...
- Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...
- Codeforces Round #365 (Div. 2) Chris and Road
Chris and Road 题意: 给一个n个顶点的多边形的车,有速度v,人从0走到对面的w,人速度u,问人最快到w的时间是多少,车如果挡到人,人就不能走. 题解: 这题当时以为计算几何,所以就没做 ...
- cf703C Chris and Road
C. Chris and Road time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 暑假练习赛 003 B Chris and Road
B - Chris and Road Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144K ...
- Codeforces 703C(计算几何)
C. Chris and Road time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 【23.15%】【codeforces 703C】Chris and Road
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Educational Codeforces Round 15 D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 【26.83%】【Codeforces Round #380C】Road to Cinema
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- 结构-行为-样式-requireJs实现图片轮播插件
最近工作需要,就自己写了一个图片轮播插件,不过想到要集成到框架中,于是又用RequireJs改了一遍. 主要文件: style.css jquery-1.11.1.min.js require.js ...
- 【C#】Get the html code of a webpage
As for the title,the console program will show you a sample which can get the webpage-code.Enjoy it: ...
- CodeForces 631D Messenger
$KMP$. $n=1$和$n=2$的时候可以单独计算.$n>2$时,可以拿字符和数字分别做一次匹配,然后扫描一遍判断一下就可以计算出答案了. #pragma comment(linker, & ...
- 对于笔试题--“good and abc”的理解
今天朋友问了一个面试题,题目如下: public class Example{ String str=new String("good"); char[]ch={'a','b',' ...
- ios_swift开发资源整理
目录 1.苹果官方资源 2.国内外视频网站推荐 3.中文文档 4.demo网站 5.开发工具推荐 6.国内外开发网站论坛 7.技术博客推荐 8.书籍推荐 9.第三方框架推荐 10.第三方发布平台 11 ...
- 我理解的session和cookie
tomcat管理session 理解tomcat是如何生成session的. 当用户请求到web资源有request.getSession()这段代码的时候,request首先会对请求的url判读是否 ...
- Linux 操作命令列表记录
Linux 操作命令列表记录 SSH登录 登录 ## 范式 ssh [username]@[host] ## 例 ssh -p 1222 root@10.0.0.1 使用非默认端口(ssh默认端口22 ...
- 51nod1092(lcs简单运用/dp)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1092 题意:中文题诶- 思路: 解法1:最坏的情况就是在原字 ...
- WinForms 实现气泡提示窗口(转载)
[实例说明] 气泡提示因为他的美观又好被大多数用户所接收,用户所喜爱的就是程序员要实现的. 本实例实现了任务栏气泡提示,运行本实例,效果图如下所示: 单击提示.气泡提示就会显示,单击“关闭”气泡又会消 ...
- [Q]安装问题(找不到InstallUtilLib.dll)
安装时提示 使用下面的方法解决(参考) 一.如果您的系统提示“没有找到Installutillib.Dll”或者“缺少Installutillib.Dll”等类似错误信息,请把Installutill ...