http://acm.hdu.edu.cn/showproblem.php?pid=2073
自己做了一下,我自己找不到是那里错了,大家看一下这题有什么好方法吗?
我把自己的代码贴在了下面!
#include <stdio.h>
#include <math.h>
int main(void)
{
long n, x1, x2, y1, y2, i, j, he1, he2, temp, temp1, temp2;
double sum;
scanf("%ld", &n);
for(i = 0;i < n;i ++)
{
sum = 0;
scanf("%ld%ld%ld%ld", &x1, &y1, &x2, &y2);
he1 = x1 + y1;
he2 = x2 + y2;
if(he1 > he2)
{
temp = he1;
he1 = he2;
he2 = temp;
temp1 = x1;
x1 = x2;
x2 = temp1;
temp2 = y1;
y1 = y2;
y2 = temp2;
}
for(j = he2;j > he1;j --)
{
sum += sqrt(j * j + (j - 1) * (j - 1));
}
if(he1 != he2)
sum += ((he1 - x1 + x2) * sqrt(2));
else
sum += (fabs(x1 - x2) * sqrt(2));
printf("%.3lf\n", sum);
}
return 0;
}
[此贴子已经被作者于2007-2-1 6:06:43编辑过]