QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#677177 | #7693. Convex Hull Extension | new_game_plus_players# | WA | 368ms | 3828kb | C++14 | 3.1kb | 2024-10-26 10:18:39 | 2024-10-26 10:18:44 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define double long double
struct point {
double x, y;
point (double X=0, double Y=0) {x=X; y=Y;}
point operator + (const point &t) const {return point(x+t.x, y+t.y);}
point operator - (const point &t) const {return point(x-t.x, y-t.y);}
point operator * (const double &t) const {return point(x*t, y*t);}
double det(const point &t) const {return x*t.y - y*t.x;}
double dot(const point &t) const {return x*t.x + y*t.y;}
double mx() const {return max(x, y);}
double mn() const {return min(x, y);}
void out() {
cerr<<x<<','<<y<<" ";
}
}a[55];
const double eps = 1e-9;
bool parallel(point a, point b, point c, point d) {
return fabs((b-a).det(d-c)) < eps;
}
point LxL(point a, point b, point c, point d) { // a-b x c-d
double t = (c-a).det(d-a) / (b-a).det(d-c);
return a + (b-a) * t;
}
int n;
bool in_triangle(point p, point a, point b, point c) {
if ((b-a).det(p-a) < eps) return false;
if ((c-b).det(p-b) < eps) return false;
if ((a-c).det(p-c) < eps) return false;
return true;
}
void solvex(point a, point b, int x, int &l, int &r) {
if (fabs(a.x - b.x) < eps) {
return;
}
point p = LxL(a, b, point(x, 0), point(x, 1));
if (a.x < b.x) {
l = max(l, (int)ceil(p.y + eps));
} else {
r = min(r, (int)floor(p.y - eps));
}
}
ll ANS;
const int inf = 1e9;
ll solve(point a, point b, point c) {
double R = -inf;
R = max(R, a.x);
R = max(R, b.x);
R = max(R, c.x);
double L = inf;
L = min(L, a.x);
L = min(L, b.x);
L = min(L, c.x);
ll ret = 0;
// cerr<<"solve:";
// a.out();
// b.out();
// c.out();
// cerr<<"["<<L<<","<<R<<"]"<<endl;
for (int i=L-2; i<=R+2; i++) {
int l = -inf, r = inf;
solvex(a, b, i, l, r);
solvex(b, c, i, l, r);
solvex(c, a, i, l, r);
// cerr<<"i="<<i<<" "<<l<<","<<r<<endl;
if (l<=r && l != -inf && r != inf) {
if (in_triangle(point(i, l), a, b, c)) {
ret += r-l+1;
}
}
// for (int j=-1000; j<=1000; j++) {
// ANS += in_triangle(point(i, j), a, b, c);
// }
}
return ret;
}
int solve_parallel(point a, point b, point c, point d) {
ll ret = 0;
if (fabs(a.x-b.x)<eps) {
return fabs(c.x - a.x) > 1.5;
}
for (int i=-2000; i<=2000; i++) {
int l = -inf, r = inf;
solvex(a, b, i, l, r);
solvex(c, d, i, l, r);
// cerr<<"i="<<i<<" "<<l<<","<<r<<endl;
if (l<=r && l != -inf && r != inf) {
ret += r-l+1;
return ret;
}
}
return ret;
}
int main() {
cin>>n;
for (int i=1; i<=n; i++) {
cin>>a[i].x>>a[i].y;
}
a[0] = a[n];
a[n+1] = a[1];
a[n+2] = a[2];
ll ans = 0;
for (int i=1; i<=n; i++) {
if (parallel(a[i-1], a[i], a[i+1], a[i+2])) {
int cnt = solve_parallel(a[i-1], a[i], a[i+1], a[i+2]);
if (cnt>0) {
puts("infinitely many");
return 0;
}
continue;
}
point p = LxL(a[i-1], a[i], a[i+1], a[i+2]);
double test = (p - a[i]).det(a[i+1] - a[i]);
if (test < 0) {
puts("infinitely many");
return 0;
}
ans += solve(a[i], p, a[i+1]);
}
cout<<ans<<endl;
// cerr<<"ANS="<<ANS<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
5 0 2 -2 0 -1 -3 1 -3 2 1
output:
23
result:
ok single line: '23'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
4 -7 -7 7 -7 7 7 -7 7
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
4 -1000 1000 -1000 999 -999 999 -999 1000
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 88ms
memory: 3672kb
input:
6 0 -901 900 -900 900 900 0 901 -900 900 -900 -900
output:
1457999998
result:
ok single line: '1457999998'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3720kb
input:
6 900 -900 901 0 900 900 -900 900 -901 0 -900 -900
output:
1457999998
result:
ok single line: '1457999998'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
6 0 0 400 1 400 2 0 3 -400 2 -400 1
output:
1596
result:
ok single line: '1596'
Test #7:
score: 0
Accepted
time: 60ms
memory: 3788kb
input:
6 0 -901 900 -899 900 900 0 901 -900 900 -900 -899
output:
970921796
result:
ok single line: '970921796'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3760kb
input:
6 2 -2 401 399 399 401 -2 2 -401 -399 -399 -401
output:
4794
result:
ok single line: '4794'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3672kb
input:
6 399 -401 401 -399 2 2 -399 401 -401 399 -2 -2
output:
4794
result:
ok single line: '4794'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
4 -1 -1 -2 -2 -2 -3 -1 -2
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3736kb
input:
4 0 0 0 1 -1 2 -1 1
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
48 5 -70 14 -68 22 -66 31 -63 39 -58 46 -52 52 -46 58 -39 63 -31 66 -22 68 -14 70 -5 70 5 68 14 66 22 63 31 58 39 52 46 46 52 39 58 31 63 22 66 14 68 5 70 -5 70 -14 68 -22 66 -31 63 -39 58 -46 52 -52 46 -58 39 -63 31 -66 22 -68 14 -70 5 -70 -5 -68 -14 -66 -22 -63 -31 -58 -39 -52 -46 -46 -52 -39 -58 ...
output:
36
result:
ok single line: '36'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3732kb
input:
4 -10 -10 -11 11 -11 10 -10 -11
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3736kb
input:
4 10 -10 10 -11 11 10 11 11
output:
0
result:
ok single line: '0'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3724kb
input:
4 5 5 6 5 -5 6 -6 6
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
4 100 -99 -99 -98 -100 -98 99 -99
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
4 0 1 -1 0 0 -1 1 0
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
4 -1000 0 0 -1000 1000 0 0 1000
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
4 -1000 1000 -1000 -1000 1000 -1000 1000 1000
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
4 0 0 0 2 -1 2 -1 1
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
4 -3 -2 -4 -2 -4 -3 -3 -4
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #22:
score: 0
Accepted
time: 1ms
memory: 3736kb
input:
4 6 -2 5 -2 4 -3 6 -3
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
48 4 -60 12 -59 19 -57 26 -54 33 -50 39 -45 45 -39 50 -33 54 -26 57 -19 59 -12 60 -4 60 4 59 12 57 19 54 26 50 33 45 39 39 45 33 50 26 54 19 57 12 59 4 60 -4 60 -12 59 -19 57 -26 54 -33 50 -39 45 -45 39 -50 33 -54 26 -57 19 -59 12 -60 4 -60 -4 -59 -12 -57 -19 -54 -26 -50 -33 -45 -39 -39 -45 -33 -50 ...
output:
40
result:
ok single line: '40'
Test #24:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
4 7 3 7 4 5 4 6 3
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
4 -1000 0 -999 -1000 -998 0 -999 1000
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
4 0 -1000 1000 -999 0 -998 -1000 -999
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
3 999 -1000 1000 -1000 1000 -999
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
3 -2 -1 -2 -2 -1 -2
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
3 -1 0 0 1 -1 1
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3 5 0 5 1 4 1
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
3 -777 -777 777 776 0 0
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
3 42 -13 42 -14 44 -13
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #33:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
3 -123 55 -122 57 -123 57
output:
infinitely many
result:
ok single line: 'infinitely many'
Test #34:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
48 7 -99 19 -98 32 -94 44 -89 55 -83 66 -75 75 -66 83 -55 89 -44 94 -32 98 -19 99 -7 99 7 98 19 94 32 89 44 83 55 75 66 66 75 55 83 44 89 32 94 19 98 7 99 -7 99 -19 98 -32 94 -44 89 -55 83 -66 75 -75 66 -83 55 -89 44 -94 32 -98 19 -99 7 -99 -7 -98 -19 -94 -32 -89 -44 -83 -55 -75 -66 -66 -75 -55 -83 ...
output:
156
result:
ok single line: '156'
Test #35:
score: 0
Accepted
time: 368ms
memory: 3804kb
input:
5 0 -1000 1000 -999 999 1000 -1000 1000 -1000 -999
output:
7986005002
result:
ok single line: '7986005002'
Test #36:
score: -100
Wrong Answer
time: 1ms
memory: 3796kb
input:
6 -999 1000 -1000 0 -999 -1000 999 -1000 999 -1 998 999
output:
2992004667
result:
wrong answer 1st lines differ - expected: '2992004004', found: '2992004667'