QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#822230#9869. Horizon ScanningpotpotWA 79ms4196kbC++202.0kb2024-12-20 02:23:422024-12-20 02:23:42

Judging History

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

  • [2024-12-20 02:23:42]
  • 评测
  • 测评结果:WA
  • 用时:79ms
  • 内存:4196kb
  • [2024-12-20 02:23:42]
  • 提交

answer

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

struct Point {
    int x, y;
};

double pi() {
    return atan(1) * 4.0;
}

double cal_angle(Point p) {
    return atan2(p.y, p.x) + 2 * pi();
}

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

    vector<Point> 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 cal_angle(a) < cal_angle(b);
    });

    vector<pair<double, int>> angles;
    for (int i = 0; i < islands.size(); i++) {        
        double cur_angle = cal_angle(islands[i]);
        if (angles.size() == 0 || abs(cur_angle - angles[angles.size()-1].first) > 1e-5) {
            angles.push_back(make_pair(cur_angle, 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 + 2 * pi(), angles[i].second));
    }
    double ans = 0.0;
    int l = 0, r = 0, cur_cnt = angles[0].second;
    int prev_l = 0;
    while (r < angles.size()) {
        
        while (r+1 <= l + sz && r+1 < angles.size() && cur_cnt < k) {
            r++;
            cur_cnt += angles[r].second;
        }

        // cout << "test " << l << " " << r << " " << cur_cnt << "\n";
        if (r + 1 < angles.size())
            ans = max(ans, angles[r+1].first - angles[l].first);

        while (l+1 <= r && cur_cnt >= k) {
            cur_cnt -= angles[l].second;
            l++;
        }
        if (l == prev_l) {
            l++;
            if (l == angles.size()-1) break;
            r = l;
            cur_cnt = angles[l].second;
        }
        prev_l = 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: 100
Accepted
time: 0ms
memory: 4160kb

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:

6.2831853072
1.5707963268
5.4977871438
3.1415926546
3.1415926536

result:

ok 5 numbers

Test #2:

score: -100
Wrong Answer
time: 79ms
memory: 4196kb

input:

10000
16 1
-10 -6
-5 -6
-4 9
-2 5
-2 10
1 -7
1 -5
1 6
3 1
4 -9
6 -10
6 -3
6 1
8 -5
8 -4
9 -4
17 4
-9 2
-8 -4
-8 -3
-8 -1
-6 -2
-6 -1
-6 8
-5 -8
-5 10
-4 8
-2 -8
4 -9
4 0
5 -3
8 -5
9 -2
10 10
10 6
-7 2
-4 6
-2 -7
-2 -1
-1 7
1 -9
1 8
3 -4
7 -4
9 -2
14 3
-9 10
-8 -10
-8 -8
-6 -7
-6 -5
-1 -7
-1 -2
0 -1
...

output:

1.6929914975
2.5748634361
4.6527582673
2.7726331074
5.4977871438
4.8576989910
3.4198923126
2.8127999621
6.2831853072
6.2831853072
5.1172807667
6.1467827028
3.8420890235
2.3424967168
3.4633432080
6.2831853072
5.9614347528
3.3247034709
5.2627749281
5.6724593428
1.6738779353
1.1141908549
2.4087775518
6...

result:

wrong answer 5th numbers differ - expected: '5.7427658', found: '5.4977871', error = '0.0426587'