QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#807989#9869. Horizon ScanningFalse0099WA 20ms4336kbC++202.2kb2024-12-10 15:39:182024-12-10 15:39:19

Judging History

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

  • [2024-12-10 15:39:19]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:4336kb
  • [2024-12-10 15:39:18]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1); // 统一使用`acos(-1)`计算 PI 的值
typedef pair<int, int> PII;

struct Node {
    double degree;
    int count;
};

void init() {
    // 可用于初始化全局变量或执行必要的设置
}

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

    vector<double> degrees(n + 1);
    vector<Node> aa;

    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        degrees[i] = atan2(y, x);
        // if (degrees[i] < 0) {
        //     degrees[i] += 2 * PI; // 改为使用统一的 PI
        // }
    }

    sort(degrees.begin() + 1, degrees.end());

    for (int i = 1; i <= n; i++) {
        if (!aa.empty() && abs(degrees[i] - aa.back().degree) < 1e-9) { // 防止浮点误差
            aa.back().count++;
        } else {
            aa.push_back({degrees[i], 1});
        }
    }

    int m = aa.size();
    vector<int> sum_cnt(2 * m);
    for (int i = 0; i < m; i++) {
        aa.push_back({aa[i].degree + 2 * PI, aa[i].count}); // 将环状角度映射到线性区间
    }

    sum_cnt[0] = aa[0].count;
    for (int i = 1; i < 2 * m; i++) {
        sum_cnt[i] = sum_cnt[i - 1] + aa[i].count;
    }

    double ans = 0;

    // 滑动窗口计算最小角度范围
    auto calc = [&](int i, int j) {
        if (i == 0) {
            return sum_cnt[j] - max(aa[i].count, aa[j].count);
        } else {
            return sum_cnt[j] - sum_cnt[i - 1] - max(aa[i].count, aa[j].count);
        }
    };

    for (int i = 0, j = 0; i < m; i++) {
        j = max(i, j);
        while (j + 1 < aa.size() && calc(i, j) < k) {
            j++;
        }
        if (j < aa.size() && calc(i, j) >= k) {
            ans = max(ans, aa[j].degree - aa[i].degree);
        }
    }

    ans = min(ans, 2 * PI); // 最终角度范围不能超过 2PI
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cout << fixed << setprecision(10);

    int t;
    cin >> t;
    init();

    while (t--) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 4336kb

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: 20ms
memory: 4272kb

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.7427658069
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 48th numbers differ - expected: '4.8391565', found: '4.9786410', error = '0.0288241'