poj 2187 Beauty Contest (凸包 Graham)
来源:互联网 发布:淘宝卖家常用语 编辑:程序博客网 时间:2024/06/05 00:15
题意:给你n个点,求两点之间距离最大值(也就是相隔最远的两个点之间的距离)
分析:采用凸包解决,先用Graham扫描算法,求出最外围的点,然后再求最外围两点之间的距离,得出最大的。
#include <iostream>#include<cstdio>#include<algorithm>using namespace std;#define N 50005struct point{ int x,y; point(int x,int y):x(x),y(y){} point(){} bool operator< (const point &s)const { return x<s.x||(x==s.x&&y<s.y); } int det(point a) { return x*a.y-y*a.x; } point operator-(point a) { return point(x-a.x,y-a.y); }};point p[N],res[N];int main(){ int n; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) { scanf("%d%d",&p[i].x,&p[i].y); } sort(p,p+n); int k=0; for(int i=0;i<n;i++) { while(k>1&&(res[k-1]-res[k-2]).det(p[i]-res[k-2])<=0) k--; res[k++]=p[i]; } int t=k; for(int i=n-2;i>=0;i--) { while(k>t&&(res[k-1]-res[k-2]).det(p[i]-res[k-2])<=0) k--; res[k++]=p[i]; } int ans=0; for(int i=0;i<k;i++) { for(int j=0;j<k;j++) { ans=max(ans,(res[i].x-res[j].x)*(res[i].x-res[j].x)+(res[i].y-res[j].y)*(res[i].y-res[j].y)); } } printf("%d\n",ans); } return 0;}
0 0
- poj 2187 Beauty Contest 凸包 Graham
- POJ 2187 Beauty Contest(凸包-Graham扫描法)
- poj 2187 Beauty Contest (凸包 Graham)
- 【POJ 2187】 Beauty Contest (凸包-Graham扫描算法)
- POJ 2187-Beauty Contest(凸包-Graham扫描法/旋转卡壳法)
- poj 2187 Beauty Contest(凸包)
- poj 2187 Beauty Contest(凸包)
- POJ 2187 Beauty Contest(凸包)
- POJ 2187 Beauty Contest (凸包)
- poj 2187 Beauty Contest(凸包)
- poj2187 Beauty Contest 凸包 Graham扫描
- POJ 2187 Beauty Contest (凸包)
- POJ 2187 Beauty Contest 凸包
- POJ 2187 Beauty Contest (凸包)
- poj 2187 Beauty Contest(凸包)
- POJ 2187 Beauty Contest (凸包)
- POJ 2187 Beauty Contest(凸包)
- POJ Beauty Contest 2187 (凸包)
- 严重: Exception sending context initialized event to listener instance of class org.springframework.we
- DE2-115创建Web Server详细步骤(Quartus 13.1)
- Spring 关键点
- hpp.h与.h的区别
- 断言的学习
- poj 2187 Beauty Contest (凸包 Graham)
- poj之旅——3262
- 这个人准备学的↓↓↓↓↓
- SVN基础总结
- 缺少动态连接库.so--cannot open shared object file: No such file or directory
- iOS中assign,copy,retain之间的区别以及weak和strong的区别
- LintCode:不同的路径II
- hive 基本命令
- Codeforces 671B Robin Hood 二分答案