hdu 5533 计算几何 判断是否为正方形
2017-08-03 23:06
429 查看
原题目链接:
最后题目意思就是给你n个点,判断是否能组成正n边形。实际上由于正三角形正五边形,正六边形不可能都由整数点(即横坐标和纵坐标都是整数)构成,故我们只用判断能组成正方形即可。
Dancing Stars on MeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1797 Accepted Submission(s): 1045 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 nlines, 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 |
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<stack> #include<math.h> #include<vector> #include<map> #include<set> #include<stdlib.h> #include<cmath> #include<string> #include<algorithm> #include<iostream> using namespace std; struct point { int x,y; } pp[110]; int main() { int t,i,j,n,k,cnt; int s[6]; scanf("%d",&t); while(t--) { scanf("%d",&n); cnt=0; for(i=0; i<n; i++) scanf("%d%d",&pp[i].x,&pp[i].y); if(n!=4) { puts("NO"); continue; } for(i=0; i<n; i++) { for(j=0; j<i; j++) { s[cnt++]=(pp[i].x-pp[j].x)*(pp[i].x-pp[j].x)+(pp[i].y-pp[j].y)*(pp[i].y-pp[j].y); } } sort(s,s+6); if(s[0]==s[1]&&s[2]==s[1]&&s[2]==s[3]&&s[4]==s[5]&&s[4]!=s[3]) puts("YES"); else puts("NO"); } return 0; }
相关文章推荐
- hdu 5365 计算几何 给几个点判断是否为正方形
- hdu 5206 Four Inages Strategy【计算几何】【判断空间正方形】
- 【计算几何初步-判断是否凸多边形】【HDU2108】Shape of HDU
- hdu 2108:Shape of HDU(计算几何,判断多边形是否是凸多边形,水题)
- 【计算几何初步-判断是否凸多边形】【HDU2108】Shape of HDU
- 杭电 hdu 5563(计算几何)(思维)(判断是否为五角星)
- HOJ1102 计算几何 判断两个线段是否会相交
- 7月10号 计算几何 对向量叉积 判断两条直线是否相交的理解
- SGU 124. Broken line 计算几何 判断点是否在多边形内
- hdu 5206 判断三维空间中的四个点是否构成正方形
- COJ 1645计算几何:判断线段是否相交
- [hdu 5533][2015ACM/ICPC亚洲区长春站] Dancing Stars on Me 计算几何
- POJ 3304 Segments (计算几何、判断直线与线段是否相交)
- 2017 ACM-ICPC乌鲁木齐网络赛 B. Out-out-control cars【计算几何||判断射线与线段是否相交】
- 计算几何——HDUOJ 2108 - Shape of HDU(判断凹凸)
- 经典算法 | 计算几何 | 判断点是否在多边形内部两个算法
- ZOJ1248/POJ1474/HDU1469 Video Surveillance(判断多边形是否存在核,计算几何)
- 判断线段与圆是否相交(计算几何)
- POJ 1584(计算几何初步——凸包判断,圆与多边形,点是否在多边形内)
- hdu 5533 Dancing Stars on Me【计算几何】