文章标题 HDU 5533 : Dancing Stars on Me
来源:互联网 发布:电路图制作软件cad 编辑:程序博客网 时间:2024/06/13 02:18
Dancing Stars on Me
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 indicating the total number of test cases. Each test case begins with an integer , denoting the number of stars in the sky. Following lines, each contains integers , describe the coordinates of stars.
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条边是所有两两的两个点的距离最短的。所以只要把n个点所有的两点之间的距离保存下来,看有没有n条最短的边。
代码:
#include<iostream>#include<string>#include<cstdio>#include<cstring>#include<vector>#include<math.h>#include<map>#include<queue> #include<algorithm>using namespace std;const int inf = 0x3f3f3f3f;struct node { int x,y;};node a[105];int main (){ int t; scanf ("%d",&t); while (t--){ int n; scanf ("%d",&n); for (int i=0;i<n;i++){ scanf ("%d%d",&a[i].x,&a[i].y); } vector <long long>v;//保存两点距离 long long tmp; for (int i=0;i<n;i++){遍历所有的两点 for (int j=i+1;j<n;j++){ long long xn=a[i].x-a[j].x; long long yn=a[i].y-a[j].y; tmp=xn*xn+yn*yn; v.push_back(tmp); } } sort (v.begin(),v.end());//排序 long long minx=v[0]; int len=upper_bound (v.begin(),v.end(),minx)-v.begin();//找第一个比最短距离大的下标,即最短距离的条数。 if (len==n){ printf ("YES\n"); } else printf ("NO\n"); } return 0;}
- 文章标题 HDU 5533 : Dancing Stars on Me
- hdu 5533 Dancing Stars on Me
- hdu 5533 Dancing Stars on Me
- HDU 5533 Dancing Stars on Me
- hdu 5533 Dancing Stars on Me
- HDU 5533:Dancing Stars on Me【数学】
- HDU 5533 Dancing Stars on Me
- HDU 5533 Dancing Stars on Me [数学]
- HDU 5533 Dancing Stars on Me
- HDU-5533 Dancing stars on me
- HDU Dancing Stars on Me
- Dancing Stars on Me HDU
- HDU杭电5533 Dancing Stars on Me
- hdu 5533 Dancing Stars on Me(水)
- HDU 5533 Dancing Stars on Me(凸包)
- HDU-5533-Dancing Stars on Me【2015长春赛区】
- hdu 5533 Dancing Stars on Me【计算几何】
- HDU-5533 Dancing Stars on Me(几何/极点排序)
- python3 调用百度号码归属地查询接口显示中文结果
- JFinal Web开发学习(一)开启HelloWorld
- 初识XSS
- 要求:不申请变量和空间 反转字符串 ,用一个函数实现。 异或^交换或者加减交换的典型应用! VIA 笔试题
- java枚举详解
- 文章标题 HDU 5533 : Dancing Stars on Me
- sass+compass笔记系列1--compass配置简介
- 有符号整数 存储
- 五大流浏览器内核及其代表
- 极光那些事(推送笔记)
- Ubuntu安装Androidstudio,包含其他环境配置
- 返回二进制中1的个数
- 【Dongle】【Web】【JavaScript】AJAX页面局部动态刷新
- 数据结构之线性表(C++)---数组描述