题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2073
(c语言的double类型printf %lf 显示0.00000问题):https://blog.csdn.net/swustzhaoxingda/article/details/83536101
第一次一遍过的题,抚慰了今天抑郁的心情。
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
double soq(int x, int y)
{
return (double)(x*x+y*y);
}
double dist(int l, int x)
{
double d=0.0;
for(int i=1; i<=l; i++)
{
double tmp=soq(i-1, i);
double tmp2=sqrt(tmp);
d+=(double)(i-1)*sqrt(2.0)+tmp2;
}
d+=(double)(x*sqrt(2.0));
return d;
}
int main()
{
int n;
int x1, y1, x2, y2;
cin>>n;
while(n--)
{
cin>>x1>>y1>>x2>>y2;
int l1,l2;
l1=x1+y1;
l2=x2+y2;
double d1,d2;
d1=dist(l1, x1);
d2=dist(l2, x2);
printf("%.3f\n",fabs(d1-d2));
}
return 0;
}