QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593037#9253. Prism PalacergnerdplayerAC ✓43ms9420kbC++207.8kb2024-09-27 11:13:372024-09-27 11:13:37

Judging History

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

  • [2024-09-27 11:13:37]
  • 评测
  • 测评结果:AC
  • 用时:43ms
  • 内存:9420kb
  • [2024-09-27 11:13:37]
  • 提交

answer

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

using i64 = long long;

using Real = long double; // modify these if needed
constexpr Real eps = 1e-9;

template <typename T>
int sign(T x) {
    return (x > 0) - (x < 0);
}
int sign(Real x) {
    return (x > eps) - (x < -eps);
}
template <typename T>
int cmp(T a, T b) {
    return sign(a - b);
}

template <typename T>
struct P {
    T x = 0, y = 0;
    P(T x = 0, T y = 0) : x(x), y(y) {}
    friend istream& operator>>(istream &is, P &p) { return is >> p.x >> p.y; }
    friend ostream& operator<<(ostream &os, P p) { return os << p.x << ' ' << p.y; }
    friend bool operator==(P a, P b) { return cmp(a.x, b.x) == 0 && cmp(a.y, b.y) == 0; }
    friend bool operator!=(P a, P b) { return !(a == b); }
    P operator-() { return P(-x, -y); }
    P& operator+=(P a) {
        x += a.x, y += a.y;
        return *this;
    }
    P& operator-=(P a) {
        x -= a.x, y -= a.y;
        return *this;
    }
    P& operator*=(T d) {
        x *= d, y *= d;
        return *this;
    }
    P& operator/=(T d) {
        x /= d, y /= d;
        return *this;
    }
    friend P operator+(P a, P b) { return P(a) += b; }
    friend P operator-(P a, P b) { return P(a) -= b; }
    friend P operator*(P a, T d) { return P(a) *= d; }
    friend P operator/(P a, T d) { return P(a) /= d; }
    friend bool operator<(P a, P b) {
        int sx = cmp(a.x, b.x);
        return sx != 0 ? sx == -1 : cmp(a.y, b.y) == -1;
    }
};

template <typename T>
struct L {
    array<P<T>, 2> l;
    L(P<T> a = {}, P<T> b = {}) : l{a, b} {}
};

template <typename T>
T dot(P<T> a, P<T> b) { return a.x * b.x + a.y * b.y; }

template <typename T>
T square(P<T> a) { return dot(a, a); }

template <typename T>
T dist2(P<T> a, P<T> b) { return square(a - b); }

template <typename T>
Real length(P<T> a) { return sqrtl(square(a)); }

template <typename T>
Real dist(P<T> a, P<T> b) { return length(a - b); }

template <typename T>
T cross(P<T> a, P<T> b) { return a.x * b.y - a.y * b.x; }

template <typename T>
T cross(P<T> p, P<T> a, P<T> b) { return cross(a - p, b - p); }

template <typename T>
P<Real> normal(P<T> a) {
    Real len = length(a);
    return P<Real>(a.x / len, a.y / len);
}

template <typename T>
bool up(P<T> a) { return sign(a.y) > 0 || sign(a.y) == 0 && sign(a.x) > 0; }

// 3 colinear? please remember to remove (0, 0)
template <typename T>
bool polar(P<T> a, P<T> b) {
    bool ua = up(a), ub = up(b);
    return ua != ub ? ua : sign(cross(a, b)) == 1;
}

template <typename T>
bool parallel(P<T> a, P<T> b) {
    return sign(cross(a, b)) == 0;
}

template <typename T>
bool sameDirection(P<T> a, P<T> b) {
    return sign(cross(a, b)) == 0 && sign(dot(a, b)) == 1;
}

// 1 if on a->b's left
template <typename T>
int side(P<T> p, P<T> a, P<T> b) { return sign(cross(p, a, b)); }

template <typename T>
int side(P<T> p, L<T> l) { return side(p, l.l[0], l.l[1]); }

template <typename T>
P<T> rotate90(P<T> p) {
    return {-p.y, p.x};
}

P<Real> rotate(P<Real> p, Real ang) {
    return {p.x * cos(ang) - p.y * sin(ang), p.x * sin(ang) + p.y * cos(ang)};
}

template <typename T>
Real angle(P<T> p) {
    return atan2(p.y, p.x);
}

