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. 编译g++后更新libstdc++.so.6链接

    若不更新链接,运行时可能会发生错误: ./a.out: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by ...

  2. DB2的sql函数

    转自:http://blog.chinaunix.net/uid-21162795-id-3587646.html 一.字符转换函数 1.ASCII() 返回字符表达式最左端字符的ASCII 码值.在 ...

  3. 关于 initWithNibName 和 loadNibNamed 的区别和联系-iPhone成长之路

    转自:http://blog.sina.com.cn/s/blog_7b9d64af01018f2u.html 关于 initWithNibName 和 loadNibNamed 的区别和联系.之所以 ...

  4. iOS第三方开源库的吐槽和备忘

    转自:http://blog.ibireme.com/2013/09/23/ios-third-party-libs/#more-41361 由 ibireme 发表于 2013/09/23 做iOS ...

  5. angular多个控制器如何共享数据

    多个控制器之间共享数据,通常两种方式,一种是在控制器里通过$scope.$$prevSibling或$scope.$$nextSibling获得另一个控制器的作用域对象. 第二种是通过服务的方式,也是 ...

  6. GPIO—位带操作

    GPIO—位带操作本章参考资料:< STM32F4xx 中文参考手册>存储器和总线构架章节. GPIO 章节,< Cortex®-M4 内核编程手册> 2.2.5 Bit-ba ...

  7. python跳一跳辅助学习

    微信跳一跳辅助工具 准备工具 adb驱动 安卓手机 打开手机的调试模式 usb接好手机和电脑 PyCharm:全宇宙唯一一款专门用于Python开发IDE工具 实现原理: 获取手机的实时的截图 点击起 ...

  8. 转:Linux下which、whereis、locate、find 命令的区别

    我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索.这些是从网上找到的资料,因为有时很长时间不会用到,当要用的时候经常弄混了,所以放到这里方便使用. which    ...

  9. HashMap原理<转>

    1. HashMap的数据结构 数据结构中有数组和链表来实现对数据的存储,但这两者基本上是两个极端. 数组 数组存储区间是连续的,占用内存严重,故空间复杂的很大.但数组的二分查找时间复杂度小,为O(1 ...

  10. Android——手机尺寸相关的概念 +尺寸单位+关于颜色

    手机的尺寸: 屏幕对角线的长度,单位为英寸(2.54cm) 手机的分辨率: 屏幕能显示的像素的数量, 一般用在长方向上数量*宽方向上数量来表达 手机的像素密度: pixels per inch,也称P ...