题目地址:http://acm.fzu.edu.cn/problem.php?pid=2035
其实这题也是一样的:http://acm.hdu.edu.cn/showproblem.php?pid=3902
题目意思也很好懂,就是处理如何判断多边行是否对称。
先找出所有点的中点,然后一共有2×N个点,依次检查是否关于XY的连线对称
如果存在对称轴,必定是点i和点i+n连成的直线,然后分别验证两边对称的点到点i和点i+n的距离是否相等
参考这里:http://www.cnblogs.com/kuangbin/archive/2011/08/03/2126194.html
代码如此:
#include <stdio.h>
#include <string.h>
#include <math.h>
#define Max 20000
#define eps 1e-5
struct node
{
double x,y;
}node[2*Max+10];
int n,m;
bool flag;
double dis(int i,int 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)
{
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 reco(int x,int 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()
{
int i,j,cou;
scanf("%d",&cou);
for(i=0;i<cou;i++)
{
scanf("%d",&n);
m=2*n;
for(j=1;j<=m;j+=2)
{
scanf("%lf%lf",&node[j].x,&node[j].y);
}
node[m+1]=node[1];
for(j=2;j<=m;j+=2)
{
node[j].x=(node[j-1].x+node[j+1].x)/2;
node[j].y=(node[j-1].y+node[j+1].y)/2;
}
flag=false;
for(j=1;j<=n;j++)
{
reco(j,j+n);
if(flag)break;
}
if(flag)printf("Case %d: YES\n",i+1);
else printf("Case %d: NO\n",i+1);
}
return 0;
}
作为模板mark下,写的程序太少了。。。。。。