Codeforces Round #365 (Div. 2) C

链接:http://codeforces.com/problemset/problem/703/C

分析:  这题其实是个大水题,只要短短的几行就可以搞定的, 首先需要直觉判断一点,就是只要判断最左边的点和最下面的点 以及和他们相邻边的右边的点

第二部我们就需要判断人与这两个边有没有交点,如果人与上面的有交点,那么人肯定就需要在下面的那条边等待  等待的时间是 max(x - y*1.0*v/u)

那么我们所需要做的还有一步就是判断就是需不需要等待 ,当min(x - y*1.0*v/u) >= 0(都没过) 或者max(x - y*1.0*v/u) <=0(都过了) 这两个时候,人都是可以直接全速前进

那么答案就是w*1.0/u  如果需要等待那么就要在不等待时间基础上加上等待的时间  那么要等待的时间是多少呢? max(x - y*1.0*v/u)/v

还有一点需要注意的是 需要用long double   我之前用double 写的 wa掉了 然后索性全部开成了 long long 和 long double

下面附上AC代码:

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    double w, v, u;
    long long n;
    long double maxx = -1e9;
    long double minx = 1e9;
    cin >> n >> w >> v >> u;
    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> x >> y;
        long double tmp = x - y*v*1.0/u;
        maxx = maxx > tmp ? maxx : tmp;
        minx = minx < tmp ? minx : tmp;
    }
    if(minx >= 0) cout << fixed << setprecision(10) << w*1.0/u << endl;
    else if(maxx > 0 && minx < 0) cout << fixed << setprecision(10) << (w*1.0/u + maxx/v) << endl;
    else if(maxx <= 0) cout << fixed << setprecision(10) << (w*1.0/u) << endl; 
    return 0;
}
posted @ 2016-08-06 11:33  BOSON+CODE  阅读(253)  评论(0编辑  收藏  举报