oval-and-rectangle

oval-and-rectangle
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

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

题目概述

有一个椭圆形。
半长轴长度为a在x轴上。
半短轴长度为b在y轴上。
在y轴上从[0,b]区间中随机选择一个实数c,经过点(0,c)做一条垂直于y轴的直线,进而得到一个矩形:
1。它的四个顶点在椭圆的轮廓上。
2。它的两边平行于坐标轴。
3。它的一边是y=c。
求矩形周长的期望值。

思路

首先由题意我们可以画出一个图
这里写图片描述

那么很显然我们要求周长的期望,就要对周长进行积分再除以积分区间即可

这里写图片描述
这里写图片描述
这里写图片描述

代码
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define LL long long
#define inf 0x3f3f3f3
const int mod = 1e9+7;
const int N = 1e5+7;
int main ()
{
    int t;
    double a,b,ans;
    scanf("%d",&t);
    while (t--)
    {
        scanf("%lf %lf",&a,&b);
        ans = a*PI+2*b-0.0000005;
        printf("%.6f\n",ans);
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值