【HDU-6362】解题报告(数学,积分,2018杭电多校第六场)

原始题目

oval-and-rectangle

  • Time Limit: 2000/1000 MS (Java/Others)
  • Memory Limit: 32768/32768 K (Java/Others)
  • Total Submission(s): 647
  • Accepted Submission(s): 310

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

Source

2018 Multi-University Training Contest 6

Recommend

chendu

题目大意

  • 椭圆半长轴为\(a\),半短轴为\(b\),从区间\([0,b]\)随机抽实数\(c\),求过\((0,c)\)点的与椭圆内切,四边与坐标轴平行 的长方形周长

解题思路

  • 是个积分题,不过直接用积分函数计算到制定精度会T(没错我就这么T了一发)
  • 手动算一下
    • 最后除以b得到答案
  • 注意要求不四舍五入,精度应该输出\(ans-0.0000005\)

解题代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <set>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#define INF 0x3f3f3f3f
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define ms(x,a) memset((x),(a),sizeof(a))
using namespace std;
const int maxn=1e5+5;
#define PI acos(-1.0)
int n,m,t;
int a,b;

int main(){
ios::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>a>>b;
double ans=a*PI+2*b;
cout<<fixed<<setprecision(6)<<ans-0.0000005<<endl;
}
}

收获与反思

  • 高数教做人系列