poj 2187 Beauty Contest 最远点距
/**
求出凸包枚举每个点的矩距离即可 因为凸包上的点可定不多。。
学习: 刚开始WA 了一次,,因为用int 存的, 一看discuss 里提供的数据,想起来,,应该是越界了。。
后来用longlong 就过了。。
**/
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; struct point {
long long x,y;
//point (){}
point (double x=,double y=):x(x),y(y){}
};
point p[],ch[]; typedef point Vector; Vector operator -(point a,point b){
return Vector (a.x-b.x,a.y-b.y);
}
long long cross(Vector a,Vector b){
return a.x*b.y-a.y*b.x;
} bool cmp(point a,point b){
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
long long length(Vector a){
return a.x*a.x+a.y*a.y;
} 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;
} int main()
{
int n;
cin>>n;
for(int i=;i<n;i++){
cin>>p[i].x>>p[i].y;
}
int m = convexHull(p,n,ch);
long long max_len = ;
for(int i=;i<m;i++){
for(int j=i+;j<m;j++){
if(length(ch[j]-ch[i])>max_len)
max_len = length(ch[j]-ch[i]);
}
}
cout<<max_len<<endl;
return ;
}
poj 2187 Beauty Contest 最远点距的更多相关文章
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- 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 Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 24431 Accepted: 7459 D ...
- POJ 2187 Beauty Contest (求最远点对,凸包+旋转卡壳)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 24283 Accepted: 7420 D ...
- poj 2187:Beauty Contest(计算几何,求凸包,最远点对)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 26180 Accepted: 8081 D ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 2187 Beauty Contest
Beauty Contest 题意:给你一个数据范围在2~5e4范围内的横纵坐标在-1e4~1e4的点,问你任意两点之间的距离的最大值的平方等于多少? 一道卡壳凸包的模板题,也是第一次写计算几何的题, ...
- POJ 2187 Beauty Contest [凸包 旋转卡壳]
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36113 Accepted: 11204 ...
随机推荐
- Azure Traffic Manager 现可与 Azure 网站集成!
编辑人员注释:本文章由 WindowsAzure 网站团队高级专家级工程师 Jim Cheshire撰写. AzureTraffic Manager 已经推出有一段时间,这是一种跨多个区域管理网 ...
- python 在 for i in range() 块中改变 i 的值的效果
先上一段代码: for i in range(3): i = 2 print(i) 实际结果是: 2 2 2 可以发现实际效果就是 在每次执行 for 语句块的内容后 i 会被重新赋值
- ubuntu12.04下 安装虚拟主机
Ubuntu Linux 方法一 一.修改/etc/apache2/sites-available/ 1. 打开目录 /etc/apache2/sites-available/, 发现 default ...
- android 数据持久化——I/O操作
上一节中简单的介绍了File的操作,这一节来说说使用android平台自带对象实现文件的基本操作 主要的两个类:openFileOutput(写)和openFileInput(读) 向文件中写如数据代 ...
- cocoapod的安装与使用
cocoaPods的使用 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ...
- Qt多线程编程总结(一)(所有GUI对象都是线程不安全的)
Qt对线程提供了支持,基本形式有独立于平台的线程类.线程安全方式的事件传递和一个全局Qt库互斥量允许你可以从不同的线程调用Qt方法. 这个文档是提供给那些对多线程编程有丰富的知识和经验的听众的.推荐阅 ...
- ThreadSafeClientConnManager用来支持多线程的使用http client
import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.clien ...
- 关于DLL搜索路径顺序的一个问题
DLL的动态链接有两种方法.一种是加载时动态链接(Load_time dynamic linking).Windows搜索要装入的DLL时,按以下顺序:应用程序所在目录→当前目录→Windows SY ...
- poj 2533 Longest Ordered Subsequence(线性dp)
题目链接:http://poj.org/problem?id=2533 思路分析:该问题为经典的最长递增子序列问题,使用动态规划就可以解决: 1)状态定义:假设序列为A[0, 1, .., n],则定 ...
- [置顶] Asp.Net底层原理(一、浏览器和服务器的交互原理)
…… 一.浏览器和服务器的交互原理 二.写自己的"迷你"Asp.net框架 三.Asp.Net的请求与响应过程 1.在此之前,首先简单的模拟一下我们去请求一个网址的时候,浏览器和服 ...