QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#313281 | #7730. Convex Checker | tiny_fish | WA | 27ms | 14464kb | C++17 | 2.8kb | 2024-01-24 17:08:17 | 2024-01-24 17:08:18 |
Judging History
answer
#include <cstdio>
#include <cmath>
#include <algorithm>
typedef double ld;
struct Point{
ld x, y, ang;
Point operator + (const Point &oth) const { return { x+oth.x, y+oth.y }; }
Point operator - (const Point &oth) const { return { x-oth.x, y-oth.y }; }
Point operator * (const ld &p) const { return { x*p, y*p }; }
Point operator / (const ld &p) const { return { x/p, y/p }; }
bool operator == (const Point &oth) const { return x == oth.x && y == oth.y; }
};
ld dot(const Point &a, const Point &b){
return a.x * b.x + a.y * b.y;
}
ld det(const Point &a, const Point &b){
return a.x * b.y - a.y * b.x;
}
ld dis(const Point &a){
return sqrt(a.x*a.x + a.y*a.y);
}
ld dis(const Point &a, const Point &b){
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
ld vec_angle(const Point &a, const Point &b){
// 适用于向量 a 和 b 求角
// return acos(dot(a, b) / (dis(a) * dis(b)));
return atan2(a.y, a.x) - atan2(b.y, b.x);
}
const int maxn = 2e5 + 5;
int n;
Point p[maxn], tmp[2][maxn];
int stk[maxn], top;
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
int id = 1;
for(int i = 2; i <= n; i++) if(p[i].y < p[1].y || (p[i].y == p[1].y && p[i].x < p[1].x)) id = i;
// printf("%d\n", id);
int pos = id;
for(int i = 1; i <= n; i++){
tmp[0][i] = p[pos++];
if(pos > n) pos = 1;
}
pos = id;
for(int i = 1; i <= n; i++){
tmp[1][i] = p[pos--];
if(pos < 1) pos = n;
}
// for(int i = 1; i <= n; i++) tmp[0][i] = p[(i+id-1) <= n ? (i+id-1) : ((i+id)%n+1)];
// for(int i = 1; i <= n; i++) tmp[1][i] = p[(id-i+1) >= 1 ? (id-i+1) : ((id-i+n)%n+1)];
std::swap(p[1], p[id]);
// for(int i = 1; i <= n; i++) printf("%lf %lf\n", tmp[i].x, tmp[i].y);
for(int i = 2; i <= n; i++) p[i].ang = atan2(p[i].y - p[1].y, p[i].x - p[1].x);
std::sort(p+2, p+1+n, [&](Point a, Point b){ return a.ang == b.ang ? dis(a, p[1]) < dis(b, p[1]) : a.ang < b.ang; });
stk[++top] = 1;
for(int i = 2; i <= n; i++){
while(top > 1 && det(p[stk[top]] - p[stk[top-1]], p[i] - p[stk[top]]) <= 0) top--;
stk[++top] = i;
}
// for(int i = 1; i <= top; i++) printf("%d%c", stk[i], " \n"[i==top]);
if(top < n){ puts("No"); return 0; }
for(int i = 1; i <= n; i++){
// printf("Compare (%lf, %lf) with (%lf, %lf) or (%lf, %lf)\n", p[stk[i]].x, p[stk[i]].y, tmp[0][i].x, tmp[0][i].y, tmp[1][i].x, tmp[1][i].y);
if(p[stk[i]] == tmp[0][i] || p[stk[i]] == tmp[1][i]) continue;
// if(n == 128312) printf("Compare (%lf, %lf) with (%lf, %lf) or (%lf, %lf)\n", p[stk[i]].x, p[stk[i]].y, tmp[0][i].x, tmp[0][i].y, tmp[1][i].x, tmp[1][i].y);
puts("No"); return 0;
}
puts("Yes");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 6016kb
input:
3 0 0 1 0 0 1
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 4400kb
input:
4 0 0 0 1 1 1 1 0
output:
Yes
result:
ok answer is YES
Test #3:
score: 0
Accepted
time: 0ms
memory: 4292kb
input:
4 0 0 0 3 1 2 1 1
output:
Yes
result:
ok answer is YES
Test #4:
score: 0
Accepted
time: 0ms
memory: 4032kb
input:
3 0 0 0 0 0 0
output:
No
result:
ok answer is NO
Test #5:
score: 0
Accepted
time: 0ms
memory: 4300kb
input:
5 1 0 4 1 0 1 2 0 3 2
output:
No
result:
ok answer is NO
Test #6:
score: 0
Accepted
time: 0ms
memory: 4276kb
input:
5 0 0 1000000000 0 1000000000 500000000 1000000000 1000000000 0 1000000000
output:
No
result:
ok answer is NO
Test #7:
score: 0
Accepted
time: 0ms
memory: 4340kb
input:
5 0 0 1000000000 0 1000000000 499999999 1000000000 1000000000 0 1000000000
output:
No
result:
ok answer is NO
Test #8:
score: 0
Accepted
time: 0ms
memory: 4388kb
input:
5 0 0 999999999 0 1000000000 50000000 999999999 1000000000 0 1000000000
output:
Yes
result:
ok answer is YES
Test #9:
score: -100
Wrong Answer
time: 27ms
memory: 14464kb
input:
128312 5578014 410408218 5585076 410404717 5588011 410403262 5588473 410403033 5589740 410402405 5593295 410400643 5593751 410400417 5597248 410398684 5598935 410397848 5600618 410397014 5605185 410394751 5610514 410392111 5614281 410390245 5617263 410388768 5621142 410386847 5630840 410382045 56310...
output:
No
result:
wrong answer expected YES, found NO