| ||||||||||
| 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 | |||||||||
WA了十多次,总结起来就是对点排序的时候要细心,附个码#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
struct point
{
int x,y;
} p[50005],res[50005];
int n,st;
int dis(point a, point b)
{
return (b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y);
}
int cross(point a, point b, point c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
int cmp(point a, point b)
{
if(cross(p[0], a, b) > 0||(cross(p[0], a, b)==0&&dis(p[0], a) < dis(p[0], b)))
return 1;
return 0;
}
void get_convex()
{
st = 0;
p[n] = res[++st] = p[0];
res[++st] = p[1];
res[++st] = p[2];
for(int i = 3; i <= n; ++i)
{
while(st > 1&&cross(res[st-1], res[st], p[i]) < 0)--st;
res[++st] = p[i];
}
}
int main()
{
while(~scanf("%d", &n))
{
for(int i = 0; i < n; ++i)
{
scanf("%d%d", &p[i].x, &p[i].y);
if(p[i].x < p[0].x||(p[i].x==p[0].x&&p[i].y < p[0].y))
swap(p[0], p[i]);
}
sort(p+1, p+n, cmp);
get_convex();
int ans = 0;
for(int i = 1; i < st-1; ++i)
for(int j = i+1; j < st; ++j)
ans = max(ans, dis(res[i], res[j]));
printf("%d\n", ans);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator