Dancing Stars on Me

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 223    Accepted Submission(s): 151

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 n lines, 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
 
Source
 题意:给你n个整数点,问这n个点能否组成正多边形。因为都是整数点,所以组成的正多边形只能是正方形。所以只需判断是否为正方形就好啦
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring> using namespace std; #define N 25 int n; struct node
{
int x, y;
}P[N]; int slove(int i, int j, int k, int q) // 判断是否为正四边形
{
if(i == j || i == k) // 不能有重点
return false;
if(i == q || j == k)
return false;
if(j == q || k == q)
return false; int w = 0, num[8];
memset(num, 0, sizeof(num)); num[w++] = (P[i].x-P[j].x)*(P[i].x-P[j].x)+(P[i].y-P[j].y)*(P[i].y-P[j].y);
num[w++] = (P[i].x-P[k].x)*(P[i].x-P[k].x)+(P[i].y-P[k].y)*(P[i].y-P[k].y);
num[w++] = (P[i].x-P[q].x)*(P[i].x-P[q].x)+(P[i].y-P[q].y)*(P[i].y-P[q].y);
num[w++] = (P[j].x-P[k].x)*(P[j].x-P[k].x)+(P[j].y-P[k].y)*(P[j].y-P[k].y);
num[w++] = (P[j].x-P[q].x)*(P[j].x-P[q].x)+(P[j].y-P[q].y)*(P[j].y-P[q].y);
num[w++] = (P[q].x-P[k].x)*(P[q].x-P[k].x)+(P[q].y-P[k].y)*(P[q].y-P[k].y); sort(num, num+w); w = unique(num, num+w) - num; if(w != 2) // 只能有两种不相同的边
return false;
return true;
} int main()
{
int t;
scanf("%d\n", &t);
while(t--)
{
scanf("%d", &n); int ans = 0; for(int i = 1; i <= n; i++)
scanf("%d%d", &P[i].x, &P[i].y);
if(n != 4)
{
printf("NO\n");
continue;
} for(int i = 1; i <= n; i++)
for(int j = i+1; j <= n; j++)
for(int k = j+1; k <= n; k++)
for(int q = k+1; q <= n; q++)
if(slove(i, j, k, q))
ans++;
if(ans != 0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

  

Dancing Stars on Me的更多相关文章

  1. 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me

    Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  2. hdu 5533 Dancing Stars on Me 水题

    Dancing Stars on Me Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  3. hdu 5533 Dancing Stars on Me

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5533 Dancing Stars on Me Time Limit: 2000/1000 MS (Ja ...

  4. Dancing Stars on Me(判断正多边形)

    Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  5. HDU 5533/ 2015长春区域 G.Dancing Stars on Me 暴力

    Dancing Stars on Me Problem Description The sky was brushed clean by the wind and the stars were col ...

  6. hdu 5533 Dancing Stars on Me(数学,水)

    Problem Description The sky was brushed clean by the wind and the stars were cold in a black sky. Wh ...

  7. 【2015 ICPC亚洲区域赛长春站 G】Dancing Stars on Me(几何+暴力)

    Problem Description The sky was brushed clean by the wind and the stars were cold in a black sky. Wh ...

  8. Dancing Stars on Me---hdu5533(判断是否为正多边形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5533 题意:平面图中 有n个点给你每个点的坐标,判断是否能通过某种连线使得这些点所组成的n边形为 正n ...

  9. 【HDOJ5533】Dancing Stars on Me(计算几何)

    题意:给定二维平面上的n个整点,问它们是否都在正n边形的定点上 n<=100,abs(x[i]),abs(y[i])<=1e4 思路:队友做的,抱大腿 可以发现只有n=4时顶点有可能都是整 ...

随机推荐

  1. Canvas入门08-绘制仪表盘

    需求 实现下图所示的仪表盘的绘制. 分析 我们先来将仪表盘进行图形拆分,并定义尺寸. 我们绘制的逻辑: 绘制中心圆 绘制环外圈圆 绘制环内圈圆 绘制刻度内圈圆 绘制刻度线 绘制刻度文字 绘制指针 定义 ...

  2. ssh远程登录过程中卡住

    1.首先排查网络连通性,查看网络是否通畅,远程端口是否开放 2.查看服务器复制,cpu,内存负载是否过大 3.检查ssh配置,查看以下配置是否这样配置 UseDNS no GSSAPIAuthenti ...

  3. python并发编程之进程池、线程池、协程

    需要注意一下不能无限的开进程,不能无限的开线程最常用的就是开进程池,开线程池.其中回调函数非常重要回调函数其实可以作为一种编程思想,谁好了谁就去掉 只要你用并发,就会有锁的问题,但是你不能一直去自己加 ...

  4. SpringMVC访问映射的jsp文件时,报404错误

    配置文件中需要配置映射自然不必多说 <bean class="org.springframework.web.servlet.view.InternalResourceViewReso ...

  5. centos6.9 安装mysql8

    centos6.9 安装 mysql8 # 安装mysql8 1.下载https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.16-2.el6.x86 ...

  6. springboot工程启动时,报错:No bean named 'shiroFilter' available

    在启动Springboot项目时,报错:org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ' ...

  7. windows10操作系统上使用virtualenv虚拟环境

    前提win10上已经安装了Python环境! virtualenv库的使用: 安装 如果win10上同时安装了Python2和python3的安装virtualenv时用; Python2:pip i ...

  8. django后台集成富文本编辑器Tinymce的使用

    富文本编辑器Tinymce是使用步骤: 1.首先去python的模块包的网站下载一个django-tinymce的包 2.下载上图的安装包,然后解压,进入文件夹,执行: (pychrm直接运行命令pi ...

  9. C语言中整形数组、字符数组、字符串的区别

    一. 第一 整型数组的存放,数组最后是不加'\0'的,字符串会自动加上,因此存放字符的时候数组的大小要比实际字符的多一个 第二 整型数组 每一个单元是4个字节的,字符串是一个一个字符存放的,每个字符占 ...

  10. POI读取文件的最佳实践

    POI是 Apache 旗下一款读写微软家文档声名显赫的类库.应该很多人在做报表的导出,或者创建 word 文档以及读取之类的都是用过 POI.POI 也的确对于这些操作带来很大的便利性.我最近做的一 ...