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<bits/stdc++.h>
#define MAX 100
#define INF 0x3f3f3f3f
using namespace std;
int x[MAX+],y[MAX+],e[MAX+][MAX+];
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=;
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%d%d",&x[i],&y[i]);
int minn=INF;
for(i=;i<=n;i++)
{
for(j=i+;j<=n;j++)
{
e[i][j]=dis(i,j);
minn=min(minn,e[i][j]);
}
}
for(i=;i<=n;i++)
for(j=i+;j<=n;j++)
if(minn==e[i][j])
sum++;
if(sum==n) printf("YES\n");
else printf("NO\n");
}
return ;
}

【2015 ICPC亚洲区域赛长春站 G】Dancing Stars on Me(几何+暴力)的更多相关文章

  1. 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)

    队名:Unlimited Code Works(无尽编码)  队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...

  2. 2014ACM/ICPC亚洲区域赛牡丹江站汇总

    球队内线我也总水平,这所学校得到了前所未有的8地方,因为只有两个少年队.因此,我们13并且可以被分配到的地方,因为13和非常大的数目.据领队谁oj在之上a谁去让更多的冠军.我和tyh,sxk,doub ...

  3. 【2013 ICPC亚洲区域赛成都站 F】Fibonacci Tree(最小生成树+思维)

    Problem Description Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do s ...

  4. 【2018 ICPC亚洲区域赛徐州站 A】Rikka with Minimum Spanning Trees(求最小生成树个数与总权值的乘积)

    Hello everyone! I am your old friend Rikka. Welcome to Xuzhou. This is the first problem, which is a ...

  5. 2014ACM/ICPC亚洲区域赛牡丹江现场赛总结

    不知道怎样说起-- 感觉还没那个比赛的感觉呢?如今就结束了. 9号.10号的时候学校还评比国奖.励志奖啥的,由于要来比赛,所以那些事情队友的国奖不能答辩.自己的励志奖班里乱搞要投票,自己又不在,真是无 ...

  6. 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-K ( ZOJ 3829 ) Known Notation

    Known Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know reverse Polish notation ...

  7. 【2017 ICPC亚洲区域赛北京站 J】Pangu and Stones(区间dp)

    In Chinese mythology, Pangu is the first living being and the creator of the sky and the earth. He w ...

  8. 【2016 ICPC亚洲区域赛北京站 E】What a Ridiculous Election(BFS预处理)

    Description In country Light Tower, a presidential election is going on. There are two candidates,   ...

  9. 【2018 ICPC亚洲区域赛南京站 A】Adrien and Austin(博弈)

    题意: 有一排n个石子(注意n可以为0),每次可以取1~K个连续的石子,Adrien先手,Austin后手,若谁不能取则谁输. 思路: (1) n为0时的情况进行特判,后手必胜. (2) 当k=1时, ...

随机推荐

  1. Linux基础之命令练习Day7-nginx,nfs

    一. Nginx Nginx("engine x") 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗 ...

  2. MYSQL连接相关参数和状态值详解

    针对mysql的连接参数和状态值,本文做些介绍和对比 一.MYSQL连接参数变量 1.常用连接数限制参数 show variables like '%connect%'; | max_connect_ ...

  3. ajax 请求 服务器 响应内容过长 返回500错误的解决方法

    在web.config试试加上 <system.web.extensions> <scripting> <webServices> <jsonSerializ ...

  4. js中公有方法、特权方法、静态方法

    1.公有属性和公有方法 1 2 3 4 5 6 7 8 9 function User(name,age){   this.name = name;//公有属性   this.age = age; } ...

  5. dailiaojie new

    http://imushan.com/categories/Java/ 编译优化手段.

  6. 如何给SAP C4C的产品主数据division配置出新的下拉选项

    如图:C4C产品主数据division字段默认的下拉菜单选项: 切换成调试模式,找到UI这个字段绑定的模型字段名称:/Root/MaterialDivision: 再找到这个UI模型字段绑定到的cor ...

  7. jsp和servlet的问题收集.... 答案有部分是自己理解的,可能有点差异

    如何创建一个动态工程? File ---->  New ---->other ---->Web ---->Dynamic Web Project  选择动态WEB 项目工程 W ...

  8. 手把手教你自定义attr

    最近在学习的过程中遇到了自定义的attr和自定义的style.因此各种百度,各种博客的学习,算是有了一个系统的了解.在这里记录下自己的收获. 一.为什么要使用自定义attr以及本文定位 在androi ...

  9. mybatis插入返回主键

     useGeneratedKeys="true" keyProperty="id" <insert id="insertReturnPrimar ...

  10. Gluon 实现 dropout 丢弃法

    多层感知机中: hi 以 p 的概率被丢弃,以 1-p 的概率被拉伸,除以  1 - p import mxnet as mx import sys import os import time imp ...