按顺逆时针给出一个几何图形的端点,判断其是否是轴对称图形

思路:由于点是顺逆时针输入,所以可以把每个点和边中点按顺序保存,然后对称轴必然由i,i + n组成,枚举对称轴O(n),然后在枚举每个点的对称点是否在点集中即可

问题:主要问题是不会写(无比真实)

#include<iostream>
#include<stdio.h>
#include<set>
using namespace std;

struct node
{
    double x,y;
}t[2010];
int T,tot,n;
double x[510],y[510];
double A,B,C;
typedef pair<double,double>pp;
set<pp>q;

bool check(double A,double B,double C)
{
    for(int i = 0;i < n; i += 2)
    {
        double xx = x[i] - (2 * A * (A * x[i] + B * y[i] + C)) / (A * A + B * B);
        double yy = y[i] - (2 * B * (A * x[i] + B * y[i] + C)) / (A * A + B * B);
        if(q.find(make_pair(xx,yy)) == q.end()) return 0;
    }
    return 1;
}

bool slove()
{
    for(int i = 0;i < n; ++i)
    {
        A = t[i].y - t[i + n].y;
        B = -(t[i].x - t[i + n].x);
        C = -(A * t[i].x + B * t[i].y);
        if(check(A,B,C)) return 1;
    }
    return 0;
}

int main()
{
    scanf("%d",&T);
    tot = 0;
    while(T--)
    {
        scanf("%d",&n);
        q.clear();
        for(int i = 0;i < n; ++i)
        {
            scanf("%lf%lf",&x[i],&y[i]);
            q.insert(make_pair(x[i],y[i]));
        }
        for(int i = 0;i < n - 1; ++i)
        {
            t[i * 2].x = x[i];
            t[i * 2].y = y[i];
            t[i * 2 + 1].x = (x[i] + x[i + 1]) / 2;
            t[i * 2 + 1].y = (y[i] + y[i + 1]) / 2;
        }
        t[(n - 1) * 2].x = x[n - 1];
        t[(n - 1) * 2].y = y[n - 1];
        t[n * 2 - 1].x = (x[n - 1] + x[0]) / 2;
        t[n * 2 - 1].y = (y[n - 1] + y[0]) / 2;
        printf("Case %d: ",++tot);
        if(slove()) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}