洛谷P1227 [JSOI2008]完美的对称

洛谷P1227 [JSOI2008]完美的对称 

 

#include <bits/stdc++.h> 
#define For(i,j,k) for(int i=j;i<=k;i++)
using namespace std ; 

const int N = 20011 ; 
const double eps = 1e-8 ; 
struct node{
    double x,y ; 
}a[N];
node ans,tmp ; 
double ansx,ansy ; 
int n,mid ; 

inline int read() 
{
    int x = 0 , f = 1 ; 
    char ch = getchar() ; 
    while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; } 
    while(ch>='0'&&ch<='9') { x=x * 10 + ch-48 ; ch = getchar() ; } 
    return x * f ; 
}

inline bool cmp(node a,node b) 
{
    if(fabs(a.x - b.x) > eps) return a.x < b.x ; 
    return a.y < b.y ; 
}

inline void init() 
{
    n = read() ; 
    For(i,1,n) 
        scanf("%lf%lf",&a[ i ].x,&a[ i ].y) ; 
}

inline void work() 
{
    mid = n / 2 ; 
    sort(a+1,a+n+1,cmp) ; 
    ans.x = ( a[ 1 ].x + a[ n ].x ) / 2 ; 
    ans.y = ( a[ 1 ].y + a[ n ].y ) / 2 ;   
    For(i,2,mid) {
        tmp.x = ( a[ i ].x + a[ n-i+1 ].x ) / 2 ; 
        tmp.y = ( a[ i ].y + a[ n-i+1 ].y ) / 2 ; 
        if( fabs( ans.x - tmp.x ) > eps || fabs( ans.y - tmp.y > eps ) ) {
            printf("This is a dangerous situation!") ; 
            exit( 0 ) ; 
        }
    }
    printf("V.I.P. should stay at (%.1lf,%.1lf).",ans.x,ans.y) ; 
}

int main() 
{
    init() ; 
    work() ; 
    return 0 ; 
}

 

posted @ 2017-08-04 09:44  third2333  阅读(164)  评论(0编辑  收藏  举报