Poj Solution 1859

http://poj.org/problem?id=1859

#include <stdio.h>
#include <algorithm>

using namespace std;

struct pairs {
    int first, second;
}p[20100];

bool cmp( const pairs& a, const pairs& b ) {
    return a.first<b.first || a.first==b.first&&a.second<b.second;
}

int main( ) {
    int n, i, sx, sy;

    while( true ) {
        scanf( "%d", &n );

        if( n == 0 )
            break;

        sx = sy = 0;
        for( i=0; i<n; i++ ) {
            scanf( "%d%d", &p[i].first, &p[i].second );
            sx += p[i].first;
            sy += p[i].second;
        }
        
        if( ( (n%1) && (sx%n||sy%n) ) || 2*sx%n || 2*sy%n ) {
            printf( "This is a dangerous situation!n" );
            continue;
        }
        
        stable_sort( p, p+n, cmp );
        
        sx = 2*sx/n; sy = 2*sy/n;
        
        for( i=0; i<=n/2; i++ )
            if( p[i].first+p[n-1-i].first != sx 
                || p[i].second+p[n-1-i].second != sy )
                break;
            
        if( i > n/2 )
            printf( "V.I.P. should stay at (%.1f,%.1f).n", sx*0.5, sy*0.5 );
        else
            printf( "This is a dangerous situation!n" );
    }

    return 0;
}



											
This entry was posted in poj. Bookmark the permalink.