QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#313326 | #7730. Convex Checker | 2972204889 | WA | 1ms | 3740kb | C++14 | 1.0kb | 2024-01-24 17:33:01 | 2024-01-24 17:33:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct Point {
int x, y;
};
int crossProduct(Point p1, Point p2, Point p3) {
return (p2.x - p1.x) * (p3.y - p2.y) - (p2.y - p1.y) * (p3.x - p2.x);//判断是否逆时针
}
bool isConvexPolygon(int n, const vector<Point>& vertices) {
int cross[n];
for (int i = 0; i < n; ++i) {
cross[i] = crossProduct(vertices[i], vertices[(i + 1) % n], vertices[(i + 2) % n]);
}
int cnt=0;
if(cross[0]==0){
cnt++;
}
for(int i=1;i<n;i++){
if(cross[i]*cross[i-1]<0){
return false;
}
if(cross[i]==0){
cnt++;
}
}
if(cnt==n){
return false;
}
return true;
}
signed main() {
int n;
cin >> n;
vector<Point> vertices(n);
for (int i = 0; i < n; ++i) {
cin >> vertices[i].x >> vertices[i].y;
}
bool result = isConvexPolygon(n, vertices);
if (result) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
3 0 0 1 0 0 1
output:
YES
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3740kb
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: 3716kb
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: 3712kb
input:
3 0 0 0 0 0 0
output:
NO
result:
ok answer is NO
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3576kb
input:
5 1 0 4 1 0 1 2 0 3 2
output:
YES
result:
wrong answer expected NO, found YES