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. 清楚苹果 iPai端按钮默认样式

    input[type="button"], input[type="submit"], input[type="reset"] { -web ...

  2. VC编程操作word2010生成表格

    作者:朱金灿 来源:http://blog.csdn.net/clever101 一.   右键单击工程节点,然后选择添加类,如下图: 二.   添加TypeLib中的MFC类,如下图: 三.   选 ...

  3. 从Event Loop谈JS的运行机制

    这里主要是结合Event Loop来谈JS代码是如何运行的. 事件循环对于我们平时开发可以说是特别重要,可以让我们写出更好的代码. 到这里相信我们已经知道了JS引擎是单线程,而且这里会用到前面说的的几 ...

  4. nginx转发配置

    nginx upstream backend19050 { server 10.10.10.10:19050 max_fails=3 fail_timeout=30s; } server { list ...

  5. Python初学者第二天 用户输入和注释

    2day Python基础语法: 1.用户输入和注释 用户输入:   代码注释:# 注释部分不会被执行,或用来帮助理清代码逻辑   2.数据类型:数字 int:整数   long:长整形  注:Pyt ...

  6. JQuery里ajax的表单传值serialize()用法

          本文导读:在jQuery中,当我们使用ajax时,常常需要拼装 input数据以键值对(Key/Value)的形式发送到服务器,用JQuery的serialize方法可以轻松的完成这个工作 ...

  7. ZT 段祺瑞终生忏悔枪杀学生?

    段祺瑞终生忏悔枪杀学生?http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece76310528c315c4380146080955468d4e4 ...

  8. MapReduce编程中常用的字符操作

    本文主要用于记录自己在编写mapreduce程序时常用的一些方法,后期会不断更新,用于自己复习和给新手一些帮助. 字符串操作 String str = " 12345"; // 字 ...

  9. 使用SAP C4C rule editor动态控制UI上某个按钮是否显示

    假设我想根据Sales Order的outbound delivery字段来控制这个Trigger Delivery按钮的动态显示: 首先Adapt->Edit Master Layout进入K ...

  10. ES6-模块导入导出

    基本用法 命名导出(named exports) 可以直接在任何变量或者函数前面加上一个 export 关键字,就可以将它导出. 例如: export const sqrt = Math.sqrt; ...