Time Limit: 20 Secphp
Memory Limit: 256 MBios
http://acm.hdu.edu.cn/showproblem.php?pid=5533app
Inputide
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.Outputthis
For each test case, please output "`YES`" if the stars can form a regular polygon. Otherwise, output "`NO`" (both without quotes).Sample Inputspa
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 Outputorm
NO
YES
NO
題意
three
給你n個整數點,而後問你是否這幾個點可以構成一個正多邊形ip
題解:ci
只用考慮n=4的狀況,而後判斷是否爲一個正方形就行了
而後瞎搞一波。。。
代碼
#include<iostream> #include<stdio.h> #include<algorithm> #include<cstring> using namespace std; pair<int,int> p[302]; int check() { sort(p,p+4); vector<int>G; for(int i=0;i<4;i++) for(int j=i+1;j<4;j++) { int x = p[i].first - p[j].first; int y = p[i].second - p[j].second; G.push_back((x*x)+(y*y)); } sort(G.begin(),G.end()); for(int i=1;i<4;i++) if(G[i]!=G[i-1]) return 0; if(G[4]==G[3])return 0; if(G[5]!=G[4])return 0; return 1; } int main() { int t;scanf("%d",&t); while(t--) { int n;scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&p[i].first,&p[i].second); if(n!=4) { printf("NO\n");continue; } sort(p,p+4); if(check())printf("YES\n"); else printf("NO\n"); } }
Time Limit: 20 Sec
Memory Limit: 256 MB
http://acm.hdu.edu.cn/showproblem.php?pid=5533
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.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
題意
給你n個整數點,而後問你是否這幾個點可以構成一個正多邊形
題解:
只用考慮n=4的狀況,而後判斷是否爲一個正方形就行了
而後瞎搞一波。。。
代碼
#include<iostream> #include<stdio.h> #include<algorithm> #include<cstring> using namespace std; pair<int,int> p[302]; int check() { sort(p,p+4); vector<int>G; for(int i=0;i<4;i++) for(int j=i+1;j<4;j++) { int x = p[i].first - p[j].first; int y = p[i].second - p[j].second; G.push_back((x*x)+(y*y)); } sort(G.begin(),G.end()); for(int i=1;i<4;i++) if(G[i]!=G[i-1]) return 0; if(G[4]==G[3])return 0; if(G[5]!=G[4])return 0; return 1; } int main() { int t;scanf("%d",&t); while(t--) { int n;scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&p[i].first,&p[i].second); if(n!=4) { printf("NO\n");continue; } sort(p,p+4); if(check())printf("YES\n"); else printf("NO\n"); } }