暴力过了

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; struct point{
double x,y;
};
point p[N],s[N];
int n;
double dir(point p1,point p2,point p3)
{
return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);
}
double dis(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double powdis(point p1,point p2)
{
return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
bool comp(point p1,point p2)
{
double te=dir(p[],p1,p2);
if(te<)return ;
if(te==&&dis(p[],p1)<dis(p[],p2))return ;
return ;
}
double Graham()
{
int pos;
double minx,miny;
minx=miny=inf;
for(int i=;i<n;i++)
{
if(p[i].x<minx||(p[i].x==minx&&p[i].y<miny))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
}
swap(p[],p[pos]);
sort(p+,p+n,comp);
int top=;
p[n]=p[];
s[]=p[],s[]=p[],s[]=p[];
for(int i=;i<=n;i++)
{
while(top>=&&dir(s[top-],s[top],p[i])>)top--;
s[++top]=p[i];
}
/* for(int i=0;i<top;i++)
cout<<s[i].x<<" "<<s[i].y<<endl;*/
double ans=;
for(int i=;i<top;i++)
{
for(int j=i+;j<top;j++)
{
ans=max(ans,powdis(s[i],s[j]));
}
}
return ans;
}
int main()
{
/* ios::sync_with_stdio(false);
cin.tie(0);*/
while(~scanf("%d",&n)){
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
printf("%.0f\n",Graham());
}
return ;
}

暴力枚举

但是旋转卡壳死活过不了,

10
0 0
10000 0
1 100
2 199
9999 100
9998 199
100 -900
200 -1799
9800 -1799
9900 -900
这组数据过不了,
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; struct point{
double x,y;
};
point p[N],s[N];
int n;
double dir(point p1,point p2,point p3)
{
return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);
}
double dis(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double powdis(point p1,point p2)
{
return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
bool comp(point p1,point p2)
{
double te=dir(p[],p1,p2);
if(te<)return ;
if(te==&&dis(p[],p1)<dis(p[],p2))return ;
return ;
}
double Graham()
{
int pos;
double minx,miny;
minx=miny=inf;
for(int i=;i<n;i++)
{
if(p[i].x<minx||(p[i].x==minx&&p[i].y<miny))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
}
swap(p[],p[pos]);
sort(p+,p+n,comp);
int top=;
p[n]=p[];
s[]=p[],s[]=p[],s[]=p[];
for(int i=;i<=n;i++)
{
while(top>=&&dir(s[top-],s[top],p[i])>)top--;
s[++top]=p[i];
}
/* for(int i=0;i<top;i++)
cout<<s[i].x<<" "<<s[i].y<<endl;*/
//Rotating Calipers
double ans=;
int resx=,resy=;
for(int i=;i<top;i++)
{
if(s[i].x==s[].x)resx++;
if(s[i].y==s[].y)resy++;
}
if(resx==top||resy==top)return powdis(s[],s[top-]);
if(top==)ans=powdis(s[],s[]);
else
{
int j=;
for(int i=;i<top;i++)
{
while(dir(s[i],s[i+],s[j+])>=dir(s[i],s[i+],s[j]))
j=(j+)%top;
// cout<<endl;
// cout<<i<<" "<<j<<endl;
// cout<<powdis(s[i],s[j])<<" "<<powdis(s[i],s[j+1])<<endl;
ans=max(ans,max(powdis(s[j],s[i]),powdis(s[j+],s[i])));
}
}
return ans;
}
int main()
{
/* ios::sync_with_stdio(false);
cin.tie(0);*/
while(~scanf("%d",&n)){
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
printf("%.0f\n",Graham());
}
return ;
}
/*
4
0 0
0 1
1 1
1 0
*/

rc

不知道哪里出错了,希望有路过的大神帮忙改改错

poj2187凸包最远点对的更多相关文章

  1. 【poj2187】最远点对(勉强凑数)

    题目简述 输入n个点,及其坐标,n<=50000,所有坐标都是不超过10000的整数组成,没有重点. 问最远点对间的距离的平方是多少 题解 这是一道旋转卡壳的裸题 我们要求这个多边形的直径,这可 ...

  2. [Gym-101512C] 凸包+最远点对

    找最大的四边形或者三角形面积,先求凸包,然后枚举两个点,再通过旋转,找最大的另两个点 #include<bits/stdc++.h> #define fi first #define se ...

  3. 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)

    1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...

  4. OpenCV学习(30) 轮廓defects

    上一篇教程中,我们学习了如何计算轮廓的凸包,其实对一个轮廓而言,可能它的凸包和它本身是重合的,也有可能不是重合的.比如下面左边图像的轮廓本身就是凸包,而右边图像的轮廓则不是.我们可以通过函数bool ...

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

    链接:传送门 题意:给出 n 个点,求出这 n 个点中最远的两个点距离的平方 思路:最远点对一定会在凸包的顶点上,然后直接暴力找一下凸包顶点中距离最远的两个点 /******************* ...

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

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

  7. [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)

    http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...

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

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

  9. POJ2187(凸包+旋转卡壳)

    这道题目的大意是给出一组二维空间的顶点,计算其中距离最远的两个顶点之间的距离. 先说明凸包的概念和求法. 定义:对于多边形P,若将P中任意的两个点(包含边上)用一条线段连接,线段都落于该多边形中(含边 ...

随机推荐

  1. TensorFlow学习笔记(三)MNIST数字识别问题

    一.MNSIT数据处理 MNSIT是一个非常有名的手写体数字识别数据集.包含60000张训练图片,10000张测试图片.每张图片是28X28的数字. TonserFlow提供了一个类来处理 MNSIT ...

  2. 20165324 2017-2018-2 《Java程序设计》课程总结

    20165324 2017-2018-2 <Java程序设计>课程总结 每周作业链接汇总 预备作业1:20165324 我期望的师生关系 预备作业2:20165324 学习基础与C语言学习 ...

  3. C++基础之头文件和源文件的关系

    今天找了个解析xml的开源C++项目tinyxml,按照网上的说法去编译,但是一直编译不通过,"无法打开头文件tinyxml.h",但是明明我在工程底下有了这个文件,对于我这种初学 ...

  4. ORM中的related_name

    ORM 的反向查找(related_name) 先定义两个模型,一个是A,一个是B,是一对多的类型. class A(models.Model): name= models.CharField('名称 ...

  5. 88. Merge Sorted Array(从后向前复制)

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...

  6. 31. Next Permutation (下一个全排列)

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  7. SHUOJ - 算法题1 矩阵连乘问题(区间dp)

    链接:http://acmoj.shu.edu.cn/problem/24/ 分析:设\(dp[i][j]\)为矩阵\(A[i:j]\)所需的最少乘法次数,则有dp方程:\(dp[i][j]=min\ ...

  8. Java TreeMap详细介绍和使用示例

    ①对TreeMap有个整体认识 TreeMap是一个有序的key-value集合,它是通过红黑树实现的. TreeMap继承于AbstractMap,所以它是一个Map,即key-value集合. T ...

  9. SpringBoot入门学习(三)

    基于第二讲,这一讲我们主要讲解包含以下内容 springBoot添加对freemarker的支持 使用@RestController处理ajax请求 使用@PathVariable注解获取url参数 ...

  10. netbeans通过wsdl生成webservice的UTF8问题

    在netbeans通过wsdl方式生成的webservice,打开类文件时,提示无法通过UTF-8打开. 这是因为默认生成的文件不是UTF-8格式的,解决方案如下: 1.打开netbeans的安装目录 ...