题目链接
题目大意
给你2个爪子,左爪和右爪,相互对称,给你右爪的图,然后给你20个连续的点(可顺可逆)要你判断是右爪还是左爪
题目思路
发现叉积可以应用到计算几何上,叉积可以确定一些相对位置,找最长边的那两个点,和挨着它的短的那条边的点,总共三个点,判断其叉积正负即可。注意一定要保证这三个点,每次顺序都一样!
叉积的其他作用
1:确定三角形的面积,叉积相乘除以2
2:已知直线上的两点s、e,可以求出ax+by+c=0的参数
a = s.y-e.y;
b = e.x-s.x;
c = s×e;
还有一些性质可以看这个博客:链接
代码
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define debug printf("I am here\n");
using namespace std;
typedef long long ll;
const int maxn=30+5,mod=2147493647,inf=0x3f3f3f3f;
const double eps=1e-10;
int t;
double x[maxn],y[maxn];
double cal(double x1,double y1,double x2,double y2){
return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
}
int main(){
scanf("%d",&t);
while(t--){
double ma=-1;
int pos1,pos2,l,mid,r;
for(int i=1;i<=20;i++){
scanf("%lf%lf",&x[i],&y[i]);
}
x[0]=x[20],y[0]=y[20];
x[21]=x[1],y[21]=y[1];
x[22]=x[2],y[22]=y[2];
for(int i=1;i<=20;i++){
double len=cal(x[i],y[i],x[i+1],y[i+1]);
if(len>ma){
ma=len;
pos1=i,pos2=i+1;
}
}
if(cal(x[pos1],y[pos1],x[pos1-1],y[pos1-1])<cal(x[pos2],y[pos2],x[pos2+1],y[pos2+1])){
l=pos1-1,mid=pos1,r=pos2;
}else{
l=pos2+1,mid=pos2,r=pos1;
}
if((x[r]-x[mid])*(y[l]-y[mid])-(x[l]-x[mid])*(y[r]-y[mid])<0){
printf("left\n");
}else{
printf("right\n");
}
}
return 0;
}