题目链接

题意:给你n个点的坐标,n<=50000,求最远点对

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const int big=50000;
int max(int a,int b) {return a>b?a:b;};
int min(int a,int b) {return a<b?a:b;};
struct node{
int x, y;
}ne[50005];
bool cmp(node a,node b)
{
if(a.x!=b.x)
return a.x<b.x;
return a.y<b.y;
} int cross(node a,node b,node c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
} int a[50005],m,k;
void tubao(int n)
{
sort(ne+1,ne+n+1,cmp);
m=0; for(int i=1;i<=n;i++)
{
while(m>=2&&cross(ne[a[m-1]],ne[a[m]],ne[i])<=0)
m--;
++m;
a[m]=i;
}
k=m;
for(int i=n-1;i>=1;i--)
{
while((m>=k+1)&&cross(ne[a[m-1]],ne[a[m]],ne[i])<=0)
m--;
++m;
a[m]=i;
}
} double dist(int i,int j)
{
return (ne[i].x-ne[j].x)*(ne[i].x-ne[j].x)
+(ne[i].y-ne[j].y)*(ne[i].y-ne[j].y);
} int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
scanf("%d %d",&ne[i].x,&ne[i].y);
tubao(n);
int maxn=0;
for(int i=1;i<=k;i++)
for(int j=k+1;j<=m;j++)
maxn=max(maxn,dist(a[i],a[j]));
//for(int i=1;i<=m;i++)
// cout<<"|||"<<a[i]<<endl;
printf("%d\n",maxn);
}
return 0;
}

  分析:模板

wa代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const int big=50000;
int max(int a,int b) {return a>b?a:b;};
int min(int a,int b) {return a<b?a:b;};
struct node{
int x, y;
}ne[50005];
bool cmp(node a,node b)
{
if(a.x!=b.x)
return a.x<b.x;
return a.y<b.y;
} int cross(node a,node b,node c)
{
return (b.x-a.x)*(c.y-b.y)-(c.x-b.x)*(b.y-a.y);
} int a[50005],m;
void tubao(int n)
{
sort(ne+1,ne+n+1,cmp);
m=0; for(int i=1;i<=n;i++)
{
if(m>2&&cross(ne[a[m-1]],ne[a[m]],ne[i])<0)
m--;
a[++m]=i;
} for(int i=n-1;i>=1;i--)
{
if(i<=(n-2)&&cross(ne[i],ne[a[m]],ne[a[m-1]])>0)
m--;
a[++m]=i;
}
} double dist(int i,int j)
{
return (ne[i].x-ne[j].x)*(ne[i].x-ne[j].x)
+(ne[i].y-ne[j].y)*(ne[i].y-ne[j].y);
} int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
scanf("%d %d",&ne[i].x,&ne[i].y);
tubao(n);
int maxn=0;
for(int i=1;i<=m;i++)
for(int j=1;j<=m;j++)
if(i!=j)
maxn=max(maxn,dist(a[i],a[j]));
//for(int i=1;i<=m;i++)
// cout<<"|||"<<a[i]<<endl;
printf("%d\n",maxn);
}
return 0;
}

  

poj 2187 Beauty Contest 凸包模板+求最远点对的更多相关文章

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

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

  2. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

  3. POJ 2187 Beauty Contest 凸包

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

  4. POJ 2187 Beauty Contest [凸包 旋转卡壳]

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36113   Accepted: 11204 ...

  5. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  6. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

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

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

  8. poj 2187:Beauty Contest(计算几何,求凸包,最远点对)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 26180   Accepted: 8081 D ...

  9. POJ 2187 Beauty Contest (求最远点对,凸包+旋转卡壳)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 24283   Accepted: 7420 D ...

随机推荐

  1. Linux下安装双JDK环境与双服务器

    安装双JDK环境和双服务器,具体操作如下: (1)使用tar -xvf命令解压Tomcat: (2)在Tomcat服务器下的bin文件夹下的catalina.sh文件中的头部加入以下内容: (3)修改 ...

  2. Spring 最常用的 7 大类注解,史上最强整理!

    随着技术的更新迭代,Java5.0开始支持注解.而作为java中的领军框架spring,自从更新了2.5版本之后也开始慢慢舍弃xml配置,更多使用注解来控制spring框架. 而spring的的注解那 ...

  3. 【转】.NET Core + Ocelot + IdentityServer4 + Consul 基础架构实现

    作者:Zhang_Xiang 原文地址:.NET Core + Ocelot + IdentityServer4 + Consul 基础架构实现 先决条件 关于 Ocelot 针对使用 .NET 开发 ...

  4. linux 使用tmux

    一. 什么是tmux 1.1. tmux 是两个单词的缩写,即“Terminal MultipleXer”,意思是“终端复用器“ 1.2. tmux 结构 1.2.1. tmux主要由三层: < ...

  5. 如何實現输入字符串This is an Apple on eBay 输出 Siht si na Elppa no yAbe

    <?php $str = "This is an Apple on eBay"; //定义字符串 $len = strlen($str); //字符串长度 $sup = [] ...

  6. python多任务——协程的使用

    使用yield完成多任务 import time def test1(): while True: print("--1--") time.sleep(0.5) yield Non ...

  7. Windows Runtime (RT)

    学了sl for wp 开发了1年都没入门,只能说自己的学习欲望太低了. 今天偶然才发现wrt 跟 .net 是2个东西... orz. 得抛弃 sl ,wrt才是未来的主流吧... 这篇文章不错 h ...

  8. Git复习(一)之简介、安装、集中式和分布式

    简介 Git是分布式版本控制系统,使用C语言开发的,CVS.SVN是集中式的版本控制系统,集中式的版本控制系统不但速度慢,而且必须联网才能使用. Git是分布式版本控制系统,同一个Git仓库,可以 分 ...

  9. java读取blob全身乱码

    一.BLOB操作 .入库 ()JDBC方式 //通过JDBC获得数据库连接 Class.forName("oracle.jdbc.driver.OracleDriver"); Co ...

  10. 定义一个javascript库的兼容标准

    1. 定义一个库的兼容标准, 比如说是ie6+? 还是ie8+? 还是ie9.2. 原生知识储备,至少你不完整的读过一个库的代码.3. DOM操作和事件上的问题更多的是hack技巧,并不是算法,也不是 ...