hdu6362(求积分)

oval-and-rectangle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 455    Accepted Submission(s): 203


 

Problem Description

Patrick Star find an oval.

The half of longer axes is on the x-axis with length a.

The half of shorter axes is on the y-axis with length b.

Patrick Star plan to choose a real number c randomly from [0,b], after that, Patrick Star will get a rectangle :

1. The four vertexes of it are on the outline of the oval.

2. The two sides of it parallel to coordinate axis.

3. One of its side is y=c.

Patrick Star want to know the expectations of the rectangle's perimeter.

 

 

Input

The first line contain a integer T (no morn than 10), the following is T test case, for each test case :

Each line contains contains two integer a, b (0<b<a<105). Separated by an white space.

 

 

Output

For each test case output one line denotes the expectations of the rectangle's perimeter .

You should keep exactly 6 decimal digits and ignore the remain decimal digits. 

It is guaranted that the 7-th decimal digit of answer wont be 0 or 9.

Sample Input

1

2 1

Sample Output

8.283185

题意:求椭圆内接矩形的周长的期望

解析:

其实就是让求均值,把所有可能周长加起来除去变化范围即可

首先要求出周长公式

我们知道椭圆的公式为

\frac{^{x2}}{^{a2}}-\frac{^{y2}}{^{b2}}=1

这里写图片描述

这样我们知道y的变化范围是[0,b][0,b],并且我们可以求出x用y表示

因此可以得到周长公式

因为我们要求所有可能周长之和因此实际上就是求周长的黎曼和即求周长公式的积分

因此我们实际上要求

我们当时做的时候就求到这里的,然后直接用辛普森求积分的近似公式直接做了,样例过提交死活不对,我们知道肯定是精度问题,然后又手动求导,得到式子,还是不行,就死活用三角函数代换,哎没办法基础知识不牢固,高数都忘了,反正还是太菜了

因此周长和为因为变化范围是0-b 
所以再除以b便是期望

所以最终只需求一个式子

2b+\pia

因为题目要求保留6位小数,并且后面的全部舍去,因此为了防止%.6f造成四舍五入,因此给答案-0.0000005

#include<bits/stdc++.h>
using namespace std;

#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int T;
    scanf("%d",&T);
    while(T--)
	{
        double a,b;
        scanf("%lf%lf",&a,&b);
        double ans = 2 * b + pi * a ;
        printf("%.6f\n",ans-0.0000005);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值