当前位置:网站首页>20年ICPC澳门站L - Random Permutation
20年ICPC澳门站L - Random Permutation
2022-06-24 23:48:00 【int 我】
An integer sequence with length nn, denoted by a_1,a_2,\cdots,a_na1,a2,⋯,an, is generated randomly, and the probability of being 1,2,\cdots,n1,2,⋯,n are all \frac{1}{n}n1 for each a_iai (i=1,2,\cdots,n)(i=1,2,⋯,n).
Your task is to calculate the expected number of permutations p_1,p_2,\cdots,p_np1,p2,⋯,pn from 11 to nn such that p_i \le a_ipi≤ai holds for each i=1,2,\cdots,ni=1,2,⋯,n.
Input
The only line contains an integer nn (1 \leq n \leq 50)(1≤n≤50).
Output
Output the expected number of permutations satisfying the condition. Your answer is acceptable if its absolute or relative error does not exceed 10^{-9}10−9.
Formally speaking, suppose that your output is xx and the jury's answer is yy. Your output is accepted if and only if \frac{|x - y|}{\max(1, |y|)} \leq 10^{-9}max(1,∣y∣)∣x−y∣≤10−9.
| Inputcopy | Outputcopy |
|---|---|
2 | 1.000000000000 |
Sample 2
| Inputcopy | Outputcopy |
|---|---|
3 | 1.333333333333 |
Sample 3
| Inputcopy | Outputcopy |
|---|---|
50 | 104147662762941310907813025277584020848013430.758061352192 |
题意:长度为n的a数组中,每个数是1,2,3,4..n的概率都是1/n,对于全排列的p数组(如1,2,3。1,3,2。2,1,3。2,3,1。3,1,2。3,2,1),全部下标i都成立的pi<ai的数学期望是多少。
题意比较难懂,就是所有全排列的p数组答案+起来,p数组为1,2答案2/4,因为a数组有1,2。2,2可以,两个的概率是2/2*2=0.5,p数组为2,1的答案也是0.5,最后就是1.000000。
思路:答案简单算算可以知道为:(n!*n!)/n^n。没有公式直接算即可。
,他的意思应该是前10位对就ok,所以c++的long double和py直接小数计算都可
代码:
#include<bits/stdc++.h>
using namespace std;
#define fo(a,b) for(int i=a;i<=b;i++)
#define inf 0x3f3f3f3f
#define dou long double
#define M 100005
dou res=1,n;
int main(){
cin>>n;
for(dou i=0;i<n;i++){
res*=(n-2*i+i*i/n);
}
printf("%.15Lf\n",res);
return 0;
}
py代码:
n=(int)(input())
res=1
for i in range(1,n+1):
res*=1.0/n*i*i
print(res)边栏推荐
- Charles 抓包工具
- 李宏毅《机器学习》丨6. Convolutional Neural Network(卷积神经网络)
- Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?
- GO同步等待组
- 分布式事务解决方案和代码落地
- Computing service network: a systematic revolution of multi integration
- Pytorch learning notes (VII) ------------------ vision transformer
- Groovy之高级用法
- Insurance can also be bought together? Four risks that individuals can pool enough people to buy Medical Insurance in groups
- 14 bs对象.节点名称.name attrs string 获取节点名称 属性 内容
猜你喜欢
随机推荐
微信小程序获取扫描二维码后携带的参数
Pytorch learning notes (VII) ------------------ vision transformer
Is it out of reach to enter Ali as a tester? Here may be the answer you want
Uncaught Error: [About] is not a <Route> component. All component children of <Routes> must be a <Ro
Dirvish Chinese document of vim
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(2)——将数据库转换为集群模式
如何卸载cuda
AI服装生成,帮你完成服装设计的最后一步
李宏毅《机器学习》丨6. Convolutional Neural Network(卷积神经网络)
Test / development programmers, 30, do you feel confused? And where to go
AOSP ~ default attribute value
Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (3) -- set the database to archive mode
高数 | 精通中值定理 解题套路汇总
Rod and Schwartz cooperated with ZhongGuanCun pan Lianyuan Institute to carry out 6G technology research and early verification
自动化测试
DSPACE的性能渲染问题
Solution of separating matlab main window and editor window into two interfaces
Call system function security scheme
【STL源码剖析】配置器(待补充)
LeetCode 210:课程表 II (拓扑排序)









