QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#598237#9434. Italian Cuisineucup-team4906#Compile Error//C++143.1kb2024-09-28 20:56:062024-09-28 20:56:07

Judging History

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

  • [2024-09-28 20:56:07]
  • 评测
  • [2024-09-28 20:56:06]
  • 提交

answer

#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
#define int __int128
using namespace std;
typedef double db;
const db eps = 0;
typedef long long ll;

int sgn(int x) {
    if(abs(x) <= eps) return 0;
    else return x < 0 ? -1 : 1;
}
struct point {
    int x, y;
    point() {}
    point (int x, int y) : x(x), y(y) {}
    point operator + (point B) {return point(x + B.x, y + B.y);}
    point operator - (point B) {return point(x - B.x, y - B.y);}
}; 
struct line {
    point p1, p2;
    line() {}
    line (point p1, point p2) : p1(p1), p2(p2) {}
};
int dis(point a, point b) {return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);}
int cross(point a, point b) {return a.x * b.y - a.y * b.x;}
int polygon_area(vector<point> &p, int n) {
    int area = 0;
    F(i, 0, n - 1) area += cross(p[i], p[(i + 1) % n]);
    return area;
}
struct circle {
    point c;
    int r;
    circle() {}
    circle(int x, int y, int _r) {c = point(x, y); r = _r;}  
} C;

pair<int, int> dis_point_line(point p, line v) {
    int tmp = cross(p - v.p1, v.p2 - v.p1);
    return {tmp * tmp, dis(v.p1, v.p2)};
}
int line_circle_relation(line v, circle C) {
    auto [x, y] = dis_point_line(C.c, v);
    int r = C.r;
    if(x < y * r * r) return 0;
    else if(x == y * r * r) return 1;
    else return 2;
}
int point_line_relation(point p, line v) {return sgn(cross(p - v.p1, v.p2 - v.p1));}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll t; cin >> t;
    while(t --) {
        ll n; cin >> n;
        ll xx, yy, r; cin >> xx >> yy >> r;
        C = circle(xx, yy, r);
        vector<point> a;
        F(i, 1, n) {
            ll x, y; cin >> x >> y;
            a.push_back(point(x, y));
        }
        int sum = polygon_area(a, n);
        int res = 0, now = 0;

        for(int i = 0, j = 0; i < n; i ++) {
            // cout << i << " " << j << " " << res << "!\n";
            if(i == j) {
                j = (j + 1) % n;
                now = 0;
            } else {
                now += cross(a[j], a[i]);
            }
            while(line_circle_relation(line(a[i], a[j]), C)) {
                if(now !=  0 && now != sum) {
                    if(point_line_relation(C.c, line(a[i], a[j])) == point_line_relation(a[(i + 1) % n], line(a[i], a[j]))) {
                        res = max(res, sum - now);
                    } else if(point_line_relation(C.c, line(a[i], a[j])) == -point_line_relation(a[(i + 1) % n], line(a[i], a[j]))) {
                        res = max(res, now);
                    }
                }
                if((j + 1) % n != i) {
                    now -= cross(a[j], a[i]), now += cross(a[j], a[(j + 1) % n]), now += cross(a[(j + 1) % n], a[i]); 
                    j = (j + 1) % n;
                } else break;
            }
            now -= cross(a[i], a[(i + 1) % n]), now -= cross(a[j], a[i]);
        }
        cout << (unsigned long long)res << "\n";
    }
    return 0;
}
/*
4
4
1 1 1
0 0
4 0 
4 4
0 4
4
1 3 1
0 0
4 0 
4 4
0 4
4
3 3 1
0 0
4 0 
4 4
0 4
4
3 1 1
0 0
4 0 
4 4
0 4
*/

詳細信息

answer.code: In function ‘__int128 sgn(__int128)’:
answer.code:10:11: error: call of overloaded ‘abs(__int128&)’ is ambiguous
   10 |     if(abs(x) <= eps) return 0;
      |        ~~~^~~
In file included from /usr/include/c++/13/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:42,
                 from answer.code:1:
/usr/include/stdlib.h:840:12: note: candidate: ‘int abs(int)’
  840 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
In file included from /usr/include/c++/13/cstdlib:81:
/usr/include/c++/13/bits/std_abs.h:79:3: note: candidate: ‘constexpr long double std::abs(long double)’
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:75:3: note: candidate: ‘constexpr float std::abs(float)’
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:71:3: note: candidate: ‘constexpr double std::abs(double)’
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:61:3: note: candidate: ‘long long int std::abs(long long int)’
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:56:3: note: candidate: ‘long int std::abs(long int)’
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
answer.code: In function ‘__int128 line_circle_relation(line, circle)’:
answer.code:44:10: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   44 |     auto [x, y] = dis_point_line(C.c, v);
      |          ^
answer.code: In function ‘__int128 sgn(__int128)’:
answer.code:12:1: warning: control reaches end of non-void function [-Wreturn-type]
   12 | }
      | ^