标签:

第i个填到第i+1个的期望得分显然是1/max(a[i],a[i+1]).根据期望的线性性, 我们只需将每个选项的期望值累加即可. 
---------------------------------------------------------------------------
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int maxn = 10000009;
 
int a[maxn];
 
int main() {
	
	int n, A, B, C;
	scanf("%d%d%d%d%d", &n, &A, &B, &C, a + 1); 
      for(int i = 2; i <= n; i++) a[i] = (ll(A) * a[i-1] + B) % 100000001;
	for(int i = 1; i <= n; i++) a[i] = a[i] % C + 1;
	double ans = 1.0 / max(a[1], a[n]);
	for(int i = 1; i < n; i++) 
	    ans += 1.0 / max(a[i], a[i + 1]);
	printf("%.3lf\n", ans);
	
	return 0;
}
--------------------------------------------------------------------------- 
 
2134: 单选错位
Time Limit: 10 Sec  Memory Limit: 259 MB
Submit: 481  Solved: 366
[Submit][Status][Discuss] 
Description
Input
n很大,为了避免读入耗时太多,输入文件只有5个整数参数n, A, B, C, a1,由上交的程序产生数列a。下面给出pascal/C/C++的读入语句和产生序列的语句(默认从标准输入读入): // for pascal readln(n,A,B,C,q[1]); for i:=2 to n do q[i] := (int64(q[i-1]) * A + B) mod 100000001; for i:=1 to n do q[i] := q[i] mod C + 1; // for C/C++ scanf("%d%d%d%d%d",&n,&A,&B,&C,a+1); for (int i=2;i<=n;i++) a[i] = ((long long)a[i-1] * A + B) % 100000001; for (int i=1;i<=n;i++) a[i] = a[i] % C + 1; 选手可以通过以上的程序语句得到n和数列a(a的元素类型是32位整数),n和a的含义见题目描述。
Output
输出一个实数,表示gx期望做对的题目个数,保留三位小数。
Sample Input
3 2 0 4 1
 
Sample Output
1.167
 【样例说明】
 a[] = {2,3,1}
 正确答案	gx的答案	做对题目	出现概率
 {1,1,1}	{1,1,1}	3	1/6
 {1,2,1}	{1,1,2}	1	1/6
 {1,3,1}	{1,1,3}	1	1/6
 {2,1,1}	{1,2,1}	1	1/6
 {2,2,1}	{1,2,2}	1	1/6
 {2,3,1}	{1,2,3}	0	1/6
 共有6种情况,每种情况出现的概率是1/6,gx期望做对(3+1+1+1+1+0)/6 = 7/6题。(相比之下,lc随机就能期望做对11/6题)
 【数据范围】
 对于100%的数据 2≤n≤10000000, 0≤A,B,C,a1≤100000000
 
HINT
Source
BZOJ 2134: 单选错位( 期望 )
标签:
原文地址:http://www.cnblogs.com/JSZX11556/p/4804272.html