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
 

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值