what's wrong with my program?
help plz...
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
struct Point{
int x,y;
Point(int x=0,int y=0):x(x),y(y){}
void Read(){ scanf("%d %d",&x,&y);}
int operator ^ (Point o){ return x*o.y-o.x*y;}
int operator * (Point o){ return x*o.x+y*o.y;}
Point operator - (Point o){ return Point(x-o.x,y-o.y);}
}P[10000],buf;
double dis(double a,double b,double c,Point P){
return (a*(double)P.x+b*(double)P.y+c)/(sqrt(a*a+b*b));
}
double dis(Point p,Point q){
return sqrt((double)((q-p)*(q-p)));
}
int n;
int main(){
buf.Read(); scanf("%d",&n);
rep(i,n) P[i].Read(); P[n]=P[0]; P[n+1]=P[1];
bool inCon=1;
rep(i,n) {
if( ((P[i+1]-P[i]) ^ (buf-P[i])) * ((P[i+2]-P[i+1]) ^ (buf-P[i+1])) <0 ){
inCon=0; break;
}
}
if(inCon) {printf("0.000"); return 0;}
double ans=19970815.0;
rep(i,n){
Point N(P[i+1].y-P[i].y,P[i].x-P[i+1].x); // fa xiang
double c=-(N*P[i]);
double d= ((P[i]-P[i+1])*(buf-P[i+1])) * ((P[i+1]-P[i])*(buf-P[i])) >0
?dis(N.x,N.y,c,buf)
: min(dis(P[i],buf),dis(P[i+1],buf));
if(ans>d) ans=d;
}
printf("%.03lf",ans*2);
}