[JSOI2008]完美的对称 题解

题目大意:

  首先我们给定一点A以及对称中心S,点A'是点A以S为对称中心形成的像点,即点S是线段AA'的对称中心。

  点阵组(X)以S为中心的像点是由每个点的像点组成的点阵组。X是用来产生对称中心S的,即点阵X以S为中心的像点的集合即为点阵X本身。

思路:

  找到中心就要使得其位于点阵的中心,所以将每个点双关键字排序(横坐标小的在前,一样的使纵坐标有序)

代码:

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 int i,n,X,Y;
 5 struct data { int x,y; }a[20005];
 6 
 7 bool cmp(data a,data b)
 8 {
 9     if (a.x==b.x) return a.y<b.y;
10     return a.x<b.x;
11 }
12 
13 int main()
14 {
15     scanf("%d",&n);
16     for (i=1;i<=n;++i) scanf("%d%d",&a[i].x,&a[i].y);
17     sort(a+1,a+n+1,cmp);
18     X=a[1].x+a[n].x;Y=a[1].y+a[n].y;
19     for (i=2;i+i<n+3;++i)
20         if (a[i].x+a[n+1-i].x!=X || Y!=a[i].y+a[n+1-i].y)
21         {
22             printf("This is a dangerous situation!
");
23             return 0;
24         }
25     printf("V.I.P. should stay at (%.1lf,%.1lf).
",X/2.0,Y/2.0);
26     return 0;
27 }
原文地址:https://www.cnblogs.com/HHshy/p/6065377.html