QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#463369#7730. Convex CheckerQingyuWA 11ms4600kbC++172.3kb2024-07-04 19:09:542024-07-04 19:09:54

Judging History

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

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

answer

#include <stdio.h>
#include <math.h>
#include <vector>
typedef long long i64;
const double PI = acos(-1.0);
const double eps = 1e-8;
int rd()
{
    int k = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-')
            f = 0;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        k = (k << 1) + (k << 3) + (c ^ '0');
        c = getchar();
    }
    return f ? k : -k;
}
struct point
{
    int x, y;
    int idx;
    point(int _x = 0, int _y = 0, int id = 0) : x(_x), y(_y), idx(id) {}
    void input() { x = rd(), y = rd(); }
    point operator-(const point &o) const { return point(x - o.x, y - o.y); }
    double len() const { return sqrt(1ll * x * x + 1ll * y * y); }
    // point product of vector
    i64 operator*(const point &o) const { return 1ll * x * o.x + 1ll * y * o.y; }
    // cross product of vector
    i64 operator^(const point &o) const { return 1ll * x * o.y - 1ll * y * o.x; }
    bool operator<(const point &o) const { return (x ^ o.x) ? (x < o.x) : (y < o.y); }
    bool operator==(const point &o) const { return (x == o.x) && (y == o.y); }
};
// using point as vector
double angle(const point &a, const point &b) { return acos(1.0 * (a * b) / (a.len() * b.len())); }
bool isconvex(const std::vector<point> &pts)
{
    int n = (int)pts.size();
    if (n <= 2)
        return false;
    double exterior_angle = 0.0;
    i64 cross = (pts[0] - pts[n - 1]) ^ (pts[n - 1] - pts[n - 2]);
    if (cross == 0)
        return false;
    bool dir = cross > 0;
    exterior_angle += angle(pts[0] - pts[n - 1], pts[n - 1] - pts[n - 2]);
    cross = (pts[1] - pts[0]) ^ (pts[0] - pts[n - 1]);
    if ((cross == 0) || ((cross > 0) != dir))
        return false;
    exterior_angle += angle(pts[1] - pts[0], pts[0] - pts[n - 1]);
    for (int i = 2; i < n; ++i)
    {
        cross = (pts[i] - pts[i - 1]) ^ (pts[i - 1] - pts[i - 2]);
        if ((cross == 0) || ((cross > 0) != dir))
            return false;
        exterior_angle += angle(pts[i] - pts[i - 1], pts[i - 1] - pts[i - 2]);
    }
    return fabs(exterior_angle - 2 * PI) < eps;
}
int main()
{
    int n = rd();
    std::vector<point> pts(n);
    for (int i = 0; i < n; ++i)
        pts[i].x = rd(), pts[i].y = rd();
    puts(isconvex(pts) ? "Yes" : "No");
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

input:

3
0 0
1 0
0 1

output:

Yes

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 0ms
memory: 3912kb

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

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

input:

3
0 0
0 0
0 0

output:

No

result:

ok answer is NO

Test #5:

score: 0
Accepted
time: 0ms
memory: 3912kb

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

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

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

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: 11ms
memory: 4600kb

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