poj_2187凸包,暴力解法
来源:互联网 发布:windows ce6.0刷机包 编辑:程序博客网 时间:2024/05/22 11:52
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;struct Point{ int x,y; Point(int x=0,int y=0):x(x),y(y){}};typedef Point Vector;bool cmp(const Point &p,const Point &q){ if(p.x!=q.x) return p.x<q.x; return p.y<q.y;}Vector operator -(Point A,Point B){return Vector(A.x-B.x,A.y-B.y);}Point p[50010],ch[50010];int Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}int ConvexHull(Point *p,int n,Point *ch){ sort(p,p+n,cmp); int m=0; for(int i=0;i<n;i++){ while(m>1&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--; ch[m++]=p[i];} int k=m; for(int i=n-2;i>=0;i--) { while(m>k&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--; ch[m++]=p[i]; } if(n>1) m--; return m;}int Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}int Length(Vector A){return Dot(A,A);}int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) scanf("%d%d",&p[i].x,&p[i].y); int x=ConvexHull(p,n,ch); int ans=0; for(int i=0;i<x-1;i++) for(int j=i+1;j<x;j++) if(Length(ch[i]-ch[j])>ans) ans=Length(ch[i]-ch[j]); printf("%d\n",ans); } return 0;}
0 0
- poj_2187凸包,暴力解法
- poj_2187 Beauty Contest(凸包+旋转卡壳)
- 凸包(Convex Hull)问题的三种解法: 暴力,Graham Scan,分治
- 凸包的解法
- hdu1394 暴力解法~
- 暴力求解法入门
- 暴力求解法
- POJ_2187_Beauty Contest(凸包+暴力)
- 凸包问题之蛮力解法
- 凸包问题之GrahamScan解法
- 凸包问题的五种解法
- 凸包问题之GrahamScan解法
- 凸包问题的五种解法
- 凸包问题的五种解法
- 凸包问题的五种解法
- 凸包问题的五种解法
- 凸包问题的五种解法
- 凸包问题的五种解法
- HUDJ 3270 The Diophantine Equation
- C++string 类型结尾是否以'\0'结尾
- 7.使用JAVA程序连接至MySQL数据库
- keytool创建签名
- soapui断言和变量
- poj_2187凸包,暴力解法
- UIAlertView使用
- Android 自定义控件开发入门 (三)
- 矢量化编程——以MNIST为例
- OpenCV中的cvWaitKey()
- iBatis入门教程
- mac 执行sh批处理文件
- FPGA面试题及答案
- 修改本地hosts表用域名访问本地站点 .