当前位置:网站首页>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)边栏推荐
- jwt
- Computing service network: a systematic revolution of multi integration
- After reciting the eight part essay, I won the hemp in June
- AOSP ~ default attribute value
- Modifying universal render data at runtime
- Test / development programmers, 30, do you feel confused? And where to go
- UnityShader入门精要——PBS基于物理的渲染
- 数组-一口气冲完快慢指针
- 使用ShaderGraph制作边缘融合粒子Shader的启示
- 计网 | 【四 网络层】知识点及例题
猜你喜欢

Processon producer process (customized)

AOSP ~ WIFI架构总览

PyTorch学习笔记(七)------------------ Vision Transformer

DSPACE的性能渲染问题

jwt

The role of software security testing, how to find a software security testing company to issue a report?

Please run IDA with elevated permissons for local debugging.

Of the seven levels of software testers, it is said that only 1% can achieve level 7

Pit entry machine learning: I. Introduction

背了八股文,六月赢麻了……
随机推荐
Modifying universal render data at runtime
UnityShader入门精要——表面着色器
ida中交叉引用的解析
Charles packet capturing tool
Using qdomdocument to manipulate XML files in QT
PyTorch学习笔记(七)------------------ Vision Transformer
jwt
Lizuofan, co-founder of nonconvex: Taking quantification as his lifelong career
Resolution of cross reference in IDA
软件测试周刊(第77期):只要放弃一次,就会滋生放弃的习性, 原本可以解决的问题也会变得无法解决。
Summary of knowledge points of computer level III (database) test preparation topics
C # realizes crystal report binding data and printing
AI clothing generation helps you complete the last step of clothing design
AOSP ~ default attribute value
ERROR日志格式与注意点
Intranet learning notes (6)
背了八股文,六月赢麻了……
Unity archive system - file in JSON format
计网 | 【四 网络层】知识点及例题
消息称一加将很快更新TWS耳塞、智能手表和手环产品线