2020牛客暑期多校训练营(第三场)C.Operation Love

C.Operation Love

题目链接-C.Operation Love
在这里插入图片描述
题目大意
上图给出爱丽丝的右手,由二十个点组成,已知她的左手和右手对称,现给出二十个点,给你判断这些点组成的手是左手还是右手

解题思路
叉 积 叉积

  • 我们知道可以利用叉积判断点和线的关系,逆正顺负
  • 所以可以计算长度为 6 6 6 9 9 9这两个向量的叉积,如果相乘为正数,则为逆时针,为右手,反之是左手
  • 或者计算长度为 8 8 8 9 9 9这两个向量的叉积,如果相乘为负数,则为逆时针,为右手,反之是左手
  • 具体操作见代码

附上代码

#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
const double PI=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-4;
const int M=1e9+7;
const int N=2e5+10;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
struct node{
	double x,y;
}s[25];
double len(node a,node b){
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
double cal(node a,node b,node c){
	return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	int t;
	cin>>t;
	while(t--){
		bool ass=0;
		for(int i=1;i<=20;i++)
			cin>>s[i].x>>s[i].y;
		s[21]=s[1];
		s[22]=s[2];
		for(int i=1;i<=20;i++){
			if(fabs(len(s[i],s[i+1])-81)<=eps){
				if(fabs(len(s[i+1],s[i+2])-64)<=eps&&cal(s[i],s[i+1],s[i+2])>0){
					ass=1;
					break;
				}
				if(fabs(len(s[i+1],s[i+2])-36)<=eps&&cal(s[i],s[i+1],s[i+2])<0){
					ass=1;
					break;
				}
			}
		}
		if(ass) cout<<"right"<<endl;
		else cout<<"left"<<endl;		
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值