Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1680 Accepted Submission(s): 592
题意:给你一个多边形,问你这个多边形是否是正多边形。。。
题解:无奈啊,我刚开始就判断边是否相等,用差集排序,相邻判断,果断wa,又想着没考虑角度,就想着对相邻两个边求差集,是否相等,各种wa,无耐加心碎啊,然后就暴力了了。。。就判断个相等边都要大于等于2,然后就对了。。。fuck。。。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
#define T_T while(T--)
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=210;
int N;
struct Node{
LL x,y;
/*Node(LL x=0,LL y=0):x(x),y(y){}*/
};
Node dt[MAXN];
/*LL cross(Node a,Node b){
return a.x*b.y-a.y*b.x;
}
int cmp(Node a,Node b){
if(cross(a,b)>=0)return 1;
else return 0;
}*/
/*
Node operator - (Node a,Node b){
return Node(a.x-b.x,a.y-b.y);
}*/
double getl(Node a,Node b){
LL x=a.x-b.x,y=a.y-b.y;
return sqrt(1.0*x*x+1.0*y*y);
}
bool judge(){
//double temp=getl(dt[0],dt[N-1]);
double ans;
for(int i=0;i<N;i++){
// if(temp!=getl(dt[i],dt[i-1]))return false;
double temp=INF;
int cnt=0;
for(int j=0;j<N;j++){
if(i==j)continue;
if(getl(dt[i],dt[j])<temp)temp=getl(dt[i],dt[j]);
if(i&&ans==temp)cnt++;
}
if(!i)ans=temp;
//printf("%lf %d\n",ans,cnt);
if(i)if(temp!=ans||cnt<2)return false;
}
/*double x=cross(dt[0]-dt[N-1],dt[0]-dt[1]);
for(int i=1;i<N-1;i++){
int y;
if(x!=(y=cross(dt[i]-dt[i-1],dt[i]-dt[i+1]))){
return false;
}
}
if(x!=cross(dt[N-1]-dt[N-2],dt[N-1]-dt[0]))return false;*/
return true;
}
int main(){
int T;
SI(T);
T_T{
SI(N);
for(int i=0;i<N;i++)SL(dt[i].x),SL(dt[i].y);
//sort(dt,dt+N,cmp);
//for(int i=1;i<N;i++)printf("%d\n",cross(dt[i],dt[i-1]));
if(judge())puts("YES");
else puts("NO");
}
return 0;
}
原文:http://www.cnblogs.com/handsomecui/p/5023628.html