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 ...
随机推荐
- oracle if else 判断
CREATE OR REPLACE FUNCTION fn_GetClassifyBymxmjazfs (v_azfs varchar2,v_mx varchar2,v_mj varchar2) re ...
- 【CSS学习笔记】CSS选择器
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- hdu1041
#include <iostream> #include <string> using namespace std; const int SIZE = 1001; const ...
- ListView控制消息
ListView控制消息 ListView控制消息是提供给父窗口或其他窗口通过发消息来控制ListView窗口本身. ListView控件提供给了以下消息来让外部程序控制自身: ListView_Ap ...
- shell 字符串包含
转自:Shell判断字符串包含关系的几种方法 现在每次分析网站日志的时候都需要判断百度蜘蛛是不是真实的蜘蛛,nslookup之后需要判断结果中是否包含"baidu"字符串 以下给出 ...
- <video>和<audio>标签,对视频和音频的支持
H5新增了<video>和<audio>标签,提供对视频和音频的支持 <audio>的属性与<video>属性相同 <video> vide ...
- IIS错误解决办法(HTTP Error 500.19 - Internal Server Error)
window10 切换登陆用户,VS2015的IIS Express 调试代码报HTTP Error 500.19 - Internal Server Error 错误,无法读取配置文件解决办法. I ...
- 【IE6的疯狂之八】链接伪类(:hover)CSS背景图片有闪动BUG
IE6下链接伪类(:hover)CSS背景图片有闪动BUG,主要原因ie会再一次请求这张图片,或者说图片没被缓存. 例如: CSS代码 a:hover{background:url(imagepath ...
- Attempt to write to field 'android.support.v4.app.FragmentManagerImpl android.support.v4.app.Fragment.mFragmentManager' on a null object reference
E/AndroidRuntime﹕ FATAL EXCEPTION: mainProcess: org.example.magnusluca.drawertestapp, PID: 3624java. ...
- awk学习笔记二:调用shell、文件执行(转)
awk 'BEGIN {print "Hello"}' 不操作文件直接处理数据流 要调用shell则可以用管道命令 如,打印日期awk 'BEGIN {"date&quo ...