思路
对于一个凸多边形,它的任意内角一定小于 \(45\degree\) 。
如果每相邻两条边的叉积的符号相同就说明它们是顺时针或逆时针排列的,则可以判别出该四边形是否为凸四边形。
AC 代码
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int X1,X2,X3,X4,Y1,Y2,Y3,Y4;
int cros(int x1,int y1,int x2,int y2){//叉积计算
return x1 * y2 - y1 * x2;
}
int main(){
// freopen("text.in","r",stdin);
// freopen("text.out","w",stdout);
ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
cin>>X1>>Y1>>X2>>Y2>>X3>>Y3>>X4>>Y4;
int a = cros(X2 - X1,Y2 - Y1,X3 - X2,Y3 - Y2);
int b = cros(X3 - X2,Y3 - Y2,X4 - X3,Y4 - Y3);
int c = cros(X4 - X3,Y4 - Y3,X1 - X4,Y1 - Y4);
int d = cros(X1 - X4,Y1 - Y4,X2 - X1,Y2 - Y1);
cout<<((a>0&&b>0&&c>0&&d>0)||(a<0&&b<0&&c<0&&d<0)?"Yes\n":"No\n");
return 0;
}
标签:int,题解,Quadrilateral,abc266,X2,X3,Y3,X1,X4
From: https://www.cnblogs.com/zenoszheng/p/18612321