QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#313260#7730. Convex Checkertiny_fishWA 24ms16716kbC++172.6kb2024-01-24 16:56:552024-01-24 16:56:55

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 19:27:17]
  • hack成功,自动添加数据
  • (/hack/727)
  • [2024-07-04 19:17:30]
  • hack成功,自动添加数据
  • (/hack/726)
  • [2024-01-24 16:56:55]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:16716kb
  • [2024-01-24 16:56:55]
  • 提交

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;
        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: 8152kb

input:

3
0 0
1 0
0 1

output:

Yes

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 1ms
memory: 8372kb

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: 6344kb

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: 8092kb

input:

3
0 0
0 0
0 0

output:

No

result:

ok answer is NO

Test #5:

score: 0
Accepted
time: 1ms
memory: 8376kb

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: 1ms
memory: 6336kb

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: 1ms
memory: 6248kb

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: 1ms
memory: 6360kb

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: 24ms
memory: 16716kb

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:

Compare (49986155.000000, 400000000.000000) with (49980324.000000, 400000001.000000) or (49980324.000000, 400000001.000000)
No

result:

wrong output format YES or NO expected, but COMPARE found