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. C#之用XmlWriter保存XML数据

    http://book.51cto.com/art/201012/241202.htm https://blog.csdn.net/hongkaihua1987/article/details/790 ...

  2. 李洪强iOS经典面试题37-解释垃圾回收的原理

    李洪强iOS经典面试题37-解释垃圾回收的原理   问题 我们知道,Android 手机通常使用 Java 来开发,而 Java 是使用垃圾回收这种内存管理方式. 那么,ARC 和垃圾回收对比,有什么 ...

  3. iOS-获取苹果商店iPhone应用程序编号APPID-应用中跳转到AppStore中的其他应用

    iOS-获取苹果商店iPhone应用程序编号APPID-应用中跳转到AppStore中的其他应用 一 获取苹果商店iPhone应用程序编号APPID 1 在mac上打开itunes  选择中的A 然后 ...

  4. 用广搜实现的spfa

    用广搜实现的spfa,如果是用一般的最短路,会发现构图很麻烦,因为它不是路径带权值,而是自身带权值.写起来只要注意,在点出队列的生活将其标记为0,在要压入队列的时候,判断其标记是否为0,为0表示队列中 ...

  5. PHP的数据类型转换

    PHP的数据类型转换属于强制转换,允许转换的PHP数据类型有: •(int).(integer):转换成整形 •(float).(double).(real):转换成浮点型 •(string):转换成 ...

  6. jquery checkbox选中

    楼主写的在1.6之前是没有问题的,jquery 1.6后就要这样写了,<input type='checkbox' id='cb'/> <script> //获取是否选中 va ...

  7. linux - camera capture

    //cut a picture#include <stdio.h>#include <stdlib.h>#include <string.h>#include &l ...

  8. Java的多线程 简单入门

    Java的多线程 简单入门 首先能够先搞清楚什么是程序.进程.线程,以及它们之间的关系: 定义: 一 程序仅仅是一组指令的有序集合.它是静态的 二 进程是具有一定独立功能的程序关于某个数据集合上的一次 ...

  9. STUN协议简析

    http://blog.csdn.net/mazidao2008/article/details/4934257 ——————————————————————————————————————————— ...

  10. ComBoFuzzySearch.js

    /** * combobox和combotree模糊查询 */(function () { //combobox可编辑,自定义模糊查询 $.fn.combobox.defaults.editable ...