当前位置:网站首页>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)
边栏推荐
- Smartctl opens the device and encounters permission denied problem troubleshooting process record
- Pit entry machine learning: I. Introduction
- 14 bs对象.节点名称.name attrs string 获取节点名称 属性 内容
- AOSP ~ 默认属性值
- 一线城市软件测试工资——你拖后腿了吗
- ACM. HJ75 公共子串计算 ●●
- Jetson nano from introduction to practice (cases: opencv configuration, face detection, QR code detection)
- 数组-一口气冲完快慢指针
- 入坑机器学习:一,绪论
- [i.mx6ul] u-boot migration (VI) network driver modification lan8720a
猜你喜欢
Application of TSDB in civil aircraft industry
当他们在私域里,掌握了分寸感
Once beego failed to find bee after passing the go get command Exe's pit
Leetcode 210: curriculum II (topological sorting)
I've been doing software testing for two years. I'd like to give some advice to girls who are still hesitating
Processon producer process (customized)
AI服装生成,帮你完成服装设计的最后一步
Is it out of reach to enter Ali as a tester? Here may be the answer you want
Lihongyi, machine learning 6 Convolutional neural network
Use of hashcat
随机推荐
DDD concept is complex and difficult to understand. How to design code implementation model in practice?
UnityShader入门精要——表面着色器
Random list random generation of non repeating numbers
Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (2) -- convert database to cluster mode
202112-2 序列查询新解
Pit entry machine learning: I. Introduction
I've been doing software testing for two years. I'd like to give some advice to girls who are still hesitating
PyTorch学习笔记(七)------------------ Vision Transformer
Unity存档系统——Json格式的文件
F - Spices(线性基)
ERROR日志格式与注意点
ACM. HJ75 公共子串计算 ●●
JS regular matching numbers, upper and lower case letters, underscores, midlines and dots [easy to understand]
【STL源码剖析】STL六大组件功能与运用(目录)
UnityShader入门精要——PBS基于物理的渲染
Advanced usage of groovy
Groovy之高级用法
Resolution of cross reference in IDA
Call system function security scheme
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(3)—— 把数据库设置为归档模式