hdu 3310

用积分来做。。。。求出第一象限*8即可

要注意积分的时候dx要取中间,不然过不了(看了别人博客才知道)

 1 #include<stdio.h>
 2 #include<math.h>
 3 double cal(double r1,double r2,double dx)
 4 {
 5     return sqrt(r1*r1-dx*dx)*sqrt(r2*r2-dx*dx);
 6 }
 7 
 8 double fun(double r1,double r2)
 9 {
10     int n=1000000;
11     double dx=(r1<r2?r1:r2)/n;
12     double pi=3.141592653;
13     double v=0;
14     for(int i=0;i<n;i++)
15     {
16         v+=cal(r1,r2,(double)dx*i+dx/2);
17     }
18     return v*8*dx;
19 }
20 
21 int main()
22 {
23     int t;
24     double r1,r2;
25     scanf("%d",&t);
26     while(t--)
27     {
28         scanf("%lf%lf",&r1,&r2);
29         printf("%.2lf\n",fun(r1,r2));
30     }
31     return 0;
32 }

 

posted @ 2013-03-31 15:32  zerojetlag  阅读(168)  评论(0编辑  收藏  举报