zoukankan      html  css  js  c++  java
  • bzoj2134 单选错位

    单选错位

    Time Limit: 10 Sec Memory Limit: 259 MB

    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的含义见题目描述。
    (2≤n≤10000000, 0≤A,B,C,a1≤100000000)

    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题)

    我从来都不水博客的。。。。我们由这道题可以学会期望可以相加。。。。
    (ans=sum(每道题做对的期望))

    
    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e7 + 5;
    int n, A, B, C, a1;
    double ans = 0;
    int a[maxn];
    
    inline void putit()
    {
    	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; 
    }
    
    inline void workk()
    {
    	for(int i = 1; i < n; ++i)	ans += (1.0) / max(a[i], a[i + 1]);
    	ans += (1.0) / max(a[n], a[1]);
    }
    
    int main()
    {
    	putit();
    	workk();
    	printf("%.3f
    ", ans);
    	return 0;
    }
    
    
    心如花木,向阳而生。
  • 相关阅读:
    CSS3 flexbox弹性布局实例
    移动端自适应:flexible.js可伸缩布局使用
    玩转HTML5移动页面(转自http://tqtan.com/)
    CSS3那些不为人知的高级属性
    android开发问题记录1——Android SDK Manager无法更新Packages
    Javascirpt详解之函数function
    SPFA 最短路
    Sonya and Robots
    三角形问题
    平方和与立方和 七夕节
  • 原文地址:https://www.cnblogs.com/LLppdd/p/8608223.html
Copyright © 2011-2022 走看看