当前位置:网站首页>20 years ICPC Macau station L - random permutation
20 years ICPC Macau station L - random permutation
2022-06-25 02:50:00 【Int i】
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 |
The question : The length is n Of a Array , Each number is 1,2,3,4..n The odds are 1/n, For all permutations p Array ( Such as 1,2,3.1,3,2.2,1,3.2,3,1.3,1,2.3,2,1), All subscripts i It's all established pi<ai What are your mathematical expectations .
The meaning of the question is difficult to understand , It's all permutations p Array answers + get up ,p The array is 1,2 answer 2/4, because a Array has 1,2.2,2 Sure , The probability of two is 2/2*2=0.5,p The array is 2,1 The answer is 0.5, The last is 1.000000.
Ideas : The answer is simple calculation :(n!*n!)/n^n. There is no formula to calculate directly .
, He should mean before 10 Position right ok, therefore c++ Of long double and py Direct decimal calculation can
Code :
#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 Code :
n=(int)(input())
res=1
for i in range(1,n+1):
res*=1.0/n*i*i
print(res)边栏推荐
- LINQ 查询(3)
- Jetson Nano 从入门到实战(案例:Opencv配置、人脸检测、二维码检测)
- UnityShader入门精要——表面着色器
- 软件测试周刊(第77期):只要放弃一次,就会滋生放弃的习性, 原本可以解决的问题也会变得无法解决。
- Doak CMS article management system recommendation
- Call system function security scheme
- Groovy之高级用法
- It is said that Yijia will soon update the product line of TWS earplugs, smart watches and bracelets
- AOSP ~ default attribute value
- F - Spices(线性基)
猜你喜欢

数组-一口气冲完快慢指针

Once beego failed to find bee after passing the go get command Exe's pit

automated testing

After reciting the eight part essay, I won the hemp in June

李宏毅《机器学习》丨6. Convolutional Neural Network(卷积神经网络)

记一次beego通过go get命令后找不到bee.exe的坑

记一次beego通过go get命令后找不到bee.exe的坑

Unity archive system - file in JSON format

消息称一加将很快更新TWS耳塞、智能手表和手环产品线
![Network planning | [four network layers] knowledge points and examples](/img/c3/d7f382409e99eeee4dcf4f50f1a259.png)
Network planning | [four network layers] knowledge points and examples
随机推荐
202112-2 序列查询新解
[live review] battle code pioneer phase 7: how third-party application developers contribute to open source
Overview of AOSP ~ WiFi architecture
qt打包exe文件,解决“无法定位程序输入点_ZdaPvj于动态链接库Qt5Cored.dll”
Transformers Roberta如何添加tokens
centos7.3修改mysql默认密码_详解Centos7 修改mysql指定用户的密码
Pit entry machine learning: I. Introduction
Enlightenment of using shadergraph to make edge fusion particle shader
入坑机器学习:一,绪论
高数 | 精通中值定理 解题套路汇总
left join on和 join on的区别
Dirvish Chinese document of vim
AOSP ~ default attribute value
doak-cms 文章管理系统 推荐
Practice and Thinking on process memory
爱
国信金太阳打新债步骤 开户是安全的吗
折叠屏将成国产手机分食苹果市场的重要武器
电脑端微信用户图片DAT格式解码为图片(TK版)
How transformers Roberta adds tokens