首页 > 代码库 > fzu 2035 Axial symmetry(判断多边行对称)

fzu 2035 Axial symmetry(判断多边行对称)

题目地址:http://acm.fzu.edu.cn/problem.php?pid=2035

题目意思也很好懂,就是处理如何判断多边行是否对称。

先找出所有点的中点,然后一共有2×N个点,依次检查是否关于XY的连线对称

代码如此:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#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下,写的程序太少了。。。。。。