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

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.

输入描述


The first line contains one integer t (1≤t≤10^3) --- the number of handprints in Alice's puzzle.

Each handprint is described by a simple polygon composed of 20 points. Each point in this polygon will be given in clockwise or counterclockwise order. Each line contains two real numbers with exactly six digits after the decimal point, representing the coordinate of a point. So a handprint is composed of 20 lines in the input.

All values of coordinate in the input is in the range [-1000.0000000, 1000.000000].

输出描述


For each footprint of palm, print a line contains "right" or "left", indicating the footprint is the right palm or the left palm respectively.

输入

3
1.000000 0.000000
10.000000 0.000000
10.000000 8.000000
9.000000 8.000000
9.000000 5.000000
8.000000 5.000000
8.000000 10.000000
7.000000 10.000000
7.000000 5.000000
6.000000 5.000000
6.000000 10.000000
5.000000 10.000000
5.000000 5.000000
4.000000 5.000000
4.000000 10.000000
3.000000 10.000000
3.000000 3.000000
2.000000 3.000000
2.000000 6.000000
1.000000 6.000000

-1.000123 0.000000
-10.000123 0.000000
-10.000123 8.000000
-9.000123 8.000000
-9.000123 5.000000
-8.000123 5.000000
-8.000123 10.000000
-7.000123 10.000000
-7.000123 5.000000
-6.000123 5.000000
-6.000123 10.000000
-5.000123 10.000000
-5.000123 5.000000
-4.000123 5.000000
-4.000123 10.000000
-3.000123 10.000000
-3.000123 3.000000
-2.000123 3.000000
-2.000123 6.000000
-1.000123 6.000000

19.471068 -6.709056
13.814214 -1.052201
13.107107 -1.759308
15.228427 -3.880629
14.521320 -4.587735
10.985786 -1.052201
10.278680 -1.759308
13.814214 -5.294842
13.107107 -6.001949
9.571573 -2.466415
8.864466 -3.173522
12.400000 -6.709056
11.692893 -7.416162
8.157359 -3.880629
7.450253 -4.587735
12.400000 -9.537483
11.692893 -10.244590
9.571573 -8.123269
8.864466 -8.830376
13.107107 -13.073017

输出

right
left
right

说明

The handprint of paragraph 3 is as follows:

It obviously is the right palm.

题目大意

爱丽丝是机器人社会的美人。 这么多机器人想嫁给她。 爱丽丝决定嫁给可以解决以下难题的机器人:

首先,爱丽丝右手掌的形状如下:

爱丽丝的左手掌形状与她的右手掌对称。

在这个难题中,爱丽丝将给挑战者她手掌的许多手印。 挑战者必须正确告诉Alice每个手印是她的左手掌还是右手掌。 请注意,爱丽丝手掌的手印由其2D平面坐标按顺时针或逆时针顺序给出。 并且形状可以旋转和平移。 但是形状不会被放大或缩小。

尽管您不是机器人,但您对解决难题很感兴趣。 请尝试解决这个难题。

解题思路

首先先找到掌根(长度为9,且最长),之后和下一条边(长8或6)叉积判断结果正负即可

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
struct node{double x,y;}a[22];
double eps=0.00001;
double le(node x,node y){return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));}
double cj(node a,node b,node c){return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		bool f=0;
		for(int i=0;i<20;i++)
			scanf("%lf%lf",&a[i].x,&a[i].y);
		for(int i=0;i<20;i++)
		{
			if(fabs(le(a[i],a[(i+1)%20])-9.0)<eps)
			{
				node x=a[i],y=a[(i+1)%20],z=a[(i+2)%20];
				if(cj(x,y,z)>0&&fabs(le(y,z)-6)<eps||cj(x,y,z)<0&&fabs(le(y,z)-8)<eps)
					f=1;
				break;
			}
		}
			
		if(f)printf("left\n");
        else printf("right\n");
	}
}

猜你喜欢

转载自blog.csdn.net/cxkdad/article/details/107444466