template <typename T>
P<T> direction(L<T> l) {
    return l.l[1] - l.l[0];
}

template <typename T>
bool parallel(L<T> l1, L<T> l2) {
    return sameDirection(direction(l1), direction(l2));
}

template <typename T>
bool sameDirection(L<T> l1, L<T> l2) {
    return sameDirection(direction(l1), direction(l2));
}

P<Real> projection(P<Real> p, L<Real> l) {
    auto d = direction(l);
    return l.l[0] + d * (dot(p - l.l[0], d) / square(d));
}

P<Real> reflection(P<Real> p, L<Real> l) {
    return projection(p, l) * 2 - p;
}

Real pointToLineDist(P<Real> p, L<Real> l) {
    if (l.l[0] == l.l[1]) { return dist(p, l.l[0]); }
    return abs(cross(l.l[0] - l.l[1], l.l[0] - p)) / length(direction(l));
}

// better use integers if you don't need exact coordinate
// l <= r is not explicitly required

template <typename T>
P<T> lineIntersection(L<T> l1, L<T> l2) {
    return l1.l[0] - direction(l1) * (Real(cross(direction(l2), l1.l[0] - l2.l[0])) / cross(direction(l2), direction(l1)));
}

template <typename T>
bool between(T m, T l, T r) {
    return cmp(l, m) == 0 || cmp(m, r) == 0 || l < m != r < m;
}

template <typename T>
bool pointOnSeg(P<T> p, L<T> l) {
    return side(p, l) == 0 && between(p.x, l.l[0].x, l.l[1].x) && between(p.y, l.l[0].y, l.l[1].y);
}

template <typename T>
bool pointStrictlyOnSeg(P<T> p, L<T> l) {
    return side(p, l) == 0 && sign(dot(p - l.l[0], direction(l))) * sign(dot(p - l.l[1], direction(l))) < 0;
}

template <typename T>
bool overlap(T l1, T r1, T l2, T r2) {
    if (l1 > r1) { swap(l1, r1); }
    if (l2 > r2) { swap(l2, r2); }
    return cmp(r1, l2) != -1 && cmp(r2, l1) != -1;
}

template <typename T>
bool segIntersect(L<T> l1, L<T> l2) {
    auto [p1, p2] = l1;
    auto [q1, q2] = l2;
    return overlap(p1.x, p2.x, q1.x, q2.x) && overlap(p1.y, p2.y, q1.y, q2.y) &&
            side(p1, l2) * side(p2, l2) <= 0 &&
            side(q1, l1) * side(q2, l1) <= 0;
}

// parallel intersecting is false
template <typename T>
bool segStrictlyIntersect(L<T> l1, L<T> l2) {
    auto [p1, p2] = l1;
    auto [q1, q2] = l2;
    return side(p1, l2) * side(p2, l2) < 0 &&
           side(q1, l1) * side(q2, l1) < 0;
}

// parallel or intersect at source doesn't count
template <typename T>
bool rayIntersect(L<T> l1, L<T> l2) {
    int x = sign(cross(l1.l[1] - l1.l[0], l2.l[1] - l2.l[0]));
    return x == 0 ? false : side(l1.l[0], l2) == x && side(l2.l[0], l1) == -x;
}

template <typename T>
Real pointToSegDist(P<T> p, L<T> l) {
    auto d = direction(l);
    if (sign(dot(p - l.l[0], d)) >= 0 && sign(dot(p - l.l[1], d)) <= 0) {
        return pointToLineDist(p, l);
    } else {
        return min(dist(p, l.l[0]), dist(p, l.l[1]));
    }
}

template <typename T>
Real segDist(L<T> l1, L<T> l2) {
    if (segIntersect(l1, l2)) { return 0; }
	return min({pointToSegDist(l1.l[0], l2), pointToSegDist(l1.l[1], l2),
            pointToSegDist(l2.l[0], l1), pointToSegDist(l2.l[1], l1)});
}

// 2 times area
template <typename T>
T area(vector<P<T>> a) {
    T res = 0;
    int n = a.size();
    for (int i = 0; i < n; i++) {
        res += cross(a[i], a[(i + 1) % n]);
    }
    return res;
}

