思路链接:
https://blog.csdn.net/ACMaker/article/details/3177292
题目链接:
This is the codes:
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define pppp cout<<endl;
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long //1844674407370955161
#define INT_INF 0x3f3f3f3f //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf,sscanf, getchar, fgets之类的一起使用了。
const int dr[]= {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]= {-1, 1, 0, 0, -1, 1, -1, 1};
const int maxn = 2e5+100;
struct Point
{
LL x,y;
Point() {}
Point(LL _x,LL _y)
{
x=_x;
y=_y;
}
Point operator -(Point b) const
{
return Point(x - b.x, y - b.y);
}
LL operator ^ (Point b) const //计算叉积
{
return x*b.y - y*b.x;
}
} s[maxn],ch[maxn];
int top,n,m;
LL cs(Point p0,Point p1,Point p2) //向量p0->p1 叉乘 向量p0->p2
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
double pow_2(double x)//平方
{
return x*x;
}
double dis(Point p1,Point p2)//两点距离
{
return sqrt(pow_2(p1.x-p2.x)+pow_2(p1.y-p2.y));
}
bool cmp(Point p1,Point p2)
{
LL tmp = cs(s[0],p1,p2);
if(tmp>0)
return 1;
else if(tmp<0)
return 0;
else
return dis(s[0],p1)<dis(s[0],p2);//叉积为零,表示垂直
}
void graham() //生成凸包,ch从0开始存放
{
if(n==1)
ch[top++] = s[0];
else
{
for(int i = 0; i < n; i ++)
{
while(top>1&&cs(ch[top-2],ch[top-1],s[i])<=0)
top --;
ch[top++] = s[i];
}
}
}
double len(Point a,Point b,Point c) //两点式情况下点到直线的距离
{
double s = abs(cs(a,b,c));
return s/dis(a,b);
}
double cps() //旋转卡壳
{
if(top<=2)
return 0; //判断凸包退化成线段的情况
double ans = LL_INF;
int cur = 1;
for(int i = 1; i <= top; i ++)
{
Point v = ch[i-1] - ch[i%top];
while((v^(ch[(cur+1)%top]-ch[cur]))<0)
{
cur = (cur+1)%top;
}
ans = min(ans,len(ch[i-1],ch[i%top],ch[cur]));
//使用min求的是旋转卡壳的宽度,
}
return ans;
}
int main()
{
//freopen("D:\\chnegxubianji\\inORout\\in.txt", "r", stdin);
//freopen("D:\\chnegxubianji\\inORout\\out.txt", "w", stdout);
while(~scanf("%d%d",&n,&m))
{
top=0;
Point p0(0,1e9);
int k;
for(int i = 0; i < n; i ++)
{
scanf("%lld%lld",&s[i].x,&s[i].y);
if(p0.y>s[i].y||(p0.y==s[i].y&&p0.x>s[i].x))
{
p0 = s[i];
k = i;
}
}
swap(s[0],s[k]);
sort(s+1,s+n,cmp); //极角排序,跳过第0个
graham();
printf("%.15lf\n",cps());
}
return 0;
}