|
|
вернуться в форумHelp! Not working My idea is: find a minimum convex polygon, for every edge a in polygon w += length of a b = edge after a w += l * (2PI - angle beetwen a and b) --------------------- #include <fstream.h> #include <math.h> inline double sqr(double x) {return x*x;} class Vec2D { public: double x,y; Vec2D(double X=0, double Y=0): x(X), y(Y) {} Vec2D operator-(Vec2D &a) {return Vec2D(x-a.x,y-a.y);} void operator/=(double a) {x/=a; y/=a;} double module() {return sqrt(x*x+y*y);} double operator*(Vec2D &a) {return x*a.x+y*a.y;} double operator^(Vec2D &a) {return sqrt(sqr(x-a.x)+sqr(y-a.y));} } p[1000], c[1000]; //ifstream fin("wall.dat"); #define fin cin int i,n,l, e=1; void main() { fin >> n >> l; for(i=0; i<n; i++) fin >> p[i].x >> p[i].y; int s=0; for(i=1; i<n; i++) if(p[i].x<p[s].x) s=i; c[0]=p[s]; Vec2D d(0,-1), r; double h,w; int a=s,b; while(1) { b=-1; for(i=0; i<n; i++) if(i!=a) { r=p[i]-p[a]; h=(d*r)/r.module(); if(b==-1 || h<=w) {b=i; w=h;} } if(b==s) break; d=p[a]-p[b]; d/=d.module(); c[e++]=p[b]; a=b; } double wall=0; for(i=0; i<e; i++) { a=(i+1)%e; b=(i+2)%e; wall+=c[i]^c[a]; d=c[i]-c[a]; r=c[b]-c[a]; wall+=l*acos((d*r)/d.module()/r.module()); } cout << long(wall) << endl; } |
|
|