博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2187 Beauty Contest(凸包,旋转卡壳)
阅读量:5233 次
发布时间:2019-06-14

本文共 2544 字,大约阅读时间需要 8 分钟。

题面

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)

    题解

    题目大意:给出若干个农场的坐标,求出相距最远的农场的直线距离的平方。

    题解:
    首先扫描法求出凸包,旋转卡壳求出最大值即可

#include
#include
#include
#include
#include
#include
#include
using namespace std;#define MAX 50010#define INF 1000000000#define rg registerinline int read(){ int x=0,t=1;char ch=getchar(); while((ch<'0'||ch>'9')&&ch!='-')ch=getchar(); if(ch=='-'){t=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();} return x*t;}struct Node{ int x,y;}p[MAX],p0,S[MAX];int n,top,T;inline bool cmp(Node a,Node b){ rg double A=atan2(a.y-p0.y,a.x-p0.x); rg double B=atan2(b.y-p0.y,b.x-p0.x); if(A!=B)return A
p[i].y||(p0.y==p[i].y&&p0.x>p[i].x)) p0=p[i],k=i; swap(p[k],p[0]); sort(&p[1],&p[n],cmp);//关于最下方的点排序 S[0]=p[0];S[1]=p[1]; top=1;//栈顶 for(rg int i=2;i
=0) top--; else S[++top]=p[i++]; }}inline long long Dis(Node a,Node b)//计算两点的距离的平方和 { return 1LL*(a.x-b.x)*(a.x-b.x)+1LL*(a.y-b.y)*(a.y-b.y);}long long GetMax()//求出直径 { rg long long re=0; if(top==1)//仅有两个点 return Dis(S[0],S[1]); S[++top]=S[0];//把第一个点放到最后 int j=2; for(int i=0;i

转载于:https://www.cnblogs.com/cjyyb/p/7259598.html

你可能感兴趣的文章
一个 Java 的 Socket 服务器和客户端通信的例子
查看>>
poj 1113 Wall 凸包
查看>>
菜鸟开发WP APP…
查看>>
IntelliJ IDEA 中创建maven项目
查看>>
while循环的初始以及编码的初始
查看>>
关于数据库的建立及增删改查
查看>>
vs2010 ASP.NET, C#, Ajax 页面局部更新
查看>>
xmlSpy套件(Altova MissionKit 2016)的Ollydbg调试过程及破解
查看>>
无人驾驶技术之Kalman Filter原理介绍
查看>>
【BZOJ2002】[HNOI2010] 弹飞绵羊(大力分块)
查看>>
初学MillerRabin素数测试
查看>>
zoj1276 Optimal Array Multiplication Sequence(DP)
查看>>
BST_insert
查看>>
upper_bound下确界
查看>>
407. Trapping Rain Water II
查看>>
2-1、非线性方程与牛顿迭代法
查看>>
bzoj1001: [BeiJing2006]狼抓兔子(初识是你最小割)
查看>>
201621123006 《Java程序设计》第4周学习总结
查看>>
我的一个自己写的更新缓存的aop实例
查看>>
一步一步理解日历calendar(二)
查看>>