想想上次非常挫啊!!500分愣是没弄明白样例,问题是犯了一个很小的错误!!! 一定要细心! 1000分,又是非常挫。。。很明显的二分。。一定要冷静想清楚问题!!!bless SRM457! 1000分,二分搜索寻找答案! #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <string> #include <cstring> using namespace std; //template<class T> T gcd(T a,T b){ if(a<0) return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);} //template <class T> T lcm(T a,T b){ return a*(b/gcd(a,b));} //template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); } // vector< string > words; istringstream sin(str); string t;while (sin >> t); words.push_back(t); class CutSticks { public: double maxKth(vector <int> sticks, int C, int K) { sort(sticks.begin(), sticks.end(), greater<int>()); double low = 0.0; double high = sticks[0]; long long can_make, present; // Repeat binary search a fixed number of times to deal with precision // instead of comparing doubles for (int i = 0; i < 500; i++) { double mid = (high + low)/2.0; can_make = present = 0LL; // Count the #pieces of length >= mid you can make // and the #pieces of length >= mid you already have for (int j = 0; j < sticks.size(); j++) { can_make += (long long)(double(sticks[j])/mid); present += (((long long)(double(sticks[j])/mid))?1LL:0LL); } // Check if the constraints are satisfied if (can_make >= K && C+present >= K) low = mid; else high = mid; } return low; } };