template <typename T>
bool pointInPoly(P<T> p, vector<P<T>> a) {
    int n = a.size(), res = 0;
    for (int i = 0; i < n; i++) {
        P<T> u = a[i], v = a[(i + 1) % n];
        if (pointOnSeg(p, {u, v})) { return 1; }
        if (cmp(u.y, v.y) <= 0) { swap(u, v); }
        if (cmp(p.y, u.y) > 0 || cmp(p.y, v.y) <= 0) { continue; }
        res ^= cross(p, u, v) > 0;
    }
    return res;
}

using Point = P<i64>;
using Line = L<i64>;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    auto solve = [&]() {
        int n;
        cin >> n;

        vector<Point> p(n);
        for (int i = 0; i < n; i++) {
            cin >> p[i];
        }

        if (area(p) < 0) {
            reverse(p.begin(), p.end());
        }

        constexpr Real pi = numbers::pi;

        auto get = [&](int i) {
            Real x = angle(p[(i + n - 1) % n] - p[i]);
            Real y = angle(p[(i + 1) % n] - p[i]);
            if (x < y) {
                x += 2 * pi;
            }
            return x - y;
        };

        Real ans = 0;

        for (int i = 0; i < n; i++) {
            Real a = get(i), b = get((i + 1) % n);
            if (a + b < pi) {
                ans += (pi - a - b) / pi;
            }
        }

        cout << fixed << setprecision(12) << ans << '\n';
    };
    
    solve();
    
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0 0
1 0
0 1

output:

1.000000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 4064kb

input:

4
0 0
0 1
1 1
1 0

output:

0.000000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 4240kb

input:

4
0 0
0 3
1 2
1 1

output:

0.500000000000

result:

ok found '0.5000000', expected '0.5000000', error '0.0000000'

Test #4:

score: 0
Accepted
time: 36ms
memory: 9348kb

input:

199996
719157942 80035870
719158808 80033199
719160795 80027070
719162868 80020675
719165635 80012139
719166422 80009711
719166927 80008153
719168388 80003645
719168539 80003179
719168806 80002355
719168864 80002176
719169119 80001389
719171067 79995376
719173806 79986921
719175195 79982633
71917686...

output:

0.000077716803

result:

ok found '0.0000777', expected '0.0000777', error '0.0000000'

Test #5:

score: 0
Accepted
time: 39ms
memory: 9368kb

input:

199999
521578765 315995242
521578784 315995230
521585008 315991299
521590377 315987908
521597318 315983524
521606119 315977965
521610976 315974897
521614329 315972779
521622922 315967351
521631939 315961655
521636172 315958981
521638241 315957674
521643115 315954595
521650976 315949629
521656567 315...

output:

0.000096532179

result:

ok found '0.0000965', expected '0.0000965', error '0.0000000'

Test #6:

score: 0
Accepted
time: 43ms
memory: 9364kb

input:

200000
88808852 208512084
88810113 208513562
88812008 208515783
88812543 208516410
88816806 208521406
88824507 208530431
88825624 208531740
88831723 208538887
88834262 208541862
88838287 208546578
88845440 208554959
88848801 208558897
88855564 208566821
88856869 208568350
88862876 208575388
88868324...

output:

0.000074373701

result:

ok found '0.0000744', expected '0.0000744', error '0.0000000'

Test #7:

score: 0
Accepted
time: 43ms
memory: 9372kb

input:

199998
2857588 37580055
2857908 37582176
2857951 37582461
2858026 37582958
2859295 37591366
2859678 37593903
2860879 37601857
2862301 37611272
2862330 37611464
2863054 37616255
2864429 37625353
2865434 37632002
2865585 37633001
2867092 37642971
2867321 37644486
2867870 37648118
2868343 37651247
2868...

output:

0.000067539683

result:

ok found '0.0000675', expected '0.0000675', error '0.0000000'

Test #8:

score: 0
Accepted
time: 43ms
memory: 9420kb

input:

199999
487716180 333296644
487720319 333294576
487721706 333293883
487731571 333288954
487734599 333287441
487742738 333283374
487744419 333282534
487746174 333281657
487748301 333280594
487750462 333279514
487754846 333277323
487759670 333274912
487762097 333273699
487764676 333272410
487772963 333...

output:

0.000070696702

result:

ok found '0.0000707', expected '0.0000707', error '0.0000000'

Extra Test:

score: 0
Extra Test Passed