http://poj.org/problem?id=2187

题意:求凸包上最远点距离的平方

思路:开始用旋转卡壳求的最远点,WA,改了好久。。后来又改成枚举凸包上的点。。AC了。。

 #include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int N=;
int n;
struct Point
{
int x,y;
Point(int x = ,int y = ):x(x),y(y) {}
bool friend operator < (const Point &a,const Point &b)
{
return a.x < b.x||(a.x==b.x&&a.y < b.y);
} } p[N],ch[N];
typedef Point Vector;
Vector operator-(Point a,Point b)
{
return Vector(a.x-b.x,a.y-b.y);
}
int Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
int Distance(Point a,Point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int Graham()//判断凸包
{
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;
}
int main()
{
scanf("%d",&n);
for (int i = ; i < n; i++)
scanf("%d %d",&p[i].x,&p[i].y);
int cnt = Graham();
int ans = ;
for (int i = ; i < cnt ; i++)
{
for (int j = ; j < i; j++)
{
int dis = Distance(ch[i],ch[j]);
ans = max(ans,dis);
}
}
printf("%d\n",ans);
return ;
}

旋转卡壳的那段代码,不知道哪错了,先保留着吧。。后期再改。。

 int dia_rotating_calipers(int cnt)//旋转卡壳
{
int dia = ;
int q = ;
for (int i = ; i < cnt; i++)
{
while(Cross(ch[i+]-ch[i],ch[q+]-ch[i]) > Cross(ch[i+]-ch[i],ch[q]-ch[i]))
q = (q+)%n;
dia = max(dia,max(Distance(ch[i],ch[q]),Distance(ch[i+],ch[q+])));
}
return dia;
}

Beauty Contest(凸包求最远点)的更多相关文章

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

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

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

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

  3. poj 2187 Beauty Contest 凸包模板+求最远点对

    题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...

  4. Beauty Contest(graham求凸包算法)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25256   Accepted: 7756 Description Bess ...

  5. POJ(2187)用凸包求最远点对

    Beauty Contest http://poj.org/problem?id=2187 题目描述:输入n对整数点,求最距离远的点对,输出他们距离的平方和 算法:拿到这个题,最朴素的想法就是用2层循 ...

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

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

  7. POJ 2187 Beauty Contest 凸包

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

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

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

  9. Beauty Contest 凸包+旋转卡壳法

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27507   Accepted: 8493 D ...

随机推荐

  1. windows 设置注册表服务自动启动

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\xxx\Start = ,=自动,,=禁用

  2. CDR真实图片转水墨画效果制作教程

    CorelDRAW创造性滤镜组是最具有创造力的滤镜,使用里面的散开滤镜能够实现类似于水墨的表现手法,然后再结合图层的合并模式,让您的图片产生意想不到的视觉效果.本文将利用CorelDRAW软件中提供的 ...

  3. Windows系统设置与北京Internet时间同步

    找到提供Ntp服务器的网址:http://support.ntp.org/我从中找到东北大学的: ntp.neu.edu.cn  ( 202.118.1.46 ) 长话短说,下面开始设置: 修改后的值 ...

  4. C#当中的out关键字(借鉴于CSDN)

    一丶与ref关键字一样,out关键字也是按引用来传递的.out 关键字会导致参数通过引用来传递.这与 ref 关键字类似,不同之处在于 ref 要求变量必须在传递之前进行初始化.若要使用 out 参数 ...

  5. 使用Python的Flask框架,结合Highchart,动态渲染图表(Ajax 请求数据接口)

    参考链接:https://www.highcharts.com.cn/docs/ajax 参考链接中的示例代码是使用php写的,这里改用python写. 需要注意的地方: 1.接口返回的数据格式,这个 ...

  6. 【LeetCode Weekly Contest 26 Q4】Split Array with Equal Sum

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/split-array-with-equal-sum/ ...

  7. UVa - 12661 - Funny Car Racing

    先上题目: 12661 Funny Car RacingThere is a funny car racing in a city with n junctions and m directed ro ...

  8. hdu_1003_Max Sum_201311271630

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  9. mysql实例的连接数max_user_connections 和max_connections 配置的那些事

    今天在查线上问题时,通过phpMyAdmin来进行DML操作,发现比平时慢多了,就各种进原因. 项目的场景是一个mysql实例中创建了多个数据库,猜想可能是相互影响所致. 然后,查询线上Mysql数据 ...

  10. ELECTRON开发环境配置方法

    1.下载并安装Node.js 下载地址:https://nodejs.org/en/download/current/ 安装之后进行验证 2.下载并这装electron 安装命令:npm instal ...