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

题目描述

Alice is a beauty in a robot society. So many robots want to marry her. Alice determines to marry a robot who can solve the following puzzle:
Firstly, the shape of Alice’s right palm is as follow:
在这里插入图片描述

And the shape of Alice’s left palm is symmetrical to her right palm.
In this puzzle, Alice will give the challenger many handprints of her palm. The challenger must correctly tell Alice each handprint is her left palm or right palm. Notice that the handprint of Alice’s palm is given by its 2D plane coordinates in clockwise or counterclockwise order. And The shape may be rotated and translated. But the shape won’t be zoomed in nor be zoomed out.
Although you are not a robot, you are interested in solving puzzles. Please try to solve this puzzle.

输入输出

在这里插入图片描述
看到这样的一道题,首先想到的是计算几何。于是模板先写好

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const double eps = 0.1;
const double PI = acos(-1.0);
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;
    }
    point operator -(const point &b) const
    {
        return point(x - b.x,y - b.y);
    }
//叉积
    double operator ^(const point &b)const
    {
        return x*b.y - y*b.x;
    }
//点积
    double operator *(const point &b)const
    {
        return x*b.x + y*b.y;
    }
//绕原点旋转角度B(弧度值),后x,y的变化
    void transXY(double B)
    {
        double tx = x,ty = y;
        x = tx*cos(B) - ty*sin(B);
        y = tx*sin(B) + ty*cos(B);
    }
    void input()
    {
        scanf("%lf%lf",&x,&y);
    }
};
double dist(point a,point b)
{
 return sqrt((a-b)*(a-b));
}

然后开始想,怎么区分左手和右手
然后很容易发现手掌的最下端的线段唯一为9
接着可以左右判断哪根是大拇指
于是就要用到向量中的叉积
然后还要处理顺时针和逆时针的问题
于是就想到小拇指
判一下小拇指就好了

		 if (fabs(dist(a[i],a[(i+1)%20])-9)<=eps)
		  {
		  	point x=a[i],y=a[(i+1)%20],z=a[(i+2)%20];
		  	if ((fabs(dist(y,z)-6)<=eps && ((y-x)^(z-y))<0)||//逆时针
			   (fabs(dist(y,z)-8)<=eps && ((y-x)^(z-y))>0))//顺时针
			   {
			   	l=2;//右手
			   }
			   else
			if ((fabs(dist(y,z)-6)<=eps && ((y-x)^(z-y))>0)||// 顺时针
			   (fabs(dist(y,z)-8)<=eps && ((y-x)^(z-y))<0))// 逆时针
			   {
			   	l=1;//左手
			   }
			break;
		  }

最后还要注意double型的精度问题,用eps控制一下,就能过了
代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const double eps = 0.1;
const double PI = acos(-1.0);
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;
    }
    point operator -(const point &b) const
    {
        return point(x - b.x,y - b.y);
    }
//叉积
    double operator ^(const point &b)const
    {
        return x*b.y - y*b.x;
    }
//点积
    double operator *(const point &b)const
    {
        return x*b.x + y*b.y;
    }
//绕原点旋转角度B(弧度值),后x,y的变化
    void transXY(double B)
    {
        double tx = x,ty = y;
        x = tx*cos(B) - ty*sin(B);
        y = tx*sin(B) + ty*cos(B);
    }
    void input()
    {
        scanf("%lf%lf",&x,&y);
    }
};
double dist(point a,point b)
{
 return sqrt((a-b)*(a-b));
}
point a[25];
int n,m,i,j,k,l,o,p,T;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		for(i=0;i<20;i++) a[i].input();
		l=0;
		for (i=0;i<20;i++)
		 if (fabs(dist(a[i],a[(i+1)%20])-9)<=eps)
		  {
		  	point x=a[i],y=a[(i+1)%20],z=a[(i+2)%20];
		  	if ((fabs(dist(y,z)-6)<=eps && ((y-x)^(z-y))<0)||
			   (fabs(dist(y,z)-8)<=eps && ((y-x)^(z-y))>0))
			   {
			   	l=2;
			   }
			   else
			if ((fabs(dist(y,z)-6)<=eps && ((y-x)^(z-y))>0)||
			   (fabs(dist(y,z)-8)<=eps && ((y-x)^(z-y))<0))
			   {
			   	l=1;
			   }
			break;
		  }
		if(l==1) printf("left\n");
		 else printf("right\n");
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值