poj1859The Perfect Symmetry

时间:2022-08-01 15:55:44

链接

按x或y排序,假如有对称点的话,头尾相对。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
}p[N];
typedef Point pointt;
pointt operator + (Point a,Point b)
{
return Point(a.x+b.x,a.y+b.y);
}
pointt operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
bool cmp(Point a,Point b)
{
if(dcmp(a.x-b.x)==)
return a.y<b.y;
return a.x<b.x;
}
int main()
{
int n,i,j;
while(scanf("%d",&n)&&n)
{
for(i = ; i <= n ;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p+,p+n+,cmp);
double tx = (p[].x+p[n].x)/,ty = (p[].y+p[n].y)/;
int flag = ;
for(i = ; i <= n; i++)
{
double x = (p[i].x+p[n-i+].x)/;
double y = (p[i].y+p[n-i+].y)/;
if(dcmp(x-tx)!=||dcmp(y-ty)!=)
{
flag = ;
break;
}
}
if(flag)
printf("V.I.P. should stay at (%.1f,%.1f).\n",tx,ty);
else
printf("This is a dangerous situation!\n");
}
return ;
}