QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#659991 | #7906. Almost Convex | fosov | WA | 323ms | 4160kb | C++14 | 2.4kb | 2024-10-20 01:26:41 | 2024-10-20 01:26:42 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define MOD ((int) (1e9) + 7)
#define pii pair<int, int>
#define N 2010
typedef pair<pii, int> pt;
pii vectorize(pii A, pii B) {
return pii(B.first - A.first, B.second - A.second);
}
ll cross(pii v0, pii v1) {
return 1ll * v0.first * v1.second - 1ll * v0.second * v1.first;
}
double deg[N];
void polar_sort(vector<pt>& arr, pii center) {
for (auto [p, id] : arr) {
auto v = vectorize(center, p);
deg[id] = atan2(v.second, v.first);
}
sort(arr.begin(), arr.end(), [&](pt a, pt b) {
return deg[a.second] < deg[b.second];
});
}
pt stk[N];
int nxt[N], onhull[N];
int main() {
#ifdef TEST
freopen("zz.in", "r+", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
vector<pt> pts(n), ss;
for (int i = 0; i < n; ++ i) {
int x, y; cin >> x >> y;
pts[i] = pt(pii(x, y), i);
if (i != 0) ss.emplace_back(pts[i]);
}
polar_sort(ss, pts[0].first);
int sz = 0;
stk[++ sz] = pts[0];
stk[++ sz] = ss[0];
for (int i = 1; i < ss.size(); ++ i) {
while (sz >= 2) {
auto p0 = stk[sz - 1].first;
auto p1 = stk[sz].first;
auto p2 = ss[i].first;
if (cross(vectorize(p0, p1), vectorize(p1, p2)) < 0) {
-- sz;
continue;
}
break;
}
stk[++ sz] = ss[i];
}
for (int i = 1; i <= sz; ++ i) {
onhull[stk[i].second] = 1;
nxt[stk[i].second] = i == sz ? stk[1].second : stk[i+1].second;
}
int res = 1;
for (int i = 0; i < n; ++ i) {
auto [p, id] = pts[i];
if (onhull[id]) continue;
ss.clear();
for (int j = 0; j < n; ++ j) if (pts[j].second != id) ss.emplace_back(pts[j]);
polar_sort(ss, p);
int cont = 0;
for (int j = 0; j < ss.size(); ++ j) {
int k = j == ss.size()-1 ? 0 : j+1;
int cont = 1;
cont &= onhull[ss[j].second];
cont &= onhull[ss[k].second];
cont &= nxt[ss[j].second] == ss[k].second || nxt[ss[k].second] == ss[j].second;
res += cont;
}
}
cout << res << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4160kb
input:
7 1 4 4 0 2 3 3 1 3 5 0 0 2 4
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3984kb
input:
5 4 0 0 0 2 1 3 3 3 1
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3924kb
input:
6 0 0 3 0 3 2 0 2 1 1 2 1
output:
7
result:
ok 1 number(s): "7"
Test #5:
score: 0
Accepted
time: 0ms
memory: 4160kb
input:
4 0 0 0 3 3 0 3 3
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Wrong Answer
time: 323ms
memory: 4092kb
input:
2000 86166 617851 383354 -277127 844986 386868 -577988 453392 -341125 -386775 -543914 -210860 -429613 606701 -343534 893727 841399 339305 446761 -327040 -218558 -907983 787284 361823 950395 287044 -351577 -843823 -198755 138512 -306560 -483261 -487474 -857400 885637 -240518 -297576 603522 -748283 33...
output:
909
result:
wrong answer 1st numbers differ - expected: '718', found: '909'