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 ...
随机推荐
- POJ 1226 Substrings(后缀数组+二分答案)
[题目链接] http://poj.org/problem?id=1226 [题目大意] 求在每个给出字符串中出现的最长子串的长度,字符串在出现的时候可以是倒置的. [题解] 我们将每个字符串倒置,用 ...
- 菱形java代码
public class boy { //菱形 public static void main(String[] args) { int m=4; for (int i=0;i<=m;i++){ ...
- Unslider – 轻量的响应式 jQuery 内容轮播插件
Unslider 是一款非常轻量的 jQuery 插件(压缩后不到3KB),能够用于任何 HTML 内容的滑动. 可以响应容器的大小变化,自动排布不用大小的滑块.可以通过整合 jQuery.event ...
- 多个viewpager可能产生的问题
由于Fragment的方便性,现在很多人开始大量使用Fragment. 今天使用时遇到各问题,记录下来并分享下. 使用Fragment都会用FragmentActivity ,特别是在用到ViewPa ...
- p95 3.5、3.8
3.5 有一农夫带一条狼,一只羊和一筐菜欲从河的左岸乘船到右岸,但受下列条件限制:(1)船太小,农夫每次只能带一样东西过河:(2)如果没有农夫看管,则狼要吃羊,羊要吃菜.请设计一个过河方案,是的农夫 ...
- [Swust OJ 632]--集合运算(set容器)
题目链接:http://acm.swust.edu.cn/problem/632/ Time limit(ms): 1000 Memory limit(kb): 65535 Description ...
- gridview回顾
第一看asp.net是在做项目之前,感觉收获也很大,第二次看gridview是在做完项目之后对GridView的回顾,这次的感觉是:我需要多想点,知识直到用时方觉少.直入正题吧,看gridview. ...
- codility上的练习(5)
codility出了lesson 5了. (1) 合法括号序列,包括( [ { ) ] }这6种字符的字符串,长度N在[0..200000]范围内,为其是否合法. 要求时间复杂度O(N),空间复杂度O ...
- C——货物管理系统
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> ...
- 转: Transact-sql游标使用详解~~很详细
/*原理:游标就是把数据按照指定要求提取出相应的数据集,然后逐条进行数据处理.1.1游标的概念 游标(Cursor)它使用户可逐行访问由SQL Server返回的结果集. 使用游标(cursor)的一 ...