QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#313276 | #7730. Convex Checker | tiny_fish | WA | 0ms | 2044kb | C++17 | 2.8kb | 2024-01-24 17:06:24 | 2024-01-24 17:06:26 |
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[0][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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 2044kb
input:
3 0 0 1 0 0 1
output:
No
result:
wrong answer expected YES, found NO