oval-and-rectangle

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

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
 
Recommend
chendu   |   We have carefully selected several similar problems for you:  6373 6372 6371 6370 6369 
 
 
题意:给你椭圆的短轴长和长轴长,求y=c和椭圆相交的点的矩形周长的期望
分析:首先根据题目给出的椭圆短轴长和长轴长可以得出椭圆的方程:x^2/a^2 + y^2/b^2
  然后把y=c带进椭圆的方程可以求出对应的横坐标,矩形的周长即4*c+4*a*sqrt(1-c*c/b*b)
  接着对椭圆的周长公式进行积分,注意我们求的是周长的期望所以积分的结果还要除以b(y可以取的最大值)
  积分过程:
  
上面图片最后两行公式错了,应该是2b*b+π*a*b,最后除以b以后的期望是2*b+π*a
AC代码:
#pragma comment(linker, "/STACK:102400000,102400000")
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<string>
#include<cstdio>
#include<bitset>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<set>
#include<map>
using namespace std;
#define debug test
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#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 all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#define eps 1e-10
typedef pair<int,int> PII;
const ll mod = 1e9+7;
const int N = 1e6+10;
const double PI = acos(-1.0);
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qp(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int to[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; int a,b,t; int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>t;
while(t--) {
cin>>a>>b;
double ans = 2.0*b+PI*a;
///double ans = 1.0*a*a+2.0*a/b*PI;
ans = ans-5*1e-7; //严格控制在小数点后六位
printf("%.6lf\n",ans);
///printf("%.6lf\n",ans);
}
return 0;
}

  

杭电第六场 hdu6362 oval-and-rectangle 积分求期望的更多相关文章

  1. hdu6373 Pinball 杭电第六场 物理知识

    Pinball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  2. 杭电第四场 hdu6336 Problem E. Matrix from Arrays 打表找规律 矩阵前缀和(模板)

    Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 ...

  3. hdu6354 杭电第五场 Everything Has Changed 计算几何

    Everything Has Changed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java ...

  4. hdu6351 Beautiful Now 杭电第五场 暴力枚举

    Beautiful Now Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  5. 喝奶茶最大值(不能喝自己班级的)2019 Multi-University Training Contest 8--hdu杭电第8场(Roundgod and Milk Tea)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6667 题意: 有 n个班级,每个班级有a个人.b个奶茶,每个班的人不能喝自己的奶茶,只能喝别人班的奶茶 ...

  6. 杭电 1856 More is better (并查集求最大集合)

    Description Mr Wang wants some boys to help him with a project. Because the project is rather comple ...

  7. 杭电 1213 How Many Tables (并查集求团体数)

    Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius ...

  8. 牛客网第9场多校E(思维求期望)

    链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 题目描述 Niuniu likes to play OSU! We simplify the ...

  9. 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)

    以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...

随机推荐

  1. hdoj 4715 Difference Between Primes 素数筛选+二分查找

    #include <string.h> #include <stdio.h> const int maxn = 1000006; bool vis[1000006]; int ...

  2. java+springBoot+Thymeleaf+vue分页组件的定义

    导读 本篇着重介绍java开发环境下,如何写一个vue分页组件,使用到的技术点有java.springBoot.Thymeleaf等: 分页效果图 名称为vuepagerbasic的分页组件,只包含上 ...

  3. 【原创】JAVA进程突然消失的原因?

    引言 值此七夕佳节,烟哥放弃了无数妹纸的邀约,坐在电脑面前码字,就是为了给读者带来新的知识,这是一件伟大的事业! 好吧,实际情况是没人约.为了化解尴尬,我决定卖力写文章,嗯,一定是我过于屌丝! 好了, ...

  4. python3学习-logging模块

    1.logging模块的使用非常简单,引入模块就可以使用. import logging logging.debug('This is debug message') logging.info('Th ...

  5. js拖拽上传图片

    有时候,在开发中,需要遇到拖拽上传图片的需求,即从磁盘选中一张或多张图片,然后按着鼠标把图片拖动到页面上指定的区域,实现图片的上传. 1.后端上传图片的接口 我是之前用vue写一个简单的后台系统的时候 ...

  6. docker/kubernetes国内源/镜像源解决方式

    最近在使用kubeadm时,被各种连接不上搞到崩溃.费了很多力气,基本都解决了.这里统一整理了国内的一些镜像源,apt源,kubeadm源等,以便查阅. 国内镜像源 Azure China提供了目前用 ...

  7. Multiple dex files define Lokhttp3/internal/wsWebSocketProtocol

    Multiple dex files define Lokhttp3/internal/wsWebSocketProtocol 老套路,先晒图 图一:如题,在编译打包时遇到了如上错误,很明显这是一个依 ...

  8. ASP.NET Core MVC 之过滤器(Filter)

    ASP.NET MVC 中的过滤器允许在执行管道中的特定阶段之前或之后运行代码.可以对全局,也可以对每个控制器或每个操作配置过滤器. 1.过滤器如何工作 不同的过滤器类型在管道中的不同阶段执行,因此具 ...

  9. Netty源码分析--内存模型(下)(十二)

    这一节我们一起看下分配过程 PooledByteBuf<T> allocate(PoolThreadCache cache, int reqCapacity, int maxCapacit ...

  10. sparksession创建DataFrame方式

    spark创建dataFrame方式有很多种,官方API也比较多 公司业务上的个别场景使用了下面两种方式 1.通过List创建dataFrame /** * Applies a schema to a ...