標籤:
連結: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