Codeforces Round #365 (Div. 2) C

來源:互聯網
上載者:User

標籤:

連結: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;}

Codeforces Round #365 (Div. 2) C

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.