【牛客】5668 C-Operation Love

链接:https://ac.nowcoder.com/acm/contest/5668/C
来源:牛客网

题目描述

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.

示例1

输入

2
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

输出

right
left

示例2

输入

1
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

说明

The handprint of example 2 is as follows:
It obviously is the right palm.

题解

上面给出了右手的例子,左手与右手轴对称。每个手印由20个坐标组成,需要我们判断给出的手印是左手还是右手。

其实解题关键就在于(1,0)、(10,8)、(10,0)这三个点。

假设这三个点分别对应样例中的A、B、C三点,我们可以通过判断点C与 A B → \overrightarrow{AB} AB 的关系来判断给出的手印是左手还是右手。

若点C在 A B → \overrightarrow{AB} AB 的右边,则手印为右手;

若点C在 A B → \overrightarrow{AB} AB 的左边,则手印为左手。

判断方法详见此博客

接下来的问题就在于如何确定A、B、C这三个点。

我是通过边长来确定的,根据给出的标准手印可以知道AC=9,所以通过计算两点间的距离就可以得到A、C的坐标(由于坐标有小数参与运算,会导致误差的产生,因此计算的结果只要在±0.05内就可以了)。

但是通过这种方法我们并不知道计算的出的两个点哪个是A,哪个是C,因此,我们还需要把这两个点分别与其他点计算,找到距离为8的点,则新找出的点就是B,而参与运算的之前的点即为C。

至此,整个解题过程就已经明了了。

  1. 确定A、B、C三点的坐标C
  2. 判断C与 A B → \overrightarrow{AB} AB 的关系

代码

#include<bits/stdc++.h>
using namespace std;

typedef pair<double,double> PDD;
PDD v[20];

int main(){
	int t;
	scanf("%d",&t);
	double x,y;
	while(t--){
		for(int i=0;i<20;i++){
			scanf("%lf%lf",&x,&y);
			v[i]={x,y};
		}
		PDD A,B,C,T;
		for(int i=0;i<20;i++){
			for(int j=i+1;j<20;j++){
				if((v[i].first-v[j].first)*(v[i].first-v[j].first)+(v[i].second-v[j].second)*(v[i].second-v[j].second)>=8.95*8.95&&
					(v[i].first-v[j].first)*(v[i].first-v[j].first)+(v[i].second-v[j].second)*(v[i].second-v[j].second)<=9.05*9.05){
			   		A={v[i].first,v[i].second};
					C={v[j].first,v[j].second};
					break;
			  	}
			}
		}
		bool flag=0;// flag=0时,以C为直角交点;flag=1时,以A为直角交点;
		// 以A为直角交点 
		for(int i=0;i<20;i++){
			if((v[i].first-A.first)*(v[i].first-A.first)+(v[i].second-A.second)*(v[i].second-A.second)>=7.95*7.95&&
				(v[i].first-A.first)*(v[i].first-A.first)+(v[i].second-A.second)*(v[i].second-A.second)<8.05*8.05){
			   		B={v[i].first,v[i].second};
			   		flag=1;
					break;
			}
		}
		
		// 以C为直角交点 
		for(int i=0;i<20;i++){
			if((v[i].first-C.first)*(v[i].first-C.first)+(v[i].second-C.second)*(v[i].second-C.second)>=7.95*7.95&&
				(v[i].first-C.first)*(v[i].first-C.first)+(v[i].second-C.second)*(v[i].second-C.second)<8.05*8.05){
			   		B={v[i].first,v[i].second};
			   		flag=0;
					break;
			}
		}
		if(flag){
			if((C.first-A.first)*(B.second-A.second)-(C.second-A.second)*(B.first-A.first)<0)
				puts("right");
			else
				puts("left");
		}else{
			if((A.first-C.first)*(B.second-C.second)-(A.second-C.second)*(B.first-C.first)<0)
				puts("right");
			else
				puts("left");
		}
	} 
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值