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 ...
随机推荐
- MSMQ(Microsoft Message Queue)
http://www.cnblogs.com/sk-net/archive/2011/11/25/2232341.html 利用 MSMQ(Microsoft Message Queue),应用程序开 ...
- cocos2dx的build_win32.dat出现问题以及install-template-msvc.dat出现.js没有脚本引擎
关于cocos2dx-2.x.x版本当中出现build_win32.bat执行失败 (针对VS2013)应当在VS的安装路径查找msbuild的文件夹,再其中查找msbuild.exe文件找到四个东西 ...
- android蓝牙打印机
您还未登录!|登录|注册|帮助 首页 业界 移动 云计算 研发 论坛 博客 下载 更多 reality_jie的专栏 编程的过程是一种微妙的享受 目录视图 摘要视图 订阅 CSDN2013 ...
- Being a Good Boy in Spring Festival 尼姆博弈
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Descr ...
- Mac 下安装ruby,以及CocoaPods安装以及使用网摘
ruby安装网址:https://ruby-china.org/wiki/install_ruby_guide CocoaPods安装和使用教程地址:http://code4app.com/artic ...
- sql server操作类(本人自己写的)
package com.mytest; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Prepa ...
- jsQunit
1:什么是单元测试? 1.1:单元测试又称为模块测试,是针对程序模块(软件设计的最小单位)来进行正确性检验的测试工作.单元测试主要是用来检验程式的内部逻辑,也称为个体测试.结构测试或逻辑驱动测试.通常 ...
- 自己封装的一个无限滚动 mark 待传
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- 『TCP/IP详解——卷一:协议』读书笔记——18
2013-08-27 15:44:52 第7章 Ping程序 7.1 引言 “ping”这个名字来源于声纳定为操作.Ping程序由Mike Muuss编写,目的是为了测试另一台主机是否可达.该程序发送 ...
- 表格里使用text-overflow后不能隐藏超出的文本的解决方法
当把text-overflow设为ellipsis时文本溢出内容就能显示为省略标记,而设为clip时就能把文本溢出的部分裁切掉,不过在表格里面使用text-overflow后依旧不能隐藏超 ...