继续水水。
发现URAL的题目描述总是让我感觉很纠结。。。
其实就是求第一个点到凸包的最短距离的2倍。。。如果在凸包里面输出0。。。。这样描述好听多了。。
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define FOR(i,s,t) for(int i=s; i<t; i++)
#define BUG puts("here!!!")
#define STOP system("pause")
using namespace std;
const int MAX = 110;
struct point {
double x, y;
void get()
{
scanf("%lf%lf", &x, &y);
}
};
const double eps = 1e-6;
bool dy(double x,double y) { return x > y + eps;} // x > y
bool xy(double x,double y) { return x < y - eps;} // x < y
bool dyd(double x,double y) { return x > y - eps;} // x >= y
bool xyd(double x,double y) { return x < y + eps;} // x <= y
bool dd(double x,double y) { return fabs( x - y ) < eps;} // x == y
double disp2p(point a,point b) // a b 两点之间的距离
{
return sqrt( ( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y ) );
}
// 叉积 (三点)
double crossProduct(point a,point b,point c)//向量 ac 在 ab 的方向 顺时针是正
{
return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y);
}
double disp2seg(point p,point l1,point l2)
{
point t = p;
t.x += l1.y - l2.y; t.y += l2.x - l1.x;
if( dy(crossProduct(l1,t,p)*crossProduct(l2,t,p),0.0) ) //包括点和线段共线
return xy(disp2p(p,l1),disp2p(p,l2)) ? disp2p(p,l1) : disp2p(p,l2);
return fabs( crossProduct(p,l1,l2) )/disp2p(l1,l2);
}
bool pin_convexh(point *p,int n,point a)
{
p[n] = p[0]; p[n+1] = p[1];
for(int i=0; i<n; i++)
if( xy(crossProduct(p[i],p[i+1],a)*
crossProduct(p[i+1],p[i+2],a),0.0) )
return false;
return true;
}
point p[MAX], c;
int main()
{
int n;
double r = 1e30;
c.get();
scanf("%d", &n);
FOR(i, 0, n)
p[i].get();
p[n] = p[0];
if( pin_convexh(p, n, c) )
{
puts("0.000");
return 0;
}
FOR(i, 0, n)
r = min(r, disp2seg(c, p[i], p[i+1]));
printf("%.3lf\n", r*2);
return 0;
}