Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)
生活随笔
收集整理的這篇文章主要介紹了
Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
The Meeting Place Cannot Be Changed
我發現我最近越來越zz了,md 連調程序都不會了,首先要有想法,之后輸出如果和期望的不一樣就從輸入開始一步一步地調啊,tmd現在輸出不一樣就知道在那等著,有毛用啊.
【題目鏈接】The Meeting Place Cannot Be Changed
【題目類型】二分答案
&題解:
二分時間,判斷函數比較難想,要先假設所有人都向左走,找到坐標最大的那個,之后在假設所有人都向右走,找到坐標最小的那個,如果最大的<=最小的就行了
&代碼:
#include <cstdio> #include <iostream> #include <set> #include <cmath> #include <cstring> #include <algorithm> #include <map> #include <queue> #include <vector> using namespace std; #define INF 0x3f3f3f3f using ll=long long; const int maxn= 6e4 +9; int n,x[maxn],v[maxn]; double eps = 1e-6; bool ok(double t) {double ma=-2e9,mi=2e9; // printf("mi=%f\n",mi);for(int i=0;i<n;i++){ma=max(ma,x[i]-v[i]*t);mi=min(mi,x[i]+v[i]*t); // printf("i=%d x[i]=%d v[i]=%d mi=%f\n",i,x[i],v[i],mi);} // printf("ma %f mi %f\n",ma,mi);return ma<=mi; } int main() { // ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);//freopen("C:\\Users\\Zmy\\Desktop\\in.txt", "r", stdin);scanf("%d",&n);for(int i=0;i<n;i++) scanf("%d",&x[i]);for(int i=0;i<n;i++) scanf("%d",&v[i]);double l=0,r=1e9;while(l-r<=eps){double mid=(l+r)/2;if(ok(mid)) r=mid-eps;else l=mid+eps;}printf("%.7f\n",l);return 0; }轉載于:https://www.cnblogs.com/s1124yy/p/6517591.html
總結
以上是生活随笔為你收集整理的Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: FreePascal - 如何在各个平台
- 下一篇: 经常遇到的浏览器的兼容性有哪些?