poj 2365
http://acm.pku.edu.cn/JudgeOnline/problem?id=2365
鄙视一下自己,净犯低级错误
#include<stdio.h> #include<math.h> #define PI 3.141592653589 double distance(double x1,double y1,double x2,double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } int main() { int nNail,i; double x[110],y[110],lineleng,radius; //起先半径定义成了int,其实脑子里想着是double,不知怎么大脑短路了 while(scanf("%d%lf",&nNail,&radius)!=EOF) //输入写成了%d,再次短路 { lineleng = 2 * PI * radius; //期间怕精度不够,有换成acos(double(-1))的,没想到用C提交,CE了,C++就不CE了 scanf("%lf%lf",&x[0],&y[0]); //原先当nNail=1时,直接跳过输入,这也是一直WA的原因之一,看了好十几遍后才发现,其实在调试别人的程序时就觉得有点怪,他们没输出,我怎么有输出??? for(i = 1; i < nNail; i++) { scanf("%lf%lf",&x[i],&y[i]); lineleng += distance(x[i-1],y[i-1],x[i],y[i]); } lineleng += distance(x[0],y[0],x[nNail-1],y[nNail-1]); printf("%.2lf\n",lineleng); } return 0; }
/**************************************************************************
                 
原文来自博客园——Submarinex的博客: www.cnblogs.com/submarinex/               
 
*************************************************************************/