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

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

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <algorithm>
  5. using namespace std;
  6. #define N 50010
  7. struct node{
  8. int x,y,d;
  9. }p[N];
  10. int dist(node a,node b){
  11. return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
  12. }
  13. int crossproduct(node a,node b,node c){
  14. return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
  15. }
  16. bool cmp1(node a,node b){
  17. return (a.x==b.x)?(a.y<b.y):(a.x<b.x);
  18. }
  19. bool cmp2(node a,node b){
  20. int cp=crossproduct(p[0],a,b);
  21. if(!cp)
  22. return a.d<b.d;
  23. return cp>0;
  24. }
  25. int Graham(int n){
  26. int i;
  27. sort(p,p+n,cmp1);
  28. for(i=1;i<n;i++)
  29. p[i].d=dist(p[0],p[i]);
  30. sort(p+1,p+n,cmp2);
  31. int top=1;
  32. for(int i=2;i<n;i++){
  33. while(top>0&&crossproduct(p[i],p[top-1],p[top])<=0)
  34. --top;
  35. p[++top]=p[i];
  36. }
  37. p[++top]=p[0];
  38. int R=1,D=0;
  39. for(int L=0;L<top;++L){
  40. while(crossproduct(p[L],p[L+1],p[R])<crossproduct(p[L],p[L+1],p[R+1]))
  41. R=(R+1)%top;
  42. D=max(D,max(dist(p[L],p[R]),dist(p[L+1],p[R+1])));
  43. }
  44. return D;
  45. }
  46. int main(int argc, char** argv) {
  47. int n;
  48. while(scanf("%d",&n)!=EOF){
  49. for(int i=0;i<n;i++)
  50. scanf("%d%d",&p[i].x,&p[i].y);
  51. printf("%d\n",Graham(n));
  52. }
  53. return 0;
  54. }

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. hdu4536-XCOM Enemy Unknown(爆搜)

    XCOM-Enemy Unknown是一款很好玩很经典的策略游戏. 在游戏中,由于未知的敌人--外星人入侵,你团结了世界各大国家进行抵抗.随着游戏进展,会有很多的外星人进攻事件.每次进攻外星人会选择3 ...

  2. 基于微信公众平台的开发(清华大学第二讲)_Alien的笔记

    基于微信公众平台的开发(清华大学第二讲)_Alien的笔记 基于微信公众平台的开发(清华大学第二讲)

  3. 谷歌Cartographer学习(2)-原理阐述与源码解析

    最近终于写完了毕业论文.想仔细研究下Cartographer.无奈自己学识有限,先看下网上大牛的解析,作一个汇总. 一.泡泡机器人原创专栏-cartographer理论及实践浅析 http://mp. ...

  4. Non-negative Partial Sums(单调队列)

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  5. Golang性能调优入门

    如何利用golang自带的profile工具进行应用程序的性能调优,前一段时间我做的日志分析系统在线上遇到了一个问题,就是分任务的系统down机了,日志处理延迟了10几个小时,这个时候任务分发系统重启 ...

  6. 使用INTERVAL YEAR TO MONTH类型

    Oracle Database 9i数据库引入了一种新特性,可以用来存储时间间隔.时间间隔的例子包括: ● 1年零3个月 ● 25个月 ● -3天5小时16分 ● 1天7小时 ● -56小时 注意: ...

  7. Android 加速Gradle构建项目

    1. 升级gradle 进入项目文件夹$project/gradle/wrapper/gradle-wrapper.properties, 使用最新的gradle. 修改替换为最新的 distribu ...

  8. C# WebForm 使用NPOI 2 生成简单的word文档(.docx)

    使用NPOI可以方便的实现服务端对Word.Excel的读写.要实现对Word的读写操作,需要引用NPOI.OOXML.dll,应用命名空间XWPF. 本文使用NPOI 2.0实现对Word的基本生成 ...

  9. asp.net 发送邮件函数两则

    using System.Net.Mail; using System.Text; using System.Net; #region 邮件发送 /// <summary> /// 邮件发 ...

  10. struts2面试题

    由于找了很久的工作都没有找的,只能四处收集那个面试题的.和看面试题的 还有那个记忆力也不是很好了的,而那些公司面试的时候总会有一个面试题的!   在这里分享给大家(那个本来是想上传文件的,但是找不到的 ...