template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } classSolution { using Point = complex<double>; public: intvisiblePoints(vector<vector<int>>& points, int a, vector<int>& location){ double angle = a; constint n = points.size(); Point me {static_cast<double>(location[0]), static_cast<double>(location[1])}; vector<double> ps; ps.reserve(2 * points.size()); int same = 0; for (constauto & v : points) { if (v == location) { ++same; continue; } Point x {static_cast<double>(v[0]), static_cast<double>(v[1])}; ps.push_back(arg(x - me)*(180/M_PI)); } constint s = ps.size(); for (int i = 0; i < s; ++i) { ps.push_back(ps[i] + 360); } sort(ps.begin(), ps.end()); // cout << ps << endl; constdouble error = 1e-8; int l = 0, r = 0; int ans = 0; for (; r < ps.size(); ++r) { if (ps[r] - ps[l] > angle + error) { ++l; } ans = max(ans, r - l + 1); // cout << r << " " << l << endl; } returnmin(ans, n) + same; } };
时间复杂度: O(N log N),
空间复杂度: O(N).
1611. Minimum One Bit Operations to Make Integers Zero