poj 3258:River Hopscotch(二分)
生活随笔
收集整理的這篇文章主要介紹了
poj 3258:River Hopscotch(二分)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接
L為N+2塊石子中最右邊石子位置,0最左,M為可移除塊數,求移除后相鄰石子可達到的最大距離。
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; typedef int LL;LL L,N,M; LL a[50005];bool ok(LL x) {int cnt=0;for(int i=0,j=1;j<=N;j++) //i:當前保留石塊最靠右的一個 if(a[j]-a[i]<x) cnt++;else i=j;return cnt<=M; } LL search(LL l,LL r) {while(r-l>1){LL mid=(l+r)/2;if(ok(mid)) l=mid;else r=mid;}return l; }int main() {ios_base::sync_with_stdio(false);while(cin>>L>>N>>M){a[0]=0;a[++N]=L;for(int i=1;i<N;i++)cin>>a[i];sort(a,a+N);LL Min=1e9+7;for(int i=1;i<=N;i++)Min=min(Min,a[i]-a[i-1]);cout<<search(Min,L)<<endl;} }?
轉載于:https://www.cnblogs.com/Just--Do--It/p/6405025.html
總結
以上是生活随笔為你收集整理的poj 3258:River Hopscotch(二分)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: idea下的调试配置
- 下一篇: 1. 青蛙跳跳FrogJmp Count