zoukankan      html  css  js  c++  java
  • cf703C Chris and Road

    C. Chris and Road
    time limit per test 2 seconds
    memory limit per test 256 megabytes
    input standard input
    output 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 lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of nvertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in timeonly x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.

    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 exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u 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 lies strictly 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.

    Input

    The first line of the input contains four integers nwvu (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 of i-th polygon point. It is guaranteed that the polygon is non-degenerate.

    Output

    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 exceed 10 - 6.

    Example
    input
    5 5 1 2
    1 2
    3 1
    4 3
    3 4
    1 4
    output
    5.0000000000
    Note

    Following image describes initial position in the first sample case:

    这题简直坑上天

    一个多边形给出各个顶点一开始位置,从右往左以v速度扫过去,人站在(0,0),现在要到(0,w)去,速度不能超过u,问最小时间

    首先,换个参考系,假设多边形不动,人和终点同时获得一个向右的速度v

    然后这样想:如果某一时刻让人的速度小于u,那么这个一定可以用一段全速加上一段停止来替换。因此考虑减速是没有意义的,那么人要么全速要么停止

    如果全速,人在x方向上有个向右的速度v,在y方向有个向上的速度u,它的轨迹是一条斜率为k=u/v的直线

    如果停止,相当于人在x轴上向右滑动

    显然应该先停止再运动

    那么轨迹应该是这样的

    这图一画出来做法显然啊,先看看直接走能不能走,不能走的话因为多边形一定是经过直线y=u/v*x的,而且是连着的一大块,那么一定可以找到一条直线,使得这条直线恰好相切,而且右边的直线都相离。这显然可以二分

    至于看看直线有没有穿过内部,看看点是不是都在直线一侧就好了。这里我直接判p[i].y-k*p[i].x-b大于还是小于0而懒得用向量做了

    这题真的有毒啊。。eps设成1e-9就T了设成1e-7就A

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<algorithm>
     6 #include<cmath>
     7 #include<queue>
     8 #include<deque>
     9 #include<set>
    10 #include<map>
    11 #include<ctime>
    12 #define LL long long
    13 #define inf 0x7ffffff
    14 #define eps 1e-7
    15 using namespace std;
    16 inline LL read()
    17 {
    18     LL x=0,f=1;char ch=getchar();
    19     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    20     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    21     return x*f;
    22 }
    23 inline void write(LL a)
    24 {
    25     if (a<0){printf("-");a=-a;}
    26     if (a>=10)write(a/10);
    27     putchar(a%10+'0');
    28 }
    29 inline void writeln(LL a){write(a);printf("
    ");}
    30 int n,w,v,u;
    31 double l,r,k,b,ans;
    32 struct point{int x,y;}p[100010];
    33 inline bool jud(long double k,long double b)
    34 {
    35     int tota=0,totb=0;
    36     for (int i=1;i<=n;i++)
    37     {
    38         if (k*p[i].x+b-p[i].y<0)tota++;
    39         else totb++;
    40         if (tota&&totb)return 0;
    41     }
    42     return 1;
    43 }
    44 int main()
    45 {
    46     n=read();w=read();v=read();u=read();
    47     for (int i=1;i<=n;i++)
    48     {
    49         p[i].x=read();
    50         p[i].y=read();
    51     }
    52     k=(double)u/v;
    53     if (jud(k,0.0)){printf("%.8lf",(double)w/u);return 0;}
    54     l=0;r=1e9;
    55     while (r-l>eps)
    56     {
    57         double mid=(l+r)/2;
    58         if (jud(k,(double)-mid/v*u)){ans=(double)w/u+mid/v;r=mid;}
    59         else l=mid;
    60     }
    61     printf("%.8lf
    ",ans);
    62 }
    cf703C
    ——by zhber,转载请注明来源
  • 相关阅读:
    MQ消息队列(2)—— Java消息服务接口(JMS)
    MQ消息队列(1)—— 概念和使用场景
    SpringBoot — HelloWorld开发部署
    redis的配置文件介绍
    Redis info 参数详解
    10 分钟彻底理解 Redis 的持久化和主从复制
    Docker Yearning + Inception SQL审核平台搭建
    Inception SQL审核注解
    运行python脚本后台执行
    解决yum [Errno 256] No more mirrors to try
  • 原文地址:https://www.cnblogs.com/zhber/p/5745909.html
Copyright © 2011-2022 走看看