标签:logs code space else class main turn span algorithm
思路:
满足二分性质...
二分一下 就完了
//By SiriusRen #include <cstdio> #include <algorithm> using namespace std; int n,k,a[500050],ans; bool check(int x){ int rec=0; for(int i=1;i<=n;){ int temp=a[i]+2*x;rec++; while(a[i]<=temp&&i<=n)i++; }return rec<=k; } int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=n;i++)scanf("%d",&a[i]); sort(a+1,a+1+n); int l=0,r=0x3f3f3f3f; while(l<=r){ int mid=(l+r)>>1; if(check(mid))ans=mid,r=mid-1; else l=mid+1; }printf("%d\n",ans); }
标签:logs code space else class main turn span algorithm
原文地址:http://www.cnblogs.com/SiriusRen/p/6654393.html