2015长春区域赛 - G - Dancing Stars on Me HDU - 5533

The sky was brushed clean by the wind and the stars were cold in a black sky. What a wonderful night. You observed that, sometimes the stars can form a regular polygon in the sky if we connect them properly. You want to record these moments by your smart camera. Of course, you cannot stay awake all night for capturing. So you decide to write a program running on the smart camera to check whether the stars can form a regular polygon and capture these moments automatically. 

Formally, a regular polygon is a convex polygon whose angles are all equal and all its sides have the same length. The area of a regular polygon must be nonzero. We say the stars can form a regular polygon if they are exactly the vertices of some regular polygon. To simplify the problem, we project the sky to a two-dimensional plane here, and you just need to check whether the stars can form a regular polygon in this plane.

Input

The first line contains a integer TT indicating the total number of test cases. Each test case begins with an integer nn, denoting the number of stars in the sky. Following nn lines, each contains 22 integers xi,yixi,yi, describe the coordinates of nnstars. 

1≤T≤300
3≤n≤1001
−10000≤xi,yi≤10000
All coordinates are distinct.

Output

For each test case, please output "`YES`" if the stars can form a regular polygon. Otherwise, output "`NO`" (both without quotes).

Sample Input

3
3
0 0
1 1
1 0
4
0 0
0 1
1 0
1 1
5
0 0
0 1
0 2
2 2
2 0

Sample Output

NO
YES
NO

题意:给出n个点(坐标均为整数),看这n个点是否能连成正多边形(此处正多边形要求:边长和角度均相同)

思路:真~思维题。做题的时候思考了半天 惊喜发现只有正方形符合题意。因为多边形的n个点均为整数,所以每条边长度都应该为正整数。所以每个角的角度都应该是90度。所以只有n==4时符合题意,接下来 就是要区分正方形和长方形。

4个点确认6条边(其中4条边,2条对角线),排序后保证前4条不等于后2条,且前4条相等,后2条相等。

 

#include<bits/stdc++.h>
#define CaseT int t;scanf("%d",&t);while(t--)
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;

#define N 107
#define MAX 100002

typedef long long ll;

int n,m;
struct pp{
	int x,y;
}p[N];
double len[6];
double lenn(pp a,pp b){
	//cout<<a.x<<' '<<a.y<<' '<<b.x<<' '<<b.y<<' '<<(a.x-b.x)*(a.x-b.y)+(a.y-b.y)*(a.y-b.y)<<endl;
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

void solve(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) {
		scanf("%d%d",&p[i].x,&p[i].y);
		
	}bool flag=true;
	if(n!=4) flag=false;
	else {
		len[0]=lenn(p[0],p[1]);
		len[1]=lenn(p[0],p[2]);
		len[2]=lenn(p[0],p[3]);
		
		len[3]=lenn(p[2],p[1]);
		len[4]=lenn(p[3],p[1]);
		
		len[5]=lenn(p[2],p[3]);
		
		sort(len,len+6);
		
//		for(int i=0;i<6;i++)
//			cout<<len[i]<<' ';
			
		if(len[4]==len[3]||len[2]!=len[3])flag=false;
	}
	if(flag)cout<<"YES\n";
	else cout<<"NO\n";
} 
int main(){
	CaseT
	solve();
	return 0;
}

。。。错了好久 被队友无情嘲笑。。。。心情复杂.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值