POJ-2178 Beauty Contest 凸包+旋转卡壳求最远点对
来源:互联网 发布:选择题自动填充软件 编辑:程序博客网 时间:2024/05/16 05:52
大家都很强, 可与之共勉。
题意:
给您
eps设丑了T了一夜夜夜夜夜夜
题解:
我们首先一定可以秒看出,最远点对一定在凸包上(反证法)。
然后就旋转卡壳。
由这个图
我们可以发现,对于一条边来说,其余另外的点围成的面积,一定是单峰增长的。而使之面积最大的那个点,就是对于他们来讲的最远点,算一下距离,下一次游客已在这一次的基础上移动,保证了时间复杂度。
代码(表示暴力也跑得飞快):
# include <cmath># include <cstdio># include <algorithm>const double eps = 1e-8 ;inline int dcmp ( double x ) { return ( x > -eps ) - ( x < eps ) ;}typedef struct Vector { double x, y ; Vector ( ) { } Vector ( double x, double y ) : x ( x ), y ( y ) { } inline Vector operator + ( const Vector rhs ) const { return Vector ( x + rhs.x, y + rhs.y ) ; } inline Vector operator - ( const Vector rhs ) const { return Vector ( x - rhs.x, y - rhs.y ) ; } inline Vector operator * ( const double k ) const { return Vector ( x * k, y * k ) ; } inline Vector operator / ( const double k ) const { return Vector ( x / k, y / k ) ; } inline double operator * ( const Vector rhs ) const { return x * rhs.x + y * rhs.y ; } inline double operator % ( const Vector rhs ) const { return x * rhs.y - y * rhs.x ; }} Vector, Point ;//得到sp-op和ep-op的叉积//>0时ep在opsp的逆时针方向,<0时顺时针,=0时共线inline double Cross ( Point& sp, Point& ep, Point& op ) { return ( sp.x - op.x ) * ( ep.y - op.y ) - ( ep.x - op.x ) * ( sp.y - op.y ) ;}struct Cmp { inline bool operator ( ) ( const Point& a, const Point& b ) { return ( a.x == b.x ) ? a.y < b.y : a.x < b.x ; }} ;/*------Graham求凸包----*///n为原图的点数,p []为原图的点(0~n-1),top为凸包点的数量(0~top-1),res[]为凸包点的下标,。inline int Graham ( Point* p, int n, Point* res ) { int len ; register int top = 1 ; std :: sort ( p, p + n, Cmp ( ) ) ; for ( int i = 0 ; i < 3 ; ++ i ) res [i] = p [i] ; for ( int i = 2 ; i < n ; ++ i ) { while ( top && dcmp ( Cross ( p [i], res [top], res [top - 1] ) ) >= 0 ) -- top ; res [++ top] = p [i] ; } len = top ; res [++ top] = p [n - 2] ; for ( int i = n - 3 ; i >= 0 ; -- i ) { while ( top != len && dcmp ( Cross ( p[i], res [top], res [top - 1] ) ) >= 0 ) -- top ; res [++ top] = p [i] ; } return top ;}Point p [50050], con [50050] ;inline int dis ( Point a, Point b ) { return ( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y ) ;}int main ( ) {// freopen ( "in.txt", "r", stdin ) ; int n ; scanf ( "%d", & n ) ; for ( int i = 0 ; i < n ; ++ i ) { int a, b ; scanf ( "%d%d", & a, & b ) ; p [i] = Point ( ( double ) a, ( double ) b ) ; } int cnt = Graham ( p, n, con ) ; int rt ( 0 ) ; con [cnt] = con [0] ; for ( int p = 0, q = 1 ; p < cnt ; ++ p ) { while ( dcmp ( fabs ( Cross ( con [q + 1], con [p], con [p + 1] ) ) - fabs ( Cross ( con [q], con [p], con [p + 1] ) ) ) > 0 ) if ( ++ q >= cnt ) q -= cnt ; // !!! rt = std :: max ( rt, std :: max ( dis ( con [q], con [p] ), dis ( con [q], con [p + 1] ) ) ) ; rt = std :: max ( rt, std :: max ( dis ( con [q + 1], con [p] ), dis ( con [q + 1], con [p + 1] ) ) ) ; }/* for ( int i = 0 ; i < cnt ; ++ i ) for ( int j = i + 1 ; j < cnt ; ++ j ) { rt = std :: max ( rt, int ( ( con [i].x - con [j].x ) * ( con [i].x - con [j].x ) + ( con [i].y - con [j].y ) * ( con [i].y - con [j].y ) ) ) ; }*/ printf ( "%d\n", rt ) ;}
阅读全文
0 0
- POJ-2178 Beauty Contest 凸包+旋转卡壳求最远点对
- 【凸包】poj 2187 Beauty Contest (旋转卡壳求平面最远点对)
- POJ 2187 Beauty Contest (求最远点对,凸包+旋转卡壳)
- 【凸包直径&平面最远点对&对锺点(旋转卡壳)】poj 2187 Beauty Contest
- poj 2187 Beauty Contest 计算几何(凸包+旋转卡壳法)/最远点对
- POJ 2187 Beauty Contest(凸包_旋转卡壳之最远点对)
- POJ 2187 Beauty Contest (平面最远点对 凸包+旋转卡壳 推荐)
- [Poj2187]Beauty Contest (旋转卡壳求最远点对)
- POJ 2187 Beauty Contest 最远点对(旋转卡壳)
- POJ 2187 Beauty Contest【平面最远点对+旋转卡壳】
- poj 2187 Beauty Contest(旋转卡壳求最远点对)
- POJ 2187 Beauty Contest (凸包&最远点距&旋转卡壳)
- POJ2187 Beauty Contest(最远点对,凸包+旋转卡壳)
- POJ2187-Beauty Contest- 最远点对问题(凸包+旋转卡壳)
- hdu-2187 Beauty Contest(旋转卡壳求平面最远点对)
- poj 2187 Beauty Contest (旋转卡壳之平面最远点对)
- POJ-2187 Beauty Contest,旋转卡壳求解平面最远点对!
- Poj 2187 Beauty Contest 凸包 求最远顶点对
- Android关于buildToolVersion与CompileSdkVersion的区别 点击打开链接StackOverFlow中对这个问题进行了详细的讨论:http://stackoverfl
- 数据结构实验之图论五:从起始点到目标点的最短步数(BFS)
- 【HTML】之标签
- Database—DML
- Android 内存优化方式
- POJ-2178 Beauty Contest 凸包+旋转卡壳求最远点对
- Google超分辨率论文RAISR实现小结
- CDH 5.x完美卸载
- java+ssm 基础
- 【2017.12.3】4.Median of Two Sorted Arrays(两个排序数组的中值)难
- 随想录(插件的重要思想)
- java线程sleep join yield wait notify notifyAll
- 使用docker制作hexo镜像
- [线段树] 「JOI Open Contest 2017」Bulldozer