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 |
为什么二分时在a[i]-a[pre]=mid 时也要取出石头代码: long long a[50005]; int main() { long long L; int n,m; scanf("%I64d %d %d",&L,&n,&m); long long l=1e10,r=L; for(int i=1;i<=n;i++) { scanf("%I64d",&a[i]); } a[0]=0; a[n+1]=L; sort(a,a+n+2); for(int i=1;i<=n+1;i++) { l=min(l,a[i]-a[i-1]);//二分一般要注意初始边界 } while(l<r) { long long mid=(l+r)/2; long long pre=0,stone=0; for(int i=1;i<=n+1;i++) { if(a[i]-a[pre]<=mid)//= 这里一定要取 = wa无数次TAT { stone++; } else{ pre=i; } } if(stone>m) r=mid; else l=mid+1; //cout<<l<<' '<<r<<endl; } printf("%I64d\n",l); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator