http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28417#problem/F

题目大意:给n个点,求相聚最远距离的平方(输出整形)

集体思路:先求出包围所有点的凸包,然后暴力枚举求解(直接暴力会超时)

#include<iostream>
#include<cmath>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<iomanip> using namespace std;
#define eps 0.0000000001
#define PI acos(-1.0) //*******************************************************************************
//点和向量
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y){}
};
typedef Point Vector;
Vector operator-(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
bool operator<(const Vector& a,const Vector& b){return a.x<b.x||(a.x==b.x && a.y<b.y);}
int dcmp(double x){
if(fabs(x)<eps)return ;
else return x< ? -:;
}
double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//向量点积
double Length(Vector A){return sqrt(Dot(A,A));}//向量模长
double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}
//********************************************************************************
//计算凸包输入点数组p,个数n,输出点数组ch,返回凸包定点数
//输入不能有重复,完成后输入点顺序被破坏
//如果不希望凸包的边上有输入点,把两个<=改成<
//精度要求高时,建议用dcmp比较
//基于水平的Andrew算法-->1、点排序2、删除重复的然后把前两个放进凸包
//3、从第三个往后当新点在凸包前进左边时继续,否则一次删除最近加入的点,直到新点在左边
int ConVexHull(Point* p,int n,Point*ch){
sort(p,p+n);
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;
}
//*******************************************************************
Point x[];
Point ch[];
int main(){
for(int n;cin>>n&&n;){
for(int i=;i<n;i++)cin>>x[i].x>>x[i].y;
sort(x,x+n);
int m=ConVexHull(x,n,ch);
double maxx=-,anss;
for(int i=;i<m;i++){
for(int j=;j<m;j++){
anss=(ch[i].x-ch[j].x)*(ch[i].x-ch[j].x)+(ch[i].y-ch[j].y)*(ch[i].y-ch[j].y);
if(anss>maxx)maxx=anss;
}
}
cout<<(int)maxx<<'\n';
}return ;
}

Beauty Contest的更多相关文章

  1. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

  2. POJ2187 Beauty Contest

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

  3. 【POJ】2187 Beauty Contest(旋转卡壳)

    http://poj.org/problem?id=2187 显然直径在凸包上(黑书上有证明).(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴.....没有排序y轴.. 然后本题数据 ...

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

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

  5. poj 2187 Beauty Contest

    Beauty Contest 题意:给你一个数据范围在2~5e4范围内的横纵坐标在-1e4~1e4的点,问你任意两点之间的距离的最大值的平方等于多少? 一道卡壳凸包的模板题,也是第一次写计算几何的题, ...

  6. Beauty Contest(graham求凸包算法)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25256   Accepted: 7756 Description Bess ...

  7. poj2187 Beauty Contest(旋转卡壳)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Beauty Contest Time Limit: 3000MS   Memor ...

  8. POJ 2187 Beauty Contest 凸包

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27276   Accepted: 8432 D ...

  9. POJ 2187: Beauty Contest(旋转卡)

    id=2187">Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27218   ...

  10. Beauty Contest 凸包+旋转卡壳法

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27507   Accepted: 8493 D ...

随机推荐

  1. grep笔记

    grep "match_text" file1 file2 file3 ...                        #grep可以对多个文件进行过滤 --color   ...

  2. hibernate配置文件中的schema="dbo"在MySQL数据库不可用

    把项目的数据库由SQL Server更改为MySQL之后,发现hibernate报错. 问题在于schema="dbo",使用SQL Sever数据库时正常,使用MySQL数据库需 ...

  3. 【转载】Java中的回车换行符/n /r /t

    source:http://hane00.blog.163.com/blog/static/1600615220126204446809/ '\r'是回车,'\n'是换行,前者使光标到行首,后者使光标 ...

  4. 数位DP

    题意:(hdu 4734) 我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2)+...a(2)*2+a(1)*1,a(i)表示十进制数x中第i位的数字. 题目 ...

  5. Php 笔记

    php基本简介 为何要学习php 通过上网查资料,了解了基本的php知识,并知道了php的优缺点.php是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,利于学习,使用广泛,主要适用 ...

  6. js创建对象的几种方式

    /** * 顺便重温一下对象的创建方式 * 代码简单说明问题就好 * 概念性的东西这里就不提了,只加上自己简单理解 */ /** * 工厂模式,就是将手动的创建细节封装在一个方法里, * return ...

  7. spring事物传播机制与隔离级别

    转载自:http://www.blogjava.net/freeman1984/archive/2010/04/28/319595.html7个传播行为,4个隔离级别, Spring事务的传播行为和隔 ...

  8. python中协程的使用示例

    例子1 把字符串分割为列表 def line_splitter( delimiter = None ): print( 'ready to split' ) result = None while T ...

  9. javascript基础知识-数组

    1.javascript创建数组时无需声明数组大小或者在数组大小变化时重新分配 2.javascript数组是无类型的 3.数组元素不一定要连续 4.针对稀疏数组,length比所有元素的索引都要大 ...

  10. JDK6环境下升级项目到springframework4.x和tomcat7.x

    springframework 3.x升级到 4.x  1 xsi:schemaLocation 对应的3.x->4.x 2 pom  springframework <propertie ...