poj2187 旋转卡(qia)壳(ke)
题意:求凸包的直径
关于对踵点对、旋转卡壳算法的介绍可以参考这里:
http://www.cnblogs.com/Booble/archive/2011/04/03/2004865.html
http://www.cppblog.com/staryjy/archive/2009/11/19/101412.html
http://blog.csdn.net/ACMaker
这里使用了lrj的complex<double>大法来表示复数。
注意别忘了复数乘法的定义:(a+bi)*(c+di)=(ac-bd)+(bc+ad)i
#include <iostream>
#include <complex>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef complex<double> Point; //Point A:complex x+yi
typedef Point Vector;
const double eps=1e-; int dcmp(double x) //return 0:x==0 -1:x<0 1:x>0
{
if (fabs(x)<eps) return ;
else return x<?-:;
} bool operator == (const Point &A,const Point &B)
{
double ax=real(A),ay=imag(A),bx=real(B),by=imag(B);
return dcmp(ax-bx)== && dcmp(ay-by)==;
}
/*
bool operator < (const Point &A,const Point &B)
{
double ax=real(A),ay=imag(A),bx=real(B),by=imag(B);
return ((ax<bx)||(ax==bx && ay<by));
}
*/
bool cmp(const Point &A,const Point &B)
{
double ax=real(A),ay=imag(A),bx=real(B),by=imag(B);
//return ((ax<bx)||(ax==bx && ay<by));
int dx=dcmp(ax-bx),dy=dcmp(ay-by); //return 0:ax==bx -1:ax<bx 1:ax>bx
return ((dx==-)||((dx==)&&(dy==-)));
} double Dot(Vector A,Vector B) //Ax*Bx+Ay*By
{
return real(conj(A)*B);
} double Cross(Vector A,Vector B) //Ax*By-Ay*Bx
{
return imag(conj(A)*B);
} Vector Rotate(Vector A,double rad)
{
return A*exp(Point(,rad));
} double Dist(Point A,Point B) //distance^2
{
double ax=real(A),ay=imag(A),bx=real(B),by=imag(B);
//cout<<ax<<" "<<ay<<" "<<bx<<" "<<by<<" "<<(ax-bx)*(ax-bx)+(ay-by)*(ay-by)<<endl;
return ((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
} double PolygonArea(Point *p,int n)
{
double area=;
for (int i=;i<n-;i++)
area+=Cross(p[i]-p[],p[i+]-p[]);
return area/;
} int convexhull(Point *p,int n,Point *ch)
{
sort(p,p+n,cmp);
int m=;
for (int i=;i<n;i++)
{
while (m> && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)
m--;
ch[m++]=p[i];
}
int k=m;
for (int i=n-;i>=;i--)
{
while (m>k && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)
m--;
ch[m++]=p[i];
}
if (n>) m--;
return m;
} double rotating_calipers(Point *ch,int num)
{
int q=;
double ans=;
ch[num]=ch[];
for(int p=;p<num;p++)
{
while(Cross(ch[p+]-ch[p],ch[q+]-ch[p])>Cross(ch[p+]-ch[p],ch[q]-ch[p]))
q=(q+)%num;
ans=max(ans,max(Dist(ch[p],ch[q]),Dist(ch[p+],ch[q+])));
}
return ans;
} Point p[],ch[];
int n,x,y; int main()
{
//freopen("in.txt","r",stdin);
//freopen("ou.txt","w",stdout); while (cin>>n)
{
for (int i=;i<n;i++)
{
cin>>x>>y;
p[i]=Point(x,y);
} int num=convexhull(p,n,ch);
int ans=rotating_calipers(ch,num); //cout<<num<<" "<<ans<<endl; cout<<ans<<endl;
}
return ;
}
发现一个下载USACO Contest数据的好地方:http://iskren.info/tasks/USACO/
poj2187 旋转卡(qia)壳(ke)的更多相关文章
- BC 2015在百度之星程序设计大赛 - 预赛(1)(矩形区域-旋转卡)
矩形区域 Accepts: 717 Submissions: 1619 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- POJ 2187: Beauty Contest(旋转卡)
id=2187">Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27218 ...
- POJ2187(旋转卡壳)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 35459 Accepted: 10978 ...
- POJ2187 旋转卡壳 求最长直径
给定平面上的一些散点集,求最远两点距离的平方值. 题解: 旋转卡壳求出凸包,然后根据单调性,求出最远两点的最大距离 #pragma GCC optimize(2) #pragma G++ optimi ...
- 3d旋转卡牌
做成向中心缩放就行了,和旋转效果一样的
- [日常摸鱼]POJ2187 BeautyContest-旋转卡壳
原来这个念 旋转卡qia壳ke- 题意:求平面内给定点集里的最远点对,$n \leq 5e4$ 做法就是旋转卡壳啦,话说这题数据范围应该可以再大挺多的. #include<cstdio> ...
- POJ2187 Beauty Contest (旋转卡壳算法 求直径)
POJ2187 旋转卡壳算法如图 证明:对于直径AB 必然有某一时刻 A和B同时被卡住 所以旋转卡壳卡住的点集中必然存在直径 而卡壳过程显然是O(n)的 故可在O(n)时间内求出直径 凸包具有良好的性 ...
- 【BZOJ 1069】 凸包+旋转卡壳
1069: [SCOI2007]最大土地面积 Description 在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. Input 第 ...
- bzoj 1069: [SCOI2007]最大土地面积 凸包+旋转卡壳
题目大意: 二维平面有N个点,选择其中的任意四个点使这四个点围成的多边形面积最大 题解: 很容易发现这四个点一定在凸包上 所以我们枚举一条边再旋转卡壳确定另外的两个点即可 旋(xuan2)转(zhua ...
随机推荐
- SQL Server 百万级数据提高查询速度的方法
1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉 ...
- 翻译qmake文档 目录
利用空闲时间把qmke的文档翻译出来,翻译水平有限,有些地方翻译的不好,请谅解, 如果您能指出来,我会很感激并在第一时候做出修改. 翻译qmake文档(一) qmake指南和概述 翻译qmake文档( ...
- Tomcat 项目部署方式
方法一:在Tomcat中的Conf目录中,在Server.Xml中的,<Host/>节点中添加: <Context Path="/Hello"Docbase=&q ...
- Laravel 安装多国语言包后,phpstorm 还是报错
问题: 解决办法: vagrant@homestead:~/Code/awbeci$ composer require "overtrue/laravel-lang:~3.0" 总 ...
- 各地IT薪资待遇讨论
作为一个搞.net开发的程序员,在北京混了三年半,最近准备辞职到上海找工作.由于对上海的IT行业还不是很了解,在这里想让上海的同行们说下你们的情况,以方便我对自己在上海的定位,当然,其余城市的的同行们 ...
- Python 3 与 MySQL 5.6
主要简单说下Python 3.3搭配MySQL Community Server 5.6的使用.在Python 3系列和MySQL 5.0系列里面下面的代码应该都通用.(没有验证) 准备 python ...
- js队列
用指针和数组模拟基本队列 http://blog.csdn.net/zhuwq585/article/details/53177192 js下的事件队列,或者异步队列 http://www.jb51. ...
- Ubuntu安装出现左上角光标一直闪解决方式
Ubuntu安装出现左上角光标一直闪解决方式: 01下载ubunu http://cn.ubuntu.com/download/ 02.软碟通 http://pan.baidu.com/s/1qY8O ...
- why does turn off button means hibernate on my win8
when I upgrated my laptop's system to win8.*,I found it's hibernate when I clicked turn off button. ...
- Shell脚本_启动停止重启sh脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...