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. springboot项目中使用maven resources

    maven resource 组件可以把pom的变量替换到相关的resouces目录中的资源文件变量 示例项目:内容中心 (文章管理)  生成jar包,生成docker ,生成k8s文件 1.项目结构 ...

  2. ESXi导出的CentOS7 ovf文件导入到workstation 无法打开GUI登录界面的问题解决方案

    1. 前几天将centos的机器导出为ovf 文件 然后使用 workstation 引入之后发现总是黑屏 然后有一个 横杠在闪 2. 解决办法是 修改centos的虚拟机配置文件,将显示器修改为这样 ...

  3. 安装Linux系统CentOS6.5

    个人机器搭建分布式环境时避免要使用虚拟机来满足分布式环境所需的机器,当然伪分布式除外. 简单记录下虚拟机环境的创建过程,Mac上常用的虚拟机VMware Fusion. 虚拟机资源库中新建虚拟机: 选 ...

  4. word定义多级列表

    1.单击开始选项卡里的多级列表按钮,在下拉列表中选择定义新的多级列表 2.先设置第一级编号,选择阿拉伯数字1,2,3,...,并在自动编号“1”的左右分别输入“第”“章”,级别链接到样式选择标题一 3 ...

  5. layui动态渲染select等组件并初始化赋值失败

    描诉:有一个用户信息form表单,其中有部门单选框,数据库中有一张dept(部门)表,要动态渲染出所有部门,并默认选中用户所在部门 关键代码: html页面 <div class="l ...

  6. Thinkphp设置PC和手机端模板

    <?php // 判断手机端 function ismobile() { // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X ...

  7. 解决keil5中文注释乱码方法

    菜单上面的edit-->Configuration-->Editor-->Encoding 选择Chinese GB2312 点击OK即可解决 参考 解决keil和source in ...

  8. HNUSTOJ-1253 Babelfish(字典树)

    1253: Problem C: Babelfish 时间限制: 1 Sec  内存限制: 128 MB提交: 14  解决: 3[提交][状态][讨论版] 题目描述 Problem C: Babel ...

  9. hdu6468 zyb的面试 (思维)

    题目传送门 题意: 将1~n个数按字典序排序后,求第k个数 思路: 代码: #include<stdio.h> #include<iostream> #include<a ...

  10. FTP连接不上的解决方法

    1.注意内网IP和外网IP 2.检查ftp服务是否启动 (面板首页即可看到) 3.检查防火墙20端口 ftp 21端口及被动端口39000 - 40000是否放行 (如是腾讯云/阿里云等还需检查安全组 ...