mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-09-05 17:50:36 +00:00
Compare commits
2 Commits
78bac3ae8a
...
e04a08e502
Author | SHA1 | Date | |
---|---|---|---|
e04a08e502 | |||
2a16cbde54 |
14
src/8/21/strexpect.cpp
Normal file
14
src/8/21/strexpect.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
假设一个随机数生成器每次随机一个数[1,n],形成一个无限长的字符串s,
|
||||||
|
给定一个长度为m的数,那么第一次在s中出现位置的期望是多少
|
||||||
|
|
||||||
|
n=2 12 的位置
|
||||||
|
e[1]=1/2*1+1/2*(e[1]+1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
|
||||||
|
}
|
29
src/8/22/P1297.cpp
Normal file
29
src/8/22/P1297.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define long long long
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
ios_base::sync_with_stdio(false);
|
||||||
|
cin.tie(NULL);
|
||||||
|
int n;
|
||||||
|
long A, B, C;
|
||||||
|
vector<long> a(10000001);
|
||||||
|
scanf("%d%lld%lld%lld%ld", &n, &A, &B, &C, &a[1]);
|
||||||
|
for (int i = 2; i <= n; ++i) {
|
||||||
|
a[i] = (a[i - 1] * A + B) % 100000001;
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= n; ++i) {
|
||||||
|
a[i] = a[i] % C + 1;
|
||||||
|
}
|
||||||
|
double exp = 0.0;
|
||||||
|
for (int i = 2; i <= n; ++i) {
|
||||||
|
exp += (double)min(a[i - 1], a[i]) / (double)(a[i - 1] * a[i]);
|
||||||
|
}
|
||||||
|
exp += (double)min(a[n], a[1]) / (double)(a[n] * a[1]);
|
||||||
|
printf("%.3f\n", exp);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user