Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
1A 纪念一下#include <iostream> #include <cstdio> #include <algorithm> using namespace std; struct node { int x, y; }; node farm[50005]; node mark[50005]; bool cmp( node a, node b ) { if ( a.y < b.y ) return true; else if ( a.y == b.y ) { if ( a.x < b.x ) return true; else return false; } else return false; } bool graham( node a, node b, node c ) { if ( (b.x-a.x)*(c.y-a.y) > (b.y-a.y)*(c.x-a.x) ) return true; else return false; } int main() { int pointNumber; scanf("%d", &pointNumber); for ( int i = 0 ; i < pointNumber ; i ++ ) { scanf("%d%d", &farm[i].x, &farm[i].y); } sort( farm, farm+pointNumber, cmp ); mark[0] = farm[0]; mark[1] = farm[1]; int nowFarm = 1; for ( int i = 2 ; i < pointNumber ; i ++ ) { while ( nowFarm != 0 && !graham( mark[nowFarm], mark[nowFarm-1], farm[i] ) ) nowFarm --; nowFarm ++; mark[nowFarm] = farm[i]; } int len = nowFarm; nowFarm ++; mark[nowFarm] = farm[pointNumber-2]; for ( int i = pointNumber - 3 ; i >= 0 ; i -- ) { while ( nowFarm != len && !graham( mark[nowFarm], mark[nowFarm-1], farm[i] ) ) nowFarm --; nowFarm ++; mark[nowFarm] = farm[i]; } int maxDis= 0; for ( int i = 0 ; i < nowFarm ; i ++ ) { for ( int j = i +1 ; j < nowFarm ; j ++ ) { if ( (mark[i].x-mark[j].x)*(mark[i].x-mark[j].x)+(mark[i].y-mark[j].y)*(mark[i].y-mark[j].y) > maxDis ) maxDis = (mark[i].x-mark[j].x)*(mark[i].x-mark[j].x)+(mark[i].y-mark[j].y)*(mark[i].y-mark[j].y); } } printf("%d\n", maxDis); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator