标签:
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int xian(int &x, int &y)
{
int n,i;
for(i=0;i<=1000;i++)
{
if(y==(-x)+i)
{
n=i;
return n;
break;
}
}
}
int main()
{
int x1,x2,y1,y2,n1,n2,i,t,x11,y11,m,j;
double s1,s2,s3,s;
cin>>m;
for(j=1;j<=m;j++)
{
s1=s2=s3=0;
cin>>x1>>y1>>x2>>y2;
n1=xian(x1,y1);
n2=xian(x2,y2);
if(n1>n2)
{
t=n1;n1=n2;n2=t;
x11=x1;x1=x2;x2=x11;
y11=y1;y1=y2;y2=y11;
}
if(n1==n2) s=pow(pow(x1-x2,2)+pow(y1-y2,2),0.5);
else
{
for(i=n1+1;i<n2;i++)
{
s1+=pow(2,0.5)*i;
}
for(i=n1;i<n2;i++)
{
s2+=pow(i*i+(i+1)*(i+1),0.5);
}
s3=pow((x1-n1)*(x1-n1)+y1*y1,0.5)+pow(x2*x2+(y2-n2)*(y2-n2),0.5);
s=s1+s2+s3;
}
cout<<setiosflags(ios::fixed)<<setprecision(3)<<s<<endl;
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/NYNU-ACM/p/4658252.html