题意:给你n个坐标,求最远的两点距离

思路:用凸包算法求处,各个定点,再用旋转凸包卡壳

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 50010
struct node{
int x,y,d;
}p[N];
int dist(node a,node b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int crossproduct(node a,node b,node c){
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
bool cmp1(node a,node b){
return (a.x==b.x)?(a.y<b.y):(a.x<b.x);
}
bool cmp2(node a,node b){
int cp=crossproduct(p[0],a,b);
if(!cp)
return a.d<b.d;
return cp>0;
}
int Graham(int n){
int i;
sort(p,p+n,cmp1);
for(i=1;i<n;i++)
p[i].d=dist(p[0],p[i]);
sort(p+1,p+n,cmp2);
int top=1;
for(int i=2;i<n;i++){
while(top>0&&crossproduct(p[i],p[top-1],p[top])<=0)
--top;
p[++top]=p[i];
}
p[++top]=p[0];
int R=1,D=0;
for(int L=0;L<top;++L){
while(crossproduct(p[L],p[L+1],p[R])<crossproduct(p[L],p[L+1],p[R+1]))
R=(R+1)%top;
D=max(D,max(dist(p[L],p[R]),dist(p[L+1],p[R+1])));
}
return D;
}
int main(int argc, char** argv) {
int n;
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
printf("%d\n",Graham(n));
}
return 0;
}

Poj 2187 Beauty Contest_旋转凸包卡壳的更多相关文章

  1. poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)

    链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...

  2. POJ 2187 Beauty Contest(凸包,旋转卡壳)

    题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...

  3. POJ 2187 Beauty Contest(凸包+旋转卡壳)

    Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...

  4. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  5. poj 2187 Beauty Contest——旋转卡壳

    题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...

  6. poj 2187:Beauty Contest(旋转卡壳)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 32708   Accepted: 10156 Description Bes ...

  7. poj 2187 Beauty Contest —— 旋转卡壳

    题目:http://poj.org/problem?id=2187 学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...

  8. POJ 2187 Beauty Contest【凸包周长】

    题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  9. POJ 2187 Beauty Contest( 凸包求最远点对 )

    链接:传送门 题意:给出 n 个点,求出这 n 个点中最远的两个点距离的平方 思路:最远点对一定会在凸包的顶点上,然后直接暴力找一下凸包顶点中距离最远的两个点 /******************* ...

随机推荐

  1. 《Java程序员面试笔试宝典》之Static关键字有哪些作用

    static关键字主要有两种作用:第一,只想为某特定数据类型或对象分配单一的存储空间,而与创建对象的个数无关.第二,希望某个方法或属性与类而不是对象关联在一起,也就是说,在不创建对象的情况下就可以通过 ...

  2. 百度之星B题(组合数)

    Problem B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  3. 黑马程序员 Java正则表达式,详解反斜线在Java中的作用

    ---------------------- ASP.Net+Android+IO开发S. .Net培训.期待与您交流! ---------------------- 在程序设计过程中,经常需要对获取 ...

  4. 程序猿都是project师吗?

    全部的程序猿都是project师吗?当然不是.project师是必修课.程序猿则是选修.project师为自己的事业工作,而程序猿做他们喜欢做的事情.project是实实在在的,编程是抽象的. 为了吸 ...

  5. ASP.NET中时间的绑定和格式化

    1.Eval和Bind的区别  绑定表达式  <%# Eval("字段名") %>  <%# Bind("字段名") %> 区别 1.e ...

  6. iOS8 Core Image In Swift:更复杂的滤镜

    iOS8 Core Image In Swift:自动改善图像以及内置滤镜的使用 iOS8 Core Image In Swift:更复杂的滤镜 iOS8 Core Image In Swift:人脸 ...

  7. HttpServletRequest对象请求转发和HttpServletResponse对象请求重定向之间的区别

    HttpServletRequest对象request代表浏览器请求对象,HttpServletResponse对象代表服务器响应对象,当用浏览器访问web服务器,发出请求时,Servlet调用ser ...

  8. ORACLE序列的使用总结

    1.创建序列ORACLE序列的语法格式为: CREATE SEQUENCE 序列名[INCREMENT BY n][START WITH n][{MAXVALUE/ MINVALUE n|NOMAXV ...

  9. C# 执行存储过程

    SqlParameter[] paras = BuildParas(id, time, name); bool bRet = ExcuteProcedure(“数据库连接字符串”, "存储过 ...

  10. SQL 用中文的拼音和笔画排序

    SQL 用中文的拼音和笔画排序   城市按拼音排序: SELECT chineseName FROM [表名] order by chinesename collate Chinese_PRC_CS_ ...