QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#690236#9434. Italian Cuisinezhouchenfeng#WA 0ms3928kbC++172.9kb2024-10-30 21:09:532024-10-30 21:10:03

Judging History

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

  • [2024-10-30 21:10:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3928kb
  • [2024-10-30 21:09:53]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define db long double
#define pb push_back

const db EPS = 0;

inline int sign(db a) {return a < -EPS ? -1 : a > EPS;}
inline int cmp(db a, db b) {return sign(a - b);}

struct P {
    db x, y;
    P () {};
    P (db _x, db _y) : x(_x) , y(_y) {};
    P operator + (P p) {return {x + p.x, y + p.y};}
    P operator - (P p) {return {x - p.x, y - p.y};}
    P operator * (db d) {return {x * d, y * d};}
    db operator * (P p) {return x * p.x + y * p.y;}
    db operator ^ (P p) {return x * p.y - y * p.x;}
    P operator / (db d) {return {x / d, y / d};}
    bool operator == (P p) {
        return cmp(x, p.x) == 0 && cmp(y, p.y) == 0;
    }
    
    db distTo(P p) {return (*this - p).abs();}
    db abs2() {return x * x + y * y;}
    db abs() {return sqrt(abs2());}
    void write() {
        cout << "(" << x << "," << y << ")";
    }
}o, tr[3];
int n;
db r;
vector<P> dt;

#define cross(p1, p2, p3) ((p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y))
#define crossOp(p1, p2, p3) sign(cross(p1, p2, p3))

P proj(P p1, P p2, P q) {
    P dir = p2 - p1;
    return p1 + dir * (dir * (q - p1) / dir.abs2());
}

bool isMiddle(db a, db m, db b) {
	return sign(a - m) == 0 || sign(b - m) == 0 || (a < m != b < m);
}

bool isMiddle(P a, P m, P b) {
	return isMiddle(a.x, m.x, b.x) && isMiddle(a.y, m.y, b.y);
}

db nearest(P p1, P p2, P q) {
    if (p1 == p2) return p1.distTo(q);
    P h = proj(p1, p2, q);
    if (isMiddle(p1, h, p2)) return q.distTo(h);
    return min(p1.distTo(q), p2.distTo(q));
}

db area() {
    return abs(cross(tr[0], tr[1], tr[2]));
}

bool Contain(P p1, P p2, P q) {
    if (nearest(p1, p2, q) >= r && crossOp(p1, q, p2) < 0) return 0;
    return 1;
}

db convex() {
    db ret = 0, ans = 0;
    int tot = 3;
    for (int i = 0, j = 1, nxt; i < n; ++i) {
        if (i != 0 && tot > 2) {
            tr[0] = dt[i - 1];
            tr[1] = dt[i];
            tr[2] = dt[j];
            ret -= area();
        }
        --tot;
        if (i == j) {
            j = (j + 1) % n;
            ++tot;
        }
        nxt = (j + 1) % n;
        while (nxt != (i - 1 + n) % n && !Contain(dt[i], dt[nxt], o)) {
            tr[0] = dt[i];
            tr[1] = dt[j];
            tr[2] = dt[nxt];
            ret += area();
            ++tot;
            j = nxt;
            nxt = (j + 1) % n;
        } 
        ans = max(ans, ret);
    //    cout << ret << "\n";
    }
    return ans;
}

void solve(){
    db x, y;
    cin >> n;
    cin >> x >> y >> r;
    o = {x, y};
    dt.clear();
    for (int i = 0; i < n; ++i) {
        cin >> x >> y;
        dt.pb({x, y});
    }
    cout << convex() << "\n";
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1;
    cin >> t;
    while(t --){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5
1 1 1
0 0
1 0
5 0
3 3
0 5
6
2 4 1
2 0
4 0
6 3
4 6
2 6
0 3
4
3 3 1
3 0
6 3
3 6
0 3

output:

5
24
0

result:

ok 3 number(s): "5 24 0"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3928kb

input:

1
6
0 0 499999993
197878055 -535013568
696616963 -535013568
696616963 40162440
696616963 499999993
-499999993 499999993
-499999993 -535013568

output:

2.86863e+17

result:

wrong output format Expected integer, but "2.86863e+17" found