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 |
简单易懂系列#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; int n,c,x[110000]; bool Isable(int d) { int cnt=1,t=x[1]; for(int i=2;i<=n;i++) if(x[i]-t>=d) { t=x[i];cnt++; if(cnt>=c)return true; } return false; } int main() { scanf("%d%d",&n,&c); for(int i=1;i<=n;i++) scanf("%d",&x[i]); sort(x+1,x+n+1); int l=1,r=x[n]-x[1]; while(l!=r) { int m=(l+r+1)>>1; if(Isable(m))l=m;else r=m-1; } printf("%d",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