QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#822226#9869. Horizon ScanningpotpotWA 1ms4120kbC++203.1kb2024-12-20 02:07:212024-12-20 02:07:21

Judging History

你现在查看的是最新测评结果

  • [2024-12-20 02:07:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4120kb
  • [2024-12-20 02:07:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
	friend ostream& operator<<(ostream& os, P p) {
		return os << "(" << p.x << "," << p.y << ")"; }
};

void solve() {
    int n, k;
    cin >> n >> k;

    vector<Point<int>> islands(n);
    for (int i = 0; i < n; i++) {
        cin >> islands[i].x >> islands[i].y;
    }

    sort(islands.begin(), islands.end(), [](const auto& a, const auto &b) {
        return a.angle() < b.angle();
    });

    vector<pair<Point<int>, int>> angles;
    for (int i = 0; i < islands.size(); i++) {        
        double cur_angle = islands[i].angle();
        if (angles.size() == 0 || abs(cur_angle - angles[angles.size()-1].first.angle()) > 1e-5) {
            angles.push_back(make_pair(islands[i], 1));
        }
        else {
            angles[angles.size()-1].second++;
        }
    }
    // add 360o
    int sz = angles.size();
    for (int i = 0; i < sz; i++) {
        angles.push_back(make_pair(angles[i].first.rotate(2 * M_PI), angles[i].second));
    }
    double ans = 0.0;
    int l = 0, r = 0, cur_cnt = angles[0].second;
    while (r < angles.size()-1) {
        
        while (r < l + angles.size() && (cur_cnt <= k || l == r)) {
            r++;
            cur_cnt += angles[r].second;
        }

        
        if (l >= 0 && l < angles.size() && r >= l && r < angles.size()) {
            double angle_diff = angles[r].first.angle() - angles[l].first.angle();
            if (angle_diff < 0) angle_diff += 2 * M_PI;
            if (r == l + angles.size()) angle_diff = 2 * M_PI;
            // cout << "test " << l << " " << r << " " << angle_diff << "\n";
            ans = max(ans, angle_diff);
        }

        while (l+1 <= r && cur_cnt > k) {
            cur_cnt -= angles[l].second;
            l++;
        }
    }
    cout << fixed << setprecision(10) << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);

    int T;
    cin >> T;
    while (T--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4120kb

input:

5
1 1
0 1
8 2
1 0
1 1
0 1
-1 1
-1 0
-1 -1
0 -1
1 -1
4 2
-1 1
0 1
0 2
1 1
4 2
-1000000000 0
-998244353 1
998244353 1
1000000000 0
3 1
0 1
0 2
0 -1

output:

0.0000000000
1.5707963268
5.4977871438
3.1415926546
3.1415926536

result:

wrong answer 1st numbers differ - expected: '6.2831853', found: '0.0000000', error = '1.0000000'