标签:style blog color io os for sp div log
1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 using namespace std; 5 6 unsigned int N; 7 unsigned int C; 8 vector<int> x; 9 int stall; 10 11 int main() 12 { 13 /***************************************************/ 14 //input and preprocessing 15 16 cin >> N >> C; 17 for(int i = 0; i < N; ++i) 18 { 19 int temp; 20 cin >> temp; 21 x.push_back(temp); 22 } 23 sort(x.begin(), x.end()); 24 25 26 /***************************************************/ 27 //solver 28 int lower = 0; 29 int upper = 1000000000; 30 int mid; 31 while(upper - lower > 1) 32 { 33 mid = (upper + lower) / 2; 34 35 /***************************************************/ 36 //calc 37 stall = 1; 38 for(int i = 0, j = 0; i < x.size(); ) 39 { 40 if(x[i] - x[j] >= mid) 41 { 42 ++stall; 43 j = i; 44 ++i; 45 } 46 else 47 { 48 ++i; 49 } 50 51 } 52 //end calc 53 /***************************************************/ 54 if(stall >= C) 55 lower = mid; 56 else 57 upper = mid; 58 } 59 60 /***************************************************/ 61 //output 62 63 cout << lower << endl; 64 return 0; 65 }
标签:style blog color io os for sp div log
原文地址:http://www.cnblogs.com/shuanghong/p/4033111.html