首页 > 代码库 > hdu 2073

hdu 2073

<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://www.mamicode.com/"http://acm.hdu.edu.cn/data/images/C41-1005-1.JPG" alt="" />>
 

Sample Output
1.0002.41410.64654985.0470.000
 

Author
Lily
 

Source
浙江工业大学网络选拔赛
 这道题的求解的时候,分三步来求解,观察得到,所求的路程,是两点到原点的距离差的绝对值,求出给定坐标到原点的距离相减就行了。每个点到原点基本上都会有这样的三种类型的路线,根号2的整数倍,根号下相邻数的平方和,还有就是要是点的坐标不在坐标轴上的时候,还有相应数倍的根号2.
代码如下:
<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>