zoukankan      html  css  js  c++  java
  • BZOJ-2134: 单选错位 (期望DP)

    2134: 单选错位

    Time Limit: 10 Sec  Memory Limit: 259 MB
    Submit: 1010  Solved: 779
    [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

    推一推即可知转移方程qwq

     1 #include "bits/stdc++.h"
     2 using namespace std;
     3 typedef long long LL;
     4 const int MAX=1e7+5;
     5 int n,A,B,C,a[MAX];
     6 double ans;
     7 int main(){
     8     freopen ("wrong.in","r",stdin);freopen ("wrong.out","w",stdout);
     9     int i,j;
    10     scanf("%d%d%d%d%d",&n,&A,&B,&C,a+1);
    11     for (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;
    12     for (i=1;i<n;i++) ans+=1.0/(max(a[i],a[i+1])*1.0); ans+=1.0/(max(a[1],a[i])*1.0);
    13     printf("%.3lf",ans);
    14     return 0;
    15 }
  • 相关阅读:
    Linux eclipse 编译C++
    poj2774 Long Long Message(后缀数组or后缀自动机)
    ural 1297 Palindrome(Manacher模板题)
    bzoj 2049 Cave 洞穴勘测(LCT)
    codeforces 519E A and B and Lecture Rooms(LCA,倍增)
    hdu3830 (二分+LCA)
    codeforces 337D Book of Evil(dp)
    codeforces 22C System Administrator(构造水题)
    codeforces 144D Missile Silos(最短路)
    codeforces 505B Mr. Kitayuta's Colorful Graph(水题)
  • 原文地址:https://www.cnblogs.com/keximeiruguo/p/7807231.html
Copyright © 2011-2022 走看看