Poj 2187 Beauty Contest_旋转凸包卡壳
题意:给你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_旋转凸包卡壳的更多相关文章
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- POJ 2187 Beauty Contest(凸包,旋转卡壳)
题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...
- POJ 2187 Beauty Contest(凸包+旋转卡壳)
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- poj 2187 Beauty Contest——旋转卡壳
题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- poj 2187:Beauty Contest(旋转卡壳)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 32708 Accepted: 10156 Description Bes ...
- poj 2187 Beauty Contest —— 旋转卡壳
题目:http://poj.org/problem?id=2187 学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- POJ 2187 Beauty Contest【凸包周长】
题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 2187 Beauty Contest( 凸包求最远点对 )
链接:传送门 题意:给出 n 个点,求出这 n 个点中最远的两个点距离的平方 思路:最远点对一定会在凸包的顶点上,然后直接暴力找一下凸包顶点中距离最远的两个点 /******************* ...
随机推荐
- hdu4536-XCOM Enemy Unknown(爆搜)
XCOM-Enemy Unknown是一款很好玩很经典的策略游戏. 在游戏中,由于未知的敌人--外星人入侵,你团结了世界各大国家进行抵抗.随着游戏进展,会有很多的外星人进攻事件.每次进攻外星人会选择3 ...
- 基于微信公众平台的开发(清华大学第二讲)_Alien的笔记
基于微信公众平台的开发(清华大学第二讲)_Alien的笔记 基于微信公众平台的开发(清华大学第二讲)
- 谷歌Cartographer学习(2)-原理阐述与源码解析
最近终于写完了毕业论文.想仔细研究下Cartographer.无奈自己学识有限,先看下网上大牛的解析,作一个汇总. 一.泡泡机器人原创专栏-cartographer理论及实践浅析 http://mp. ...
- Non-negative Partial Sums(单调队列)
Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- Golang性能调优入门
如何利用golang自带的profile工具进行应用程序的性能调优,前一段时间我做的日志分析系统在线上遇到了一个问题,就是分任务的系统down机了,日志处理延迟了10几个小时,这个时候任务分发系统重启 ...
- 使用INTERVAL YEAR TO MONTH类型
Oracle Database 9i数据库引入了一种新特性,可以用来存储时间间隔.时间间隔的例子包括: ● 1年零3个月 ● 25个月 ● -3天5小时16分 ● 1天7小时 ● -56小时 注意: ...
- Android 加速Gradle构建项目
1. 升级gradle 进入项目文件夹$project/gradle/wrapper/gradle-wrapper.properties, 使用最新的gradle. 修改替换为最新的 distribu ...
- C# WebForm 使用NPOI 2 生成简单的word文档(.docx)
使用NPOI可以方便的实现服务端对Word.Excel的读写.要实现对Word的读写操作,需要引用NPOI.OOXML.dll,应用命名空间XWPF. 本文使用NPOI 2.0实现对Word的基本生成 ...
- asp.net 发送邮件函数两则
using System.Net.Mail; using System.Text; using System.Net; #region 邮件发送 /// <summary> /// 邮件发 ...
- struts2面试题
由于找了很久的工作都没有找的,只能四处收集那个面试题的.和看面试题的 还有那个记忆力也不是很好了的,而那些公司面试的时候总会有一个面试题的! 在这里分享给大家(那个本来是想上传文件的,但是找不到的 ...