QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#826657#9869. Horizon ScanningTravelerRE 1ms4144kbC++202.4kb2024-12-22 15:04:282024-12-22 15:04:30

Judging History

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

  • [2024-12-22 15:04:30]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:4144kb
  • [2024-12-22 15:04:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define int long long
using i64 = long long;
struct Point {
    i64 x;
    i64 y;
    Point(i64 x = 0, i64 y = 0) : x(x), y(y) {}
};

bool operator==(const Point &a, const Point &b) {
    return a.x == b.x && a.y == b.y;
}

Point operator+(const Point &a, const Point &b) {
    return Point(a.x + b.x, a.y + b.y);
}

Point operator-(const Point &a, const Point &b) {
    return Point(a.x - b.x, a.y - b.y);
}
ld len(const Point &a) {
    return sqrtl(a.x * a.x + a.y * a.y);
}
//cos
i64 dot(const Point &a, const Point &b) {
    return a.x * b.x + a.y * b.y;
}
//sin
i64 cross(const Point &a, const Point &b) {
    return a.x * b.y - a.y * b.x;
}

inline bool cmp(Point A, Point B) { return (A.x == B.x) ? (A.y < B.y) : (A.x < B.x); }

Point O = {0, 0}, P = {-1, 0};
ll operator ^ (Point A, Point B) { return A.x * B.y - B.x * A.y; }
inline bool cmp_vec(Point A, Point B) {
    if (((P - O) ^ (A - O)) == 0 && (P.x - O.x) * (A.x - O.x) > 0) return 1;
    if (((P - O) ^ (B - O)) == 0 && (P.x - O.x) * (B.x - O.x) > 0) return 0;
    if ((((P - O) ^ (A - O)) > 0) != (((P - O) ^ (B - O)) > 0)) return ((P - O) ^ (A - O)) > ((P - O) ^ (B - O));
    return ((A - O) ^ (B - O)) > 0;
}

// void g(ld &a) {
//     a = max(a, ld(-0.999999999999999));
//     a = min(a, ld(0.999999999999999));
// }
const ld PI = 3.1415926536;
ld get(Point a, Point b) {
    ld ans = abs(atan2(abs(cross(a, b)), dot(a, b)));
    if(cross(a, b) >= 0) {
        return ans;
    } else {
        return 2.0 * PI - ans;
    }
}
void solve() {
    int n, k;
    cin >> n >> k;
    vector<Point> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i].x >> a[i].y;
    }
    sort(a.begin(), a.end(), cmp_vec);
    vector<Point> b(2 * n);
    for(int i = 0; i < n; i++) {
        b[i] = b[i + n] = a[i];
    }
    ld ans = 0;
    for(int i = 0; i < n; i++) {
        int j = i + k;
        if(j == i + n) ans = max(ans, 2.0 * PI);
        else ans = max(ans, get(b[i], b[j]));
    }
    cout << ans << "\n";
}           
    
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(9);
    int T = 1;
    cin >> T;
    while(T--) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4144kb

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.283185307
1.570796327
5.497787144
3.141592655
3.141592654

result:

ok 5 numbers

Test #2:

score: -100
Runtime Error

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.692991497
2.574863436
4.652758267
2.772633107
5.742765807
4.857698991
3.419892313
2.812799962
6.283185307
6.283185307
5.117280767
6.146782703
3.842089024
2.342496717
3.463343208
6.283185307
5.961434753
3.324703471
5.262774928
5.672459343
1.673877935
1.114190855
2.408777552
6.283185307
5.355890089
...

result: