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


    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
    这道题的样例告诉我们千万不要写错题号,这样在题目数随机的情况下甚至正确的期望不如随便乱填。
    题解:考虑任意两道相邻的题目,前一题选项数为A,后一题选项数为B,容易得到后一题正确的概率是1/max(A,B),然后每个事件又是相互独立的,所以我们只要一遍线扫就可以了
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    double ans=0;
    int n,A,B,C,a1,last,now;
    int main()
    {
        scanf("%d %d %d %d %d",&n,&A,&B,&C,&a1);
        now=last=a1;
        for(int i=2;i<=n;i++)
        {
            now=((long long)now*A+B)%100000001;
            ans=ans+1.0/(max(last%C+1,now%C+1));
            last=now; 
         }
        ans=ans+1.0/(max(now%C+1,a1%C+1)); 
        printf("%.3f
    ",ans); 
     } 
  • 相关阅读:
    高斯消元学习
    HDU 4596 Yet another end of the world(解一阶不定方程)
    Codeforces Round #318 div2
    HDU 4463 Outlets(一条边固定的最小生成树)
    HDU 4458 Shoot the Airplane(计算几何 判断点是否在n边形内)
    HDU 4112 Break the Chocolate(简单的数学推导)
    HDU 4111 Alice and Bob (博弈)
    POJ 2481 Cows(线段树单点更新)
    HDU 4288 Coder(STL水过)
    zoj 2563 Long Dominoes
  • 原文地址:https://www.cnblogs.com/dancer16/p/7348170.html
Copyright © 2011-2022 走看看