HDU 6362

这场比赛充分暴露了我是学渣的事实

转载地址:https://blog.csdn.net/codeswarrior/article/details/81515593

oval-and-rectangle

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 . 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.
  • 1
  • 2
  • 3
  • 4

Sample Input

1
2 1
  • 1
  • 2
  • 3

Sample Output

8.283185
  • 1
  • 2

题意:

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

分析:

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

首先要求出周长公式

我们知道椭圆的公式为

x2a2+y2b2=1x2a2+y2b2=1

这里写图片描述

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

x=a1−y2b2−−−−−√x=a1−y2b2

因此可以得到周长公式

C=4(x+y)=4y+4a1−y2b2−−−−−√C=4(x+y)=4y+4a1−y2b2

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

因此我们实际上要求∫b04y+4a1−y2b2−−−−−√dy∫0b4y+4a1−y2b2dy

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

设y=bsinθy=bsinθ

∫b04y+4a1−y2b2−−−−−√dy∫0b4y+4a1−y2b2dy

=∫π20(4bsinθ+4acosθ)d(bsinθ)=∫0π2(4bsinθ+4acosθ)d(bsinθ)

=∫π20(4bsinθ+4acosθ)bcosθ dθ=∫0π2(4bsinθ+4acosθ)bcosθ dθ

=∫π204b2sinθcosθ+4abcos2θ dθ=∫0π24b2sinθcosθ+4abcos2θ dθ

=∫π202b2sin2θ+2ab(cos2θ+1)dθ=∫0π22b2sin2θ+2ab(cos2θ+1)dθ

=b2[−cos2θ]π20+ab[sin2θ+2θ]π20=b2[−cos2θ]0π2+ab[sin2θ+2θ]0π2

=2b2+πab=2b2+πab

因此周长和为2b2+πab2b2+πab,因为变化范围是0-b 
所以再除以b便是期望

所以最终只需求一个式子

2b+πa2b+πa

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

code:

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
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、付费专栏及课程。

余额充值