数学,递推。

不知道有没有更加神奇的做法,我是这样想的:

首先,如果多边形完全在$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的更多相关文章

  1. CodeForces 703C Chris and Road (简单几何)

    题意:有一个n边形的汽车向以速度v向x轴负方向移动,给出零时时其n个点的坐标.并且有一个人在(0,0)点,可以以最大速度u通过w宽的马路,到达(0,w)点.现在要求人不能碰到汽车,人可以自己调节速度. ...

  2. Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点

    // Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...

  3. Codeforces Round #365 (Div. 2) Chris and Road

    Chris and Road 题意: 给一个n个顶点的多边形的车,有速度v,人从0走到对面的w,人速度u,问人最快到w的时间是多少,车如果挡到人,人就不能走. 题解: 这题当时以为计算几何,所以就没做 ...

  4. cf703C Chris and Road

    C. Chris and Road time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. 暑假练习赛 003 B Chris and Road

    B - Chris and Road Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144K ...

  6. Codeforces 703C(计算几何)

    C. Chris and Road time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. 【23.15%】【codeforces 703C】Chris and Road

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 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 ...

  9. 【26.83%】【Codeforces Round #380C】Road to Cinema

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. C语言之循环结构 for(二)

    一 for循环的嵌套使用 for循环的嵌套语法: for(int i =0;i<10;i++){ for(int j=0;j<5;j++){ } } 一般用来打印平面,或者控制平面,或者说 ...

  2. 【C#】Creating/Querying/Modifying the .mdb databases

    As for databases, there are quit many kinds such as foxpro, mysql, sqlserver, etc. But when we need ...

  3. linux:C语言通过ICMP协议判断局域网内部主机是否存活

    ICMP协议 ICMP(Internet Control Message,网际控制报文协议)是为网关和目标主机而提供的一种差错控制机制,使它们在遇到差错时能把错误报告给报文源发方. ICMP协议是IP ...

  4. Python自动化开发-变量、数据类型和运算

    一.变量 变量定义:Variables are used to store infomation to referrenced and manipulated in a computer progra ...

  5. Jquery Form表单取值

    之前js取form表单的值都是一个一个的取,数量一多之后容易出错而且烦透了.感谢那些愿意分享的人. 页面定义form,并给form指定id值,里面的元素只要是需要键值对应的都赋予name属性,并且na ...

  6. Redmine插件及使用

    Plugins Plugin list A full list of available Redmine plugins can be found at the Plugin Directory. M ...

  7. find指令

    1.命令格式 find path -options [-print -exec -ok ...] 2.命令功能 查找文件,并作出相应处理 3.命令参数

  8. 中兴电信光纤猫F450获取管理员密码方法

    初衷:为了完成端口映射,一开始以为电信光猫不支持自定义路由,因为通过useradmin登录进去后没有找到对应的选项.一番了解之后,原来光猫有超级密码,电信装机时是不会告诉你的,电信客服一般也不会告诉你 ...

  9. httpclient用法

    Http通信方式:HttpURLConnection和HttpClient HttpURLConnection是java的标准类,什么都没封装,用起来太原始,不方便HttpClient就是一个增强版的 ...

  10. openstack私有云布署实践【10.2 计算nova - controller节点配置(办公网环境)】

    一.首先登录controller1创建nova数据库,并赋于远程和本地访问的权限.     mysql -u root -p   CREATE DATABASE nova; GRANT ALL PRI ...