QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658527 | #7906. Almost Convex | LeoG | WA | 7ms | 4040kb | C++23 | 3.1kb | 2024-10-19 16:58:59 | 2024-10-19 16:59:05 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#define int long long
#define double long double
using namespace std;
const int N = 2e3+10;
int n, p, ans;
struct Point {
int x, y;
double angle[2];
bool operator<(const Point &b) const {
return x == b.x ? y < b.y : x < b.x;
}
} list[N], stk[N], inside[N];
map<Point, bool> mp;
int cross(Point p0, Point p1, Point p2) {
return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}
bool cmp(Point a, Point b) {
if (a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
int dis(Point a, Point b) {
return (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);
}
double cos(Point a, Point b, Point c) {
// cos value of angle abc
// ac^2 = ab^2 + bc^2 - 2ab * bc * cos(abc)
// cos(abc) = (ab^2 + bc^2 - ac^2) / 2ab * bc
return (dis(a, b) + dis(b, c) - dis(a, c)) / (2 * sqrtl(dis(a, b)) * sqrtl(dis(b, c)));
}
void andrew() {
p = 1;
stk[0] = list[0], stk[1] = list[1];
for (int i = 2; i < n; ++i) {
while (p > 0 && cross(stk[p - 1], stk[p], list[i]) <= 0) --p;
stk[++p] = list[i];
}
stk[++p] = list[n - 2];
for (int i = n - 3; i >= 0; --i) {
while (p > 0 && cross(stk[p - 1], stk[p], list[i]) <= 0) --p;
stk[++p] = list[i];
}
}
signed main(){
ios::sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; ++i) cin >> list[i].x >> list[i].y;
sort(list, list + n, cmp);
andrew();
// for (int i = 0; i < p; ++i) {
// cout << stk[i].x << " " << stk[i].y << endl;
// }
for (int i = 0; i < p; ++i) {
mp[stk[i]] = true;
}
int idx = 0;
for (int i = 0; i < n; ++i) {
if (mp[list[i]] == false) {
inside[idx++] = list[i];
}
}
// for (int i = 0; i < n; ++i) { // for each point
// for (int j = 0; j < p; ++j) { // for each edge
// if (list[i] == stk[j]) {
// list[i].inside = false;
// break;
// }
// list[i].angle[j][0] = cos(list[i], stk[j], stk[j + 1]);
// list[i].angle[j][1] = cos(list[i], stk[j + 1], stk[j]);
// }
// // if (!list[i].inside) {
// // for (int j = 0; j < p; ++j) {
// // list[i].angle[j][0] = 1;
// // list[i].angle[j][1] = 1;
// // }
// // }
// }
for (int i = 0; i < p; ++i) {
for (int j = 0; j < idx; ++j) {
inside[j].angle[0] = cos(inside[j], stk[i], stk[i + 1]);
inside[j].angle[1] = cos(inside[j], stk[i + 1], stk[i]);
}
sort(inside, inside + idx, [&](Point a, Point b){
return a.angle[0] > b.angle[0];
});
double angle2 = 1;
for (int j = 0; j < idx; ++j) {
if (j == 0) {
angle2 = inside[j].angle[1];
ans++;
}
else {
if (inside[j].angle[1] > angle2) {
ans++;
}
}
}
}
cout << ans + 1 << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
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: 3632kb
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: 3636kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3684kb
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: 3504kb
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: 7ms
memory: 4040kb
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:
52152
result:
wrong answer 1st numbers differ - expected: '718', found: '52152'