Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1A 纪念一下

Posted by szy532164656 at 2013-01-31 11:13:10 on Problem 2187 and last updated at 2013-01-31 12:34:13
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator