Dancing Stars on Me

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

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个二维坐标点判断能够构成正多边形
  • 考虑正多边形顶点在同一个圆上
  • 任意挑3个点找外心,得到一组圆心和半径
  • 先对于每个点检测和圆心的距离
  • 然后如果距离都相等那就判断每两个相邻点的距离也应该相等
  • n的范围不大n^2复杂度判相邻即可
 #include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
const int maxn = 1e2 + ;
const int inf = 0x3f3f3f3f ;
const int npos = - ;
const int mod = 1e9 + ;
const int mxx = + ;
const double eps = 1e- ;
const double PI = acos(-1.0) ; struct node{
double x, y;
node(double a=0LL, double b=0LL){
x=a; y=b;
}
};
node vex[maxn], center;
node CircumCenter(node a, node b, node c){
double a1=b.x-a.x, b1=b.y-a.y, c1=(a1*a1+b1*b1)/;
double a2=c.x-a.x, b2=c.y-a.y, c2=(a2*a2+b2*b2)/;
double d=a1*b2-a2*b1;
return node(a.x+(c1*b2-c2*b1)/d,a.y+(a1*c2-a2*c1)/d);
}
double dis2(node a, node b){
return pow(a.x-b.x,)+pow(a.y-b.y,);
}
bool oneLine(node a, node b, node c){
return ((b.y-a.y)/(b.x-a.x))==((c.y-a.y)/(c.x-a.x));
}
int T, n, ans;
double R, D[maxn][maxn];
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(~scanf("%d",&T)){
while(T--){
ans=;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%lf %lf",&vex[i].x,&vex[i].y); if(oneLine(vex[],vex[],vex[]))
ans=; if(ans){
center=CircumCenter(vex[],vex[],vex[]);
R=dis2(center,vex[]);
for(int i=;i<=n;i++)
if(dis2(vex[i],center)!=R){
ans=; break;
}
} if(ans){
for(int i=;i<=n;i++){
D[i][i]=0.0;
for(int j=i+;j<=n;j++)
D[i][j]=D[j][i]=dis2(vex[i],vex[j]);
sort(D[i]+,D[i]++n);
}
for(int i=;i<=n;i++)
if(!(D[i][]==D[i][] && D[i][]==D[i-][])){
ans=; break;
}
}
puts(ans?"YES":"NO");
}
}
return ;
}

HDU_5533_Dancing Stars on Me的更多相关文章

  1. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

  2. POJ 2352 Stars(树状数组)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30496   Accepted: 13316 Descripti ...

  3. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  4. Java基础之在窗口中绘图——填充星型(StarApplet 2 filled stars)

    Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.GeneralPath; @SuppressWarnin ...

  5. XidianOJ 1177 Counting Stars

    题目描述 "But baby, I've been, I've been praying hard,     Said, no more counting dollars     We'll ...

  6. POJ-2352 Stars 树状数组

    Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...

  7. hdu 1541/poj 2352:Stars(树状数组,经典题)

    Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. POJ 2482 Stars in Your Window 线段树扫描线

    Stars in Your Window   Description Fleeting time does not blur my memory of you. Can it really be 4 ...

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

随机推荐

  1. mysql操作及自动化运维

    备份恢复工具:percona-xtrabackup-2.0.0-417.rhel6.x86_64.rpm mysql主从配置命令: 主: 1.编辑主MYSQL 服务器的MySQL配置文件my.cnf, ...

  2. 漫谈Linux下的音频问题(转)

    转自 http://www.kunli.info/2009/03/24/linux-sound-issue/ 现今的互联网,比较Linux和Windows的战争贴基本都成月经贴了.一群群激进的用户不断 ...

  3. STM32 中断应用概览

    本章参考资料< STM32F4xx 中文参考手册>第十章-中断和事件.<ARM Cortex™-M4F 技术参考手册> -4.3 章节: NVIC 和 4.4 章节: SCB— ...

  4. (七十二)自己定义通知NSNotification实现消息传递

    众所周知,iOS中一般在类之间传递消息使用较多的是delegate和block,另一种是基于通知进行的消息传递,我们经常是使用系统的通知.来实现一些功能.比如利用键盘尺寸改变的通知,我们能够依据键盘的 ...

  5. RabbitMQ之路由(Routing)【译】

    在上一节中,我们创建了一个简单的日志系统,可以广播消息到很多接收者. 这一节,我们将在上一节的基础上加一个功能--订阅部分消息.例如,我们只将严重错误信息写入到日志文件保存在磁盘上,同时我们能将所有的 ...

  6. Tomcat7调试运行环境搭建与源代码分析入门

    1. 需要准备好下面这些工具 JDK 1.6+ Maven 2或3 TortoiseSVN 1.7+ (从1.7开始”.svn”目录集中放在一处了,不再每个目录下都放一份) Eclipse 3.5+ ...

  7. [android] AndroidManifest.xml - 【 manifest -> 其他次要配置】

    <uses-sdk> 作用:使应用程序的兼容性更好,指明应用程序需要的最小API,编译API以及最大支持的API.值都是整数 <uses-sdk android:minSdkVers ...

  8. Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion

    本篇太乱,请移步: Spring Framework 官方文档学习(四)之Validation.Data Binding.Type Conversion(一) 写了删删了写,反复几次,对自己的描述很不 ...

  9. strust2自定义interceptor的基本方法及操作

    需求:制作一个网站需要用户登陆后才能查看,即一个权限的问题 1.首先明确在用户没登陆前有两个Action请求是可以通过的,即注册和登陆. 2.创建拦截器,如UserLoginInterceptor.j ...

  10. MySQL单列索引和组合索引的选择效率与explain分析

    一.先阐述下单列索引和组合索引的概念: 单列索引:即一个索引只包含单个列,一个表可以有多个单列索引,但这不是组合索引. 组合索引:即一个索包含多个列. 如果我们的查询where条件只有一个,我们完全可 ...