Dancing Stars on Me

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

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
 
Source
 
Recommend
 
 
 #define  N  109
int t,n;
double x[N],y[N];
double x_,y_;
double dis(double x,double y){
return sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_));
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
x_=,y_=;
for(int i=;i<n;i++){
scanf("%lf%lf",&x[i],&y[i]);
x_+=x[i]/n;
y_+=y[i]/n;
}
double temp=dis(x[],y[]);
int flag=;
for(int i=;i<n;i++)
{
if(dis(x[i],y[i])!=temp){
flag=;
break;
}
}
if(flag){
printf("YES\n");
}
else{
printf("NO\n");
}
}
return ;
} //结论 在平面内,如果坐标都为整数,那么只有可能是正四边形
//1 1 1 1 2 2(排序后边长比例)
int x[N],y[N];
int a[];
bool check()
{
if(n!=) return false;
int cnt=;
for(int i=;i<;i++)
{
for(int j=i+;j<;j++)
{
a[cnt++]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
}
}
sort(a,a+cnt);
if(a[]==a[]&&a[]==a[]&&a[]==a[]&&a[]==*a[]&&a[]==a[])
return true;
return false;
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d%d",&x[i],&y[i]);
}
if(check()){
printf("YES\n");
}
else{
printf("NO\n");
}
}
return ;
}

hdu 5533的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 2015ACM/ICPC亚洲区长春站 F hdu 5533 Almost Sorted Array

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  5. 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 ...

  6. hdu 5533(几何水)

    Input The first line contains a integer T indicating the total number of test cases. Each test case ...

  7. 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 ...

  8. HDU 5533 Dancing Stars on Me( 有趣的计算几何 )

    链接:传送门 题意:给出 n 个点,判断能不能构成一个正 n 边形,这 n 个点坐标是整数 思路:这道题关键就在与这 n 个点坐标是正整数!!!可以简单的分析,如果 n != 4,那一定就不能构成正 ...

  9. hdu 5533 正n边形判断 精度处理

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

随机推荐

  1. tomcat7 fail to start inside Ubuntu Docker container

    The tomcat startup script needs some special privileges. Concrete it needs to check all running proc ...

  2. Even-odd Boxes hackerrank 分类讨论

    https://www.hackerrank.com/contests/101hack50/challenges/even-and-odd-boxes/editorial 昨晚做的时候卡了挺久的. 首 ...

  3. Mysql修改server uuid

    在主从复制的时候如果第二个虚拟机是复制过去的,需要修改 https://blog.csdn.net/pratise/article/details/80413198 1. 首先要查找到mysql的安装 ...

  4. mysql非常全的和完整的总结

    (1)数据类型 类型 备注 tinyint/smallint/mediumint/int/bigint 1B/2B/3B/4B/8B float/double 单精度/双精度浮点型 decimal 不 ...

  5. C#实现程序单例日志输出

    对于一个完整的程序系统,一个日志记录是必不可少的.可以用它来记录程序在运行过程中的运行状态和报错信息.比如,那些不想通过弹框提示的错误,程序执行过程中捕获的异常等. 首先,在你的解决方案中,适当的目录 ...

  6. Ubuntu获取root 权限,开机自动登入root

    新机器获取root权限,只需要给root 增加密码: sudo passwd root 修改开机自动登入: #sudo gedit /etc/lightdm/lightdm.conf 修改参数: au ...

  7. CF 55D Beautiful numbers (数位DP)

    题意: 如果一个正整数能被其所有位上的数字整除,则称其为Beautiful number,问区间[L,R]共有多少个Beautiful number?(1<=L<=R<=9*1018 ...

  8. 【转】ios -- ViewController跳转+传值(方式一)

    方式一:通过定义一个实体类传值 (从ViewController1 跳转至 ViewController2) 1.定义实体类NotificationEntity .h声明文件 #import < ...

  9. tcp、http和socket的区别

    本文原链接:https://www.jianshu.com/p/88d69454bdde tcp.http和socket的区别 一:tcp协议 tcp协议属于传输层协议(UDP也属于传输层协议,但是U ...

  10. 干净卸载 Cloudera CDH 5 beta2

    Cloudera 的官方介绍: http://www.cloudera.com/content/cloudera-content/cloudera-docs/CM4Ent/4.8.1/Cloudera ...