QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#313688#7730. Convex Checker2972204889WA 1ms4100kbC++141.4kb2024-01-24 22:16:232024-01-24 22:16:24

Judging History

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

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

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long 
struct Point {
    double x, y;
};
double crossProduct(Point p1, Point p2, Point p3) {
    return (p2.x - p1.x) * (p3.y - p2.y) - (p2.y - p1.y) * (p3.x - p2.x);//判断是否逆时针 
}
double cosProduct(Point p1, Point p2, Point p3){
	return ((p1.x - p2.x) * (p3.x - p2.x) +(p1.y - p2.y) * (p3.y - p2.y))*1.0/(sqrt((p1.x - p2.x) * (p1.x - p2.x) +(p1.y - p2.y) * (p1.y - p2.y))*sqrt((p3.x - p2.x) * (p3.x - p2.x) +(p3.y - p2.y) * (p3.y - p2.y)));
}
bool isConvexPolygon(int n, const vector<Point>& vertices) {
	double cross[n];
	double x=0;
    for (int i = 0; i < n; ++i) {
        cross[i] = crossProduct(vertices[i], vertices[(i + 1) % n], vertices[(i + 2) % n]);
        x=x+acos(cosProduct(vertices[i], vertices[(i + 1) % n], vertices[(i + 2) % n]));
    }
    int cnt=0;
    if(cross[0]==0){
    	cnt++;
	}
	double pi=acos(-1.0);
    for(int i=1;i<n;i++){
    	if(cross[i]*cross[i-1]<0){
    		return false;
		}
		if(cross[i]==0){
			cnt++;
		}
	}
	if(cnt==n||(n-2)*pi!=x){
		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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4100kb

input:

3
0 0
1 0
0 1

output:

YES

result:

ok answer is YES

Test #2:

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

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

input:

4
0 0
0 3
1 2
1 1

output:

YES

result:

ok answer is YES

Test #4:

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

input:

3
0 0
0 0
0 0

output:

NO

result:

ok answer is NO

Test #5:

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

input:

5
1 0
4 1
0 1
2 0
3 2

output:

NO

result:

ok answer is NO

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3960kb

input:

5
0 0
1000000000 0
1000000000 500000000
1000000000 1000000000
0 1000000000

output:

YES

result:

wrong answer expected NO, found YES