题意理解的有些问题。
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define LL __int64 7 LL p[501001]; 8 int n; 9 int judge(int x,int m) 10 { 11 int pre = 0,num = 0,i; 12 for(i = 0;i <= n;i ++) 13 { 14 if(p[i] - pre <= x) 15 ; 16 else 17 { 18 num ++; 19 pre = p[i-1]; 20 } 21 } 22 if(num + 1 > m) 23 return 0; 24 else 25 return 1; 26 } 27 int main() 28 { 29 int m,i,l; 30 LL str,mid,end,minz; 31 while(scanf("%d%d%d",&l,&n,&m)!=EOF) 32 { 33 for(i = 0; i < n; i ++) 34 scanf("%I64d",&p[i]); 35 sort(p,p+n); 36 if(n == 0||m == 1) 37 { 38 printf("%d ",l); 39 continue; 40 } 41 p[n] = l; 42 minz = p[0]; 43 for(i = 0;i < n;i ++) 44 { 45 minz = max(minz,p[i+1]-p[i]); 46 } 47 str = minz;end = l; 48 while(str < end) 49 { 50 mid = (str+end)/2; 51 if(judge(mid,m) == 0) 52 str = mid + 1; 53 else 54 end = mid; 55 } 56 printf("%I64d ",str); 57 } 58 return 0; 59 }