标签:cout integer tin bsp ace this mini 代码 ati
Input
Output
Sample Input
5 3 1 2 8 4 9
Sample Output
3
Hint
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 #include<stack> 7 #include<string> 8 #include<algorithm> 9 #include<map> 10 #include<sstream> 11 #include<set> 12 #define debug(x) cout << "[" << #x <<": " << (x) <<"]"<< endl 13 #define CLE(a,b) memset(a,b,sizeof(a)) 14 #define MEC(a,b) memcpy(a,b,sizeof(a)) 15 #define ll long long 16 #define inff 0x7fffffff 17 //const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 }; 18 //const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 }; 19 //const int dx[9] = { 0,0,1,-1 }; 20 //const int dy[9] = { 1,-1,0,0 }; 21 //struct { 22 23 //}; 24 const int inf = 1e9 + 5; 25 ll book[100005]; 26 int c, n; 27 int judge(int d) 28 { 29 int cur, lef = 0; 30 for (int i = 1;i < c;i++) 31 { 32 cur = lef + 1; 33 while (cur < n && book[cur] - book[lef] < d) 34 { 35 cur++; 36 } 37 if (cur == n) 38 return 0; 39 lef = cur; 40 } 41 return 1; 42 } 43 using namespace std; 44 int main() 45 { 46 cin >> n >> c; 47 for (int i = 0;i < n;i++) 48 { 49 cin >> book[i]; 50 } 51 sort(book, book + n); 52 int l = 0, r = inf; 53 int ans = 0; 54 while (r >= l) 55 { 56 int mid = (l + r) >> 1; 57 if (judge(mid)) 58 { 59 ans = mid; 60 l = mid + 1; 61 } 62 else r = mid - 1; 63 } 64 cout << ans << endl; 65 return 0; 66 }
标签:cout integer tin bsp ace this mini 代码 ati
原文地址:https://www.cnblogs.com/cqcqygranhj/p/12325610.html