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;
}