QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#313256 | #7730. Convex Checker | tiny_fish | WA | 1ms | 8148kb | C++17 | 2.6kb | 2024-01-24 16:56:08 | 2024-01-24 16:56:08 |
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)){ std::swap(p[1], p[i]); id = i; }
// printf("%d\n", id);
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)];
// 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;
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: 0ms
memory: 8148kb
input:
3 0 0 1 0 0 1
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 6308kb
input:
4 0 0 0 1 1 1 1 0
output:
Yes
result:
ok answer is YES
Test #3:
score: 0
Accepted
time: 1ms
memory: 6428kb
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: 6104kb
input:
3 0 0 0 0 0 0
output:
No
result:
ok answer is NO
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 6396kb
input:
5 1 0 4 1 0 1 2 0 3 2
output:
Compare (2.000000, 0.000000) with (4.000000, 1.000000) or (3.000000, 2.000000) No
result:
wrong output format YES or NO expected, but COMPARE found