Swordsman ACM HDU 3902(判断n边形是不是轴对称图形,暴力求解了~~~~)

Swordsman

Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 308    Accepted Submission(s): 116


Problem Description
Mr. AC is a swordsman. His dream is to be the best swordsman in the world. To achieve his goal, he practices every day. There are many ways to practice, but Mr. AC likes “Perfect Cut” very much. The “Perfect Cut” can be described as the following two steps:
1.  Put a piece of wood block on the desk, and then suddenly wave the sword, cutting the block into two pieces.
2.  Without any motion, the two pieces must be absolutely axial symmetry.
According to the step two, when the board is an axial symmetry figure, Mr. AC has a chance to achieve the “Perfect Cut”. Now give you a board, and you should tell if Mr. AC has a chance to complete the “Perfect Cut”. The board is a simple polygon.
 

Input
The input contains several cases.
The first line of one case contains a single integer n (3 <= n <= 20000), the number of points. The next n lines indicate the points of the simple polygon, each line with two integers x, y (0 <= x, y <= 20000). The points would be given either clockwise or counterclockwise.
 

Output
For each case, output the answer in one line. If Mr. AC has the chance, print “YES”, otherwise "NO".
 

Sample Input
3 0 0 2 0 0 1 4 0 0 0 1 1 1 1 0
 

Sample Output
NO YES
Hint
Huge input, scanf is recommended.
 

Source
2011 Multi-University Training Contest 7 - Host by ECNU
 

Recommend
xubiao
 
 
暴力求解,还没有发现好的方法。
/*
判断n边形是否是轴对称图形:
n边形的n个顶点再加上n条边的中点,共2*n个顶点。
如果存在对称轴,必定是点i和点i+n连成的直线,然后分别验证两边对称的点
到点i和点i+n的距离是否相等
*/

#include
<stdio.h>
#include
<cmath>
using namespace std;
#define MAXN 20000
#define eps 1e-5
struct Node
{
double x,y;
}node[
2*MAXN+10];
int n,m;
bool flag;//用来标注是否是轴对称图形
double dis(int i,int j)//求node[i]和node[j]的距离
{
double x=node[i].x-node[j].x;
double y=node[i].y-node[j].y;
return sqrt(x*x+y*y);
}
bool check(int i,int j,int x,int y)//检查node[i]和node[j]是否关于xy对称
//对称则dis(i,x)==dis(j,x)&&dis(i,y)==dis(j,y);
{
if(fabs(dis(i,x)-dis(j,x))>eps) return false;
if(fabs(dis(i,y)-dis(j,y))>eps) return false;
return true;
}
void ff(int x,int y)//判断node[x]和node[y]组成的直线是不是对称轴
{
int i,j;
i
=j=x;
while(1)
{
i
++;j--;
if(j==0) j=m;
if(i==y)
{
flag
=true;
return;
}
if(check(i,j,x,y)==false) return;
}
}
int main()
{
//freopen("test.in","r",stdin);
//freopen("test.out","w",stdout);
int i;
while(~scanf("%d",&n))
{
m
=2*n;
for(i=1;i<=m;i+=2)
{
scanf(
"%lf%lf",&node[i].x,&node[i].y);
}
node[m
+1]=node[1];
for(i=2;i<=m;i+=2)
{
node[i].x
=(node[i-1].x+node[i+1].x)/2;
node[i].y
=(node[i-1].y+node[i+1].y)/2;
}
flag
=false;
for(i=1;i<=n;i++)
{
ff(i,i
+n);
if(flag) break;
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}

你可能感兴趣的:(Swordsman ACM HDU 3902(判断n边形是不是轴对称图形,暴力求解了~~~~))