HDU_5533_Dancing Stars on Me
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
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.
1≤T≤300
3≤n≤100
−10000≤xi,yi≤10000
All coordinates are distinct.
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
YES
NO
- 给出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的更多相关文章
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- Java基础之在窗口中绘图——填充星型(StarApplet 2 filled stars)
Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.GeneralPath; @SuppressWarnin ...
- XidianOJ 1177 Counting Stars
题目描述 "But baby, I've been, I've been praying hard, Said, no more counting dollars We'll ...
- POJ-2352 Stars 树状数组
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...
- hdu 1541/poj 2352:Stars(树状数组,经典题)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 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 ...
- 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 ...
随机推荐
- tcpdump常用参数说明
(一).学习tcpdump的5个参数 初次使用tcpdump时,使用tcpdump -h命令可以看到它有数十个参数. 根据我们在运维工作中的经验,掌握tcpdump以下5个参数即可满足大部分的工作需要 ...
- CSectsInfomation.cpp文件
#include "SectsInfomation.h" #include "WidgetMgr.h" #include "XButton.h&quo ...
- swift 函数.和匿名函数
函数 注意: 没有定义返回类型的函数会返回特殊的值,叫 Void.它其实是一个空的元组(tuple),没有任何元素,可以写成(). 使用元组作为返回参数,返回多个参数 func count(strin ...
- error: invalid use of incomplete type
一般出现这种情况都是没有将用到的头文件包含进来 我的情况是在头文件中定义了一个QMenu的指针,在源文件中使用menuBar()函数来返回一个menu指针.我在源文件中包含了文件<QtGui&g ...
- jquery checkbox选中
楼主写的在1.6之前是没有问题的,jquery 1.6后就要这样写了,<input type='checkbox' id='cb'/> <script> //获取是否选中 va ...
- 在ubuntu下安装sourceinsight
执行更新与安装 wine: # sudo apt-get update # sudo apt-get install wine 下载SourceInsight,用wine来安装: 执行:wine so ...
- am335x -- led 控制
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h&g ...
- DIV中display和visibility属性差别
DIV中display和visibility属性差别 DIV中display和visibility属性差别还是挺大的,虽然Visibility和Display属性都可以达到隐藏页面元素的目的,但它们的 ...
- 【BZOJ】1088: [SCOI2005]扫雷Mine(递推)
http://www.lydsy.com/JudgeOnline/problem.php?id=1088 脑残去想递推去了... 对于每一个第二列的格子,考虑多种情况,然后转移.....QAQ 空间可 ...
- VC++:ActiveX Test Container
VC++6.0安装后包含了ActiveX Test Container工具,位置为: "C:\Program Files (x86)\Microsoft Visual Studio\Comm ...