<span style="font-size:18px;"></span><h1 style="COLOR: #1a5cc8">无限的路</h1><span size="+0"><strong><span style="font-family:Arial;font-size:12px;color:green;FONT-WEIGHT: bold">Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5536 Accepted Submission(s): 2842 </span></strong></span> <div class="panel_title" align="left">Problem Description</div><div class="panel_content">甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接触,所以甜甜只会用它来画直线,于是他就在平面直角坐标系中画出如下的图形: <center><img src="http://acm.hdu.edu.cn/data/images/C41-1005-1.JPG" alt="" /></center> 甜甜的好朋友蜜蜜发现上面的图还是有点规则的,于是他问甜甜:在你画的图中,我给你两个点,请你算一算连接两点的折线长度(即沿折线走的路线长度)吧。</div><div class="panel_bottom"> </div> <div class="panel_title" align="left">Input</div><div class="panel_content">第一个数是正整数N(≤100)。代表数据的组数。 每组数据由四个非负整数组成x1,y1,x2,y2;所有的数都不会大于100。 </div><div class="panel_bottom"> </div> <div class="panel_title" align="left">Output</div><div class="panel_content">对于每组数据,输出两点(x1,y1),(x2,y2)之间的折线距离。注意输出结果精确到小数点后3位。</div><div class="panel_bottom"> </div> <div class="panel_title" align="left">Sample Input</div><div class="panel_content"><pre><div style="FONT-FAMILY: Courier New,Courier,monospace">5 0 0 0 1 0 0 1 0 2 3 3 1 99 99 9 9 5 5 5 5</div>
1.000 2.414 10.646 54985.047 0.000
<span style="font-size:18px;"></span>
<span style="font-size:18px;">#include<stdio.h> #include<math.h> #include<stdlib.h> double f(int a,int b) { double s=0,l; int n,i; n=a+b; l=(double)sqrt(2); for(i=1;i<n;i++) { s+=i*l; } s+=a*l; for(i=0;i<n;i++) s+=sqrt(pow(i,2)+pow(i+1,2)); return s; } int main() { int n; scanf("%d",&n); while(n--) { double sum=0; int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); sum=fabs(f(x1,y1)-f(x2,y2)); printf("%.3lf\n",sum); } return 0; } </span>
原文地址:http://blog.csdn.net/ice_alone/article/details/38345851