Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一次AC贴上代码^~^/*对rock间的距离进行二分*/ #include<iostream> #include <algorithm> #define Max 50005 using namespace std; int rock[Max]; int l,n,m,mn; bool judge(int x)//判断可移除的rock是否大于m { int del=0; for (int i=1,j=0;i<=n+1;) { if(rock[i]-rock[j]<=x) { del++;i++; } else { j=i;i++; } } if(del>m) return true;//right=mid-1; else return false;//left=mid+1; } int main() { while(cin>>l>>n>>m) { rock[0]=0;rock[n+1]=l; for (int i=1;i<=n;i++) { scanf("%d",&rock[i]); if(mn>rock[i]) mn=rock[i]; } sort(rock+1,rock+n+1); int right=l,left=mn; while(left<=right) { int mid=(right+left)>>1; if (judge(mid)) { right=mid-1; } else { left=mid+1; } } cout<<left<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator