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 |
刚AC了,要考虑N=1的清况#include<iostream> #include<math.h> #define PI (3.141592657) using namespace std; typedef struct Point{ double x,y; }Point; double LengthOfTwoPoints(Point x,Point y){ double dx=x.x-y.x,dy=x.y-y.y; return sqrt(dx*dx+dy*dy); } double CaculateAngle(Point a,Point b,Point c){ double la = LengthOfTwoPoints(b,c); double lb = LengthOfTwoPoints(a,c); double lc = LengthOfTwoPoints(a,b); return acos((lb*lb+lc*lc-la*la)/(2*lb*lc)); } double LengthOfArc(double angle,double radius){ return angle*radius; } double LengthOfRope(Point nails[],int N,double radius){ double totalLength=0; int prePos=0,nextPos=0; if(N==1) return 2*PI*radius; for(int i=0;i<N;i++){ prePos=i-1,nextPos=i+1; if(prePos<0) prePos=N-1; if(nextPos>=N) nextPos=0; totalLength+=LengthOfTwoPoints(nails[i],nails[nextPos]) +LengthOfArc(PI-CaculateAngle(nails[i],nails[prePos],nails[nextPos]),radius); } return totalLength; } /*double LengthOfRope(Point nails[],int N,double radius){ double totalLength=2*PI*radius; int nextPos=0; if(N==1) return totalLength; for(int i=0;i<N;i++){ nextPos=i+1; if(nextPos>=N) nextPos=0; totalLength+=LengthOfTwoPoints(nails[i],nails[nextPos]); } return totalLength; }*/ int main(){ Point nails[100]; int N=0; double radius=0; scanf("%d%lf",&N,&radius); for(int i=0;i<N;i++) scanf("%lf%lf",&nails[i].x,&nails[i].y); printf("%.2lf",LengthOfRope(nails,N,radius)); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator