1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 int n,i,t; 6 double x1,y1,x2,y2,s; 7 while(~scanf("%d",&n)) 8 { 9 while(n--) 10 { 11 scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); 12 if(x2+y2 < x1+y1) 13 { 14 t=x1; 15 x1=x2; 16 x2=t; 17 t=y1; 18 y1=y2; 19 y2=t; 20 } 21 t=0; 22 if(x1) 23 { 24 y1+=x1; 25 t-=x1; 26 x1=0; 27 } 28 if(y2) 29 { 30 x2+=y2; 31 t-=y2; 32 y2=0; 33 } 34 for(i=y1,s=0; i<x2; ++i) 35 s+=sqrt(i*i+(i+1)*(i+1)); 36 for(i=y1; i<=x2; ++i) 37 t+=i; 38 s+=t*sqrt(2); 39 printf("%.3lf\n",s); 40 } 41 } 42 }
1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 int n,i,t; 6 double x1,y1,x2,y2,s; 7 while(~scanf("%d",&n)) 8 { 9 while(n--) 10 { 11 scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); 12 if(x2+y2 < x1+y1) 13 { 14 t=x1; 15 x1=x2; 16 x2=t; 17 t=y1; 18 y1=y2; 19 y2=t; 20 } 21 t=0; 22 if(x1) 23 { 24 y1+=x1; 25 t-=x1; 26 x1=0; 27 } 28 if(y2) 29 { 30 x2+=y2; 31 t-=y2; 32 y2=0; 33 } 34 for(i=y1,s=0; i<x2; ++i) 35 s+=sqrt(i*i+(i+1)*(i+1)); 36 for(i=y1; i<=x2; ++i) 37 t+=i; 38 s+=t*sqrt(2); 39 printf("%.3lf\n",s); 40 } 41 } 42 }
原文:http://www.cnblogs.com/qq188380780/p/6087371.html