1 #include <cstdio>
2 #include <cstring>
3 #include <cmath>
4 #include <algorithm>
5 #define maxn 20000
6 using namespace std;
7 const double eps=1e-8;
8
9 inline double sqr(double x)
10 {
11 return x*x;
12 }
13 inline int dcmp(double x)
14 {
15 if(fabs(x)<eps) return 0;
16 else return x<0?-1:1;
17 }
18 struct node
19 {
20 double x,y;
21 }p[maxn];
22
23 double dis(node a,node b)
24 {
25 return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
26 }
27
28 double cross(node a,node b,node c)
29 {
30 return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
31 }
32
33 double dot(node a,node b)
34 {
35 return a.x*b.x+a.y*b.y;
36 }
37 bool in(node *p,int n,node a)
38 {
39 p[n]=p[0];p[n+1]=p[1];
40 for(int i=0; i<n; i++)
41 {
42 if(-cross(p[i],p[i+1],a)*cross(p[i+1],p[i+2],a)>eps)
43 {
44 return false;
45 }
46 }
47 return true;
48 }
49
50 double disten(node pp,node a,node b)
51 {
52 if(a.x==b.x&&a.y==b.y) return dis(pp,a);
53 node st1;st1.x=b.x-a.x; st1.y=b.y-a.y;
54 node st2;st2.x=pp.x-a.x; st2.y=pp.y-a.y;
55 node st3;st3.x=pp.x-b.x; st3.y=pp.y-b.y;
56 if(dcmp(dot(st1,st2))<0) return dis(pp,a);
57 else if(dcmp(dot(st1,st3)>0)) return dis(pp,b);
58 else return fabs(cross(a,b,pp))/(dis(a,b));
59 }
60
61 int main()
62 {
63 int n;
64 node c;
65 scanf("%lf%lf%d",&c.x,&c.y,&n);
66 double min1=1e10;
67 for(int i=0; i<n; i++)
68 {
69 scanf("%lf%lf",&p[i].x,&p[i].y);
70 }
71 if(in(p,n,c))
72 {
73 printf("%.3lf\n",0.0);
74 }
75 else
76 {
77 for(int i=0; i<n; i++)
78 {
79 min1=min(min1,disten(c,p[i],p[i+1]));
80 }
81 printf("%.3lf\n",2*min1);
82 }
83 return 0;
84 }