博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[POJ 2187]Beauty Contest
阅读量:4542 次
发布时间:2019-06-08

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

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

40 00 11 11 0

Sample Output

2

Hint

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

题解

可以参考 。

1 //It is made by Awson on 2018.1.29 2 #include 
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #define LL long long17 #define dob complex
18 #define Abs(a) ((a) < 0 ? (-(a)) : (a))19 #define Max(a, b) ((a) > (b) ? (a) : (b))20 #define Min(a, b) ((a) < (b) ? (a) : (b))21 #define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))22 #define writeln(x) (write(x), putchar('\n'))23 #define lowbit(x) ((x)&(-(x)))24 using namespace std;25 const int N = 50000;26 27 int n, loc = 1, S[N+5], tot;28 struct point {29 int x, y;30 point() {}31 point(int _x, int _y) {x = _x, y = _y; }32 int operator *(const point &b) const { return x*b.y-y*b.x; }33 int operator ^(const point &b) const { return (x-b.x)*(x-b.x)+(y-b.y)*(y-b.y); }34 point operator -(const point &b) const { return point(x-b.x, y-b.y); }35 }a[N+5];36 bool comp(const point &p, const point &q) {37 int x = (p-a[1])*(q-a[1]);38 return x > 0 || (x == 0 && (p^a[1])>=(q^a[1]));39 }40 bool judge(const point &a1, const point &a2, const point &a3) {41 int x = (a2-a1)*(a3-a1);42 return x > 0 || (x == 0 && (a2^a1)>=(a3^a1));43 }44 45 void work() {46 scanf("%d", &n);47 for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y);48 for (int i = 2; i <= n; i++) if (a[i].y < a[loc].y || (a[i].y == a[loc].y && a[i].x < a[loc].x)) loc = i;49 swap(a[1], a[loc]); sort(a+2, a+n+1, comp); a[n+1] = a[1];50 S[1] = 1, S[2] = 2, tot = 2;51 for (int i = 3; i <= n+1; i++) {52 while (tot > 1 && judge(a[S[tot-1]], a[i], a[S[tot]])) --tot;53 S[++tot] = i;54 }55 --tot; int ans = 0;56 for (int i = 1, now = 2; i <= tot; i++) {57 while ((a[S[i+1]]-a[S[i]])*(a[S[now]]-a[S[i]])<(a[S[i+1]]-a[S[i]])*(a[S[now+1]]-a[S[i]])) {58 ++now; if (now > tot) now = 1;59 }60 ans = Max(ans, a[S[now]]^a[S[i]]);61 }62 printf("%d\n", ans);63 }64 int main() {65 work();66 return 0;67 }

 

转载于:https://www.cnblogs.com/NaVi-Awson/p/8375995.html

你可能感兴趣的文章
APP排查内存泄漏最简单和直观的方法
查看>>
Linux下几款C++程序中的内存泄露检查工具
查看>>
[Python]数据挖掘(1)、梯度下降求解逻辑回归——考核成绩分类
查看>>
枚举类enum的values()方法
查看>>
BZOJ 1726: [Usaco2006 Nov]Roadblocks第二短路 Dijkstra
查看>>
ant简述
查看>>
C#使用CDO发送邮件
查看>>
Oracle中的NVL函数
查看>>
Redis Sentinel机制与用法说明【转】
查看>>
使用NUget发布自己的dll(转)
查看>>
7bit ASCII编解码
查看>>
flask-sqlalchemy(包含离线脚本,with在上下文管理的应用)
查看>>
机器学习工程师 - Udacity 强化学习 Part Ten
查看>>
go语言 新手学习笔记 go基础教程
查看>>
zabbix 添加宏变量
查看>>
中文词频统计
查看>>
Mark一个按照权重生成随机数方法
查看>>
Eclipse中SVN版本信息不显示的问题
查看>>
2016年11月1日——jQuery源码学习笔记
查看>>
[BZOJ]2806: [Ctsc2012]Cheat
查看>>