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代码#include<iostream> #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll a[50005]; bool C(ll x,int n); ll l; int m,n; int main() { while(~scanf("%I64d%d%d",&l,&m,&n)) { a[0]=0; for(int i=1;i<=m;i++) scanf("%d",&a[i]); sort(a,a+m+1); ll ub=0,lb=l,ans; while(lb>=ub) { ll mid=(lb+ub)>>1; if(C(mid,m-n)) { ub=mid+1; ans=mid; } else lb=mid-1; } printf("%I64d\n",ans); } } bool C(ll x,int n) { int pre=0,crt=1; int ans=0; for(crt=1;crt<=m;crt++) { if(a[crt]-a[pre]>=x&&l-a[crt]>=x) { ans++; pre=crt; } } if(ans>=n) return true; else return false; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator