HDU_5533_Dancing Stars on Me
2018-06-17 21:48:48来源:未知 阅读 ()
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.
- 给出n个二维坐标点判断能够构成正多边形
- 考虑正多边形顶点在同一个圆上
- 任意挑3个点找外心,得到一组圆心和半径
- 先对于每个点检测和圆心的距离
- 然后如果距离都相等那就判断每两个相邻点的距离也应该相等
- n的范围不大n^2复杂度判相邻即可
1 #include <iostream> 2 #include <string> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 #include <climits> 7 #include <cmath> 8 #include <vector> 9 #include <queue> 10 #include <stack> 11 #include <set> 12 #include <map> 13 using namespace std; 14 typedef long long LL ; 15 typedef unsigned long long ULL ; 16 const int maxn = 1e2 + 10 ; 17 const int inf = 0x3f3f3f3f ; 18 const int npos = -1 ; 19 const int mod = 1e9 + 7 ; 20 const int mxx = 100 + 5 ; 21 const double eps = 1e-6 ; 22 const double PI = acos(-1.0) ; 23 24 struct node{ 25 double x, y; 26 node(double a=0LL, double b=0LL){ 27 x=a; y=b; 28 } 29 }; 30 node vex[maxn], center; 31 node CircumCenter(node a, node b, node c){ 32 double a1=b.x-a.x, b1=b.y-a.y, c1=(a1*a1+b1*b1)/2; 33 double a2=c.x-a.x, b2=c.y-a.y, c2=(a2*a2+b2*b2)/2; 34 double d=a1*b2-a2*b1; 35 return node(a.x+(c1*b2-c2*b1)/d,a.y+(a1*c2-a2*c1)/d); 36 } 37 double dis2(node a, node b){ 38 return pow(a.x-b.x,2)+pow(a.y-b.y,2); 39 } 40 bool oneLine(node a, node b, node c){ 41 return ((b.y-a.y)/(b.x-a.x))==((c.y-a.y)/(c.x-a.x)); 42 } 43 int T, n, ans; 44 double R, D[maxn][maxn]; 45 int main(){ 46 // freopen("in.txt","r",stdin); 47 // freopen("out.txt","w",stdout); 48 while(~scanf("%d",&T)){ 49 while(T--){ 50 ans=1; 51 scanf("%d",&n); 52 for(int i=1;i<=n;i++) 53 scanf("%lf %lf",&vex[i].x,&vex[i].y); 54 55 if(oneLine(vex[1],vex[2],vex[3])) 56 ans=0; 57 58 if(ans){ 59 center=CircumCenter(vex[1],vex[2],vex[3]); 60 R=dis2(center,vex[1]); 61 for(int i=1;i<=n;i++) 62 if(dis2(vex[i],center)!=R){ 63 ans=0; break; 64 } 65 } 66 67 if(ans){ 68 for(int i=1;i<=n;i++){ 69 D[i][i]=0.0; 70 for(int j=i+1;j<=n;j++) 71 D[i][j]=D[j][i]=dis2(vex[i],vex[j]); 72 sort(D[i]+1,D[i]+1+n); 73 } 74 for(int i=2;i<=n;i++) 75 if(!(D[i][2]==D[i][3] && D[i][2]==D[i-1][2])){ 76 ans=0; break; 77 } 78 } 79 puts(ans?"YES":"NO"); 80 } 81 } 82 return 0; 83 }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:笔记:构造函数易错点
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
- hdu4841 2020-01-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash