博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【2015 ICPC亚洲区域赛长春站 G】Dancing Stars on Me(几何+暴力)
阅读量:4965 次
发布时间:2019-06-12

本文共 2428 字,大约阅读时间需要 8 分钟。

Problem Description

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 T indicating the total number of test cases. Each test case begins with an integer n, denoting the number of stars in the sky. Following nlines, each contains 2 integers xi,yi, describe the coordinates of n stars.

1≤T≤300

3≤n≤100
−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边形。

思路:

由于n的范围较小,所以可以直接暴力求解。因为正n边形上各点到其他点的最短距离即是该正n边形的边长w,所以只要判断下所有点之间的最短距离是否均为w即可!

#include
#define MAX 100#define INF 0x3f3f3f3fusing namespace std;int x[MAX+5],y[MAX+5],e[MAX+5][MAX+5];int dis(int a,int b){ return ((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));}int main(){ int T; scanf("%d",&T); while(T--) { memset(e,INF,sizeof(e)); int n,i,j,sum=0; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]); int minn=INF; for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { e[i][j]=dis(i,j); minn=min(minn,e[i][j]); } } for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) if(minn==e[i][j]) sum++; if(sum==n) printf("YES\n"); else printf("NO\n"); } return 0;}

 

转载于:https://www.cnblogs.com/kannyi/p/9873317.html

你可能感兴趣的文章
SQL中Group By的使用
查看>>
错误org/aopalliance/intercept/MethodInterceptor解决方法
查看>>
Pylint在项目中的使用
查看>>
使用nginx做反向代理和负载均衡效果图
查看>>
access remote libvirtd
查看>>
(4) Orchard 开发之 Page 的信息存在哪?
查看>>
ASP.NET中 GridView(网格视图)的使用前台绑定
查看>>
深入了解Oracle ASM(二):ASM File number 1 文件目录
查看>>
Boosting(提升方法)之AdaBoost
查看>>
Binding object to winForm controller through VS2010 Designer(通过VS2010设计器将对象绑定到winForm控件上)...
查看>>
Spring Boot实战笔记(二)-- Spring常用配置(Scope、Spring EL和资源调用)
查看>>
SwaggerUI+SpringMVC——构建RestFul API的可视化界面
查看>>
springmvc怎么在启动时自己执行一个线程
查看>>
C# 通知机制 IObserver<T> 和 IObservable<T>
查看>>
Code of Conduct by jsFoundation
查看>>
C#小练习ⅲ
查看>>
电源防反接保护电路
查看>>
arraylist
查看>>
zoj 1649 Rescue (BFS)(转载)
查看>>
2124: 等差子序列 - BZOJ
查看>>