zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    ubuntu实时显示网速cpu占用和内存占用率
    删除以....开头的所有文件
    0.0.....1 至 0.99.......9 之间正则
    引入腾讯视频播放,可控制是否暂停播放
    解决微信小程序textarea层级太高遮挡其他组件的问题
    查看某分支推送记录
    小程序下载canvas生成图片
    微信小程序企业付款到个人
    秒 转化为 时:分:秒 ------- 类似倒计时
    iOS--崩溃日志的格式化分析---格式化crash日志
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/5562431.html
Copyright © 2011-2022 走看看