POJ 2187 Beauty Contest (凸包)
来源:互联网 发布:网络推广总监薪资体系 编辑:程序博客网 时间:2024/05/18 01:48
题目地址:POJ 2187
凸包第一发。。用的大白书上的andew算法。
先求出凸包,然后最大距离一定是凸包之中的某两点之间的距离,然后枚举找出最大值。
代码如下:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL long longconst int INF=0x3f3f3f3f;int top, n;struct Point{ int x, y;}p[100000], tu[100000];int dist(Point x, Point y){ return (x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y);}Point operator - (Point x, Point y){ Point z; z.x=x.x-y.x; z.y=x.y-y.y; return z;}int Cross(Point x, Point y){ return x.x*y.y-x.y*y.x;}int cmp(Point x, Point y){ if(x.x==y.x) return x.y<y.y; return x.x<y.x;}int Max(int x, int y){ return x>y?x:y;}void Andew(){ int i, j, k; sort(p,p+n,cmp); top=0; for(i=0;i<n;i++) { while(top>1&&Cross(tu[top-1]-tu[top-2],p[i]-tu[top-1])<=0) top--; tu[top++]=p[i]; } k=top; for(i=n-2;i>=0;i--) { while(top>k&&Cross(tu[top-1]-tu[top-2],p[i]-tu[top-1])<=0) top--; tu[top++]=p[i]; } int max1=-1; for(i=0;i<top;i++) { for(j=0;j<i;j++) { max1=Max(max1,dist(tu[i],tu[j])); } } printf("%d\n",max1);}int main(){ int i; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d%d",&p[i].x,&p[i].y); } Andew(); return 0;}
0 0
- 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 2187 Beauty Contest(凸包)
- POJ 2187 Beauty Contest (凸包)
- POJ 2187 Beauty Contest(凸包)
- POJ Beauty Contest 2187 (凸包)
- poj 2187Beauty Contest(凸包)
- POJ 2187Beauty Contest(凸包)
- POJ 2187 Beauty Contest (凸包)
- POJ 2187 Beauty Contest (凸包)
- poj 2187 Beauty Contest 凸包 Graham
- poj 2187 Beauty Contest(凸包)
- POJ-2187--Beauty Contest---凸包
- POJ Beauty Contest (凸包)
- 图像变换-用canny算子实现边缘检测
- 深拷贝与浅拷贝
- git alias 设置
- HDFS HA系列实验之二:HA+JournalNode+zookeeper
- iOS GData解析xml
- POJ 2187 Beauty Contest (凸包)
- HDFS HA系列实验之一:基础环境搭建
- C#面向对象编程-猜拳游戏
- Matlab下绘制二维散点图
- Spark1.0.0 on Standalone 模式部署
- hadoop2.2.0源码编译(CentOS6.4)
- Scala学习笔记03
- [Lua-1] Metatable In Lua
- Android 使用动态加载框架DL进行插件化开发