Beauty Contest
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的更多相关文章
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- POJ2187 Beauty Contest
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
- 【POJ】2187 Beauty Contest(旋转卡壳)
http://poj.org/problem?id=2187 显然直径在凸包上(黑书上有证明).(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴.....没有排序y轴.. 然后本题数据 ...
- 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
Beauty Contest 题意:给你一个数据范围在2~5e4范围内的横纵坐标在-1e4~1e4的点,问你任意两点之间的距离的最大值的平方等于多少? 一道卡壳凸包的模板题,也是第一次写计算几何的题, ...
- Beauty Contest(graham求凸包算法)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25256 Accepted: 7756 Description Bess ...
- poj2187 Beauty Contest(旋转卡壳)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Beauty Contest Time Limit: 3000MS Memor ...
- POJ 2187 Beauty Contest 凸包
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27276 Accepted: 8432 D ...
- POJ 2187: Beauty Contest(旋转卡)
id=2187">Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27218 ...
- Beauty Contest 凸包+旋转卡壳法
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27507 Accepted: 8493 D ...
随机推荐
- My97Datepicker 去掉 “不合法格式或超期范围”自动纠错限制
官网上,纠错有以下三种,如日期格式不对,或超期,则必须纠错过后,才能继续操作, 但有时,可能允许出错,需要把纠错功能去掉,则可以设置errDealMode = 3,这种模式是官网说没有的, 但能够去掉 ...
- VS2012常用快捷键
Ctrl+K,D ----格式化全部代码 Ctrl+K,F ----格式化选中的代码 Ctrl+K,C ----注释选定内容 Ctrl+K,U ----取消注释选定内容 Ctrl+J或者 Ctrl+S ...
- hd 2112 HDU Today
Problem Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD ...
- Json数据中的特殊字符处理
今天在项目中遇到一个问题,页面上的数据突然显示不出来了,查验后得知是Json数据出现了问题.使用JSON从后台向前台传输数据的时候,当数据本身含有一些特殊字符,会导致JSON数据的解析出错.如果内容中 ...
- java中数组的相关知识
1. 2.数组的命名方法 1)int[]ages=new int[5]; 2) int[]ages; ages=new int[5]; 3)int[]ags={1,2,3,4,5}; 4)int[ ...
- hadoop多次搭建后,完整总结(累死宝宝了,搭建了十多遍了)
1.安装JDK1.1上传运用软件FileZilla,将windows上的jdk压缩包放到linux的root目录下 1.2解压jdk #创建文件夹 mkdir /usr/java(不要挂在在" ...
- Integrate non-OSGi Dependencies
Consider a scenario where you need to use a non-OSGi jar in your OSGi project. Most libraries are no ...
- Android多线程
final Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { ...
- 导入aar文件出错
错误日志: > Could not resolve all dependencies for configuration ':app:_debugCompile'. > Could not ...
- ansible 自动化(2)
模块介绍: copy模块 使用copy模块,可以将本地文件一键复制到远程服务器:-a后跟上参数,参数中指定本地文件和远端路径: [root@ZABBIX ~]# ansible glq -m copy ...