牛客多校3 - Operation Love(几何+叉积确定三点顺逆)

题目链接:点击查看

题目大意:在平面直角坐标系中给出一只手的轮廓,需要判断是左手还是右手

题目分析:因为这些点在给出时不能确定时顺时针还是逆时针给出,所以我们需要自己来判断,这里存一下给出三点判断顺时针还是逆时针的板子(其实就是个叉积计算三角形面积的应用),当判断出给出的图形是顺时针还是逆时针输入的时候,无非只有四种情况,分类讨论一下就好了,这里我选择的是最底下的长度为 9 的边和两侧长度分别为 6 和 8 的边讨论

牛客多校3 - Operation Love(几何+叉积确定三点顺逆)_第1张图片

因为题目给出的数据误差较大,所以在比较大小的时候,要么eps设的大一点,或者可以干脆直接比较两条边的相对长度大小就好了,因为任意两边的距离之差还是蛮大的

代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

typedef long long LL;

typedef unsigned long long ull;

const int inf=0x3f3f3f3f;

const int N=2e6+100;

const double eps = 1e-8;

int sgn(double x){
	if(fabs(x) < eps)return 0;
	if(x < 0)return -1;
	else return 1;
}

struct Point{
	double x,y;
	Point(){}
	Point(double _x,double _y){
		x = _x;
		y = _y;
	}
	void input(){
		scanf("%lf%lf",&x,&y);
	}
	void output(){
		printf("%.2f %.2f\n",x,y);
	}
	bool operator == (Point b)const{
		return sgn(x-b.x) == 0 && sgn(y-b.y) == 0;
	}
	bool operator < (Point b)const{
		return sgn(x-b.x)== 0?sgn(y-b.y)<0:x>w;
	while(w--)
	{
		int n=20;
		for(int i=0;immax)
			{
				mmax=point[i].distance(point[i+1]);
				mark=i;
			}
		}
		Point A=point[((mark-1)%n+n)%n],B=point[mark],C=point[(mark+1)%n],D=point[(mark+2)%n];
		if(sgn(A.distance(B)

 

你可能感兴趣的:(几何)