POJ2187 Beauty Contest

 

Description

Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the title 'Miss Cow World'. As a result, Bessie will make a tour of N (2 <= N <= 50,000) farms around the world in order to spread goodwill between farmers and their cows. For simplicity, the world will be represented as a two-dimensional plane, where each farm is located at a pair of integer coordinates (x,y), each having a value in the range -10,000 ... 10,000. No two farms share the same pair of coordinates. 

Even though Bessie travels directly in a straight line between pairs of farms, the distance between some farms can be quite large, so she wants to bring a suitcase full of hay with her so she has enough food to eat on each leg of her journey. Since Bessie refills her suitcase at every farm she visits, she wants to determine the maximum possible distance she might need to travel so she knows the size of suitcase she must bring.Help Bessie by computing the maximum distance among all pairs of farms. 

Input

* Line 1: A single integer, N 

* Lines 2..N+1: Two space-separated integers x and y specifying coordinate of each farm 

Output

* Line 1: A single integer that is the squared distance between the pair of farms that are farthest apart from each other. 

Sample Input

4
0 0
0 1
1 1
1 0

Sample Output

2

Hint

Farm 1 (0, 0) and farm 3 (1, 1) have the longest distance (square root of 2) 

Source

 
 
正解:凸包
解题报告:
   2016年北京大学信息学奥赛训练营上机考核第二场 A题
       大致题意是求最远点对
   碰到这样一道水题,我居然没有AC,在考场上真是农飞了。 话说pku尽考原题
       其实标准解法是先求凸包,再旋转卡壳。然而数据水,求完凸包,然后直接凸包上面跑暴力就可以了。
       考场上面没有调出来凸包,真是gi 
 
 
 1 //It is made by jump~
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cmath>
 5 #include<cstring>
 6 #include<cstdlib>
 7 #include<algorithm>
 8 #include<map>
 9 #include<set>
10 using namespace std;
11 typedef long long LL;
12 const int MAXN = 100011; 
13 int n,m;
14 LL ans;
15 
16 struct node{
17     int x,y;
18     node(int x=0,int y=0):x(x),y(y) {  }
19     bool operator < (const node a)const{
20     if(a.x==x) return a.y>y;
21     return a.x>x;
22     }
23     node operator - (const node& o){
24     return node(x-o.x, y-o.y);
25     }
26 }jump[MAXN],ch[MAXN*2];
27 
28 int getint()
29 {
30        int w=0,q=0;
31        char c=getchar();
32        while((c<'0' || c>'9') && c!='-') c=getchar();
33        if (c=='-')  q=1, c=getchar();
34        while (c>='0' && c<='9') w=w*10+c-'0', c=getchar();
35        return q ? -w : w;
36 }
37 
38 int cross(node a,node b){
39     return a.x*b.y-a.y*b.x;
40 }
41 
42 LL dis(node a,node b){
43     return (LL) ( (LL)(a.x-b.x)*(LL)(a.x-b.x) + (LL)(a.y-b.y)*(LL)(a.y-b.y)  );
44 }
45 
46 int main()
47 {
48   n=getint();
49   //for(int i=1;i<=n;i++) jump[i].x=getint(),jump[i].y=getint();
50   for(int i=1;i<=n;i++)
51       {
52       int x=getint(),y=getint();
53       jump[i]=node(x,y);
54       } 
55   sort(jump+1,jump+n+1);
56 
57   m=0;
58   for(int i=1;i<=n;i++)
59       {
60       while(m>1 && cross(ch[m-1]-ch[m-2],jump[i]-ch[m-2])<=0) m--;
61       ch[m++]=jump[i];
62       }
63   int k=m;
64   for(int i=n-1;i>=1;i--)
65       {
66       while(m>k && cross(ch[m-1]-ch[m-2],jump[i]-ch[m-2])<=0) m--;
67       ch[m++]=jump[i];
68       }
69 
70   if(n>1) m--;
71 
72   ans=0;
73   for(int i=1;i<=m;i++)
74       for(int j=i+1;j<=m;j++){
75       LL now=dis(ch[i],ch[j]);
76       if(now>ans) ans=now;
77       }
78   printf("%lld",ans);
79   return 0;
80 }

 

转载于:https://www.cnblogs.com/ljh2000-jump/p/5562431.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值