Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
郁闷了怎么我老是WA啊#include <stdio.h> #include <math.h> #define MAXN 1000 class point { private: int x; int y; public: void init(int a,int b) { x=a;y=b; }; int getx() { return x; } int gety() { return y; } double dist(const point &right); }; double point::dist(const point &right) { return sqrt(pow((double)(right.x-x),2)+pow((double)(right.y-y),2)); } int space(point p1,point p2,int x,int y) { return p1.getx()*p2.gety()+x*p1.gety()+p2.getx()*y-p1.getx()*y-x*p2.gety()-p2.getx()*p1.gety(); } int main() { point p[MAXN]; int n,l; int i,j,k; int tempx,tempy; int tx,ty; double sum=0.0; bool loop=true; scanf("%d%d",&n,&l); scanf("%d%d",&tx,&ty); p[0].init(0,0); for(i=k=1;i<n;i++) { scanf("%d%d",&tempx,&tempy); tempx-=tx; tempy-=ty; while(k>1 && space(p[k-2],p[k-1],tempx,tempy)>=0) k--; p[k].init(tempx,tempy); k++; } i=0; while(loop) { while(k-i>3 && space(p[k-2],p[k-1],p[i].getx(),p[i].gety())>=0) k--; loop=false; while(k-i>3 && space(p[k-1],p[i],p[i+1].getx(),p[i+1].gety())>=0) { i++; loop=true; } } for(j=i;j<k-1;j++) sum+=p[j].dist(p[j+1]); sum+=p[j].dist(p[i]); sum+=6.2831852*l; printf("%.0f\n", sum); return 0; } 有点繁琐就是了 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator