CodeForces 441E(Codeforces Round #252 (Div. 2))

思路:dp[i][now][mark][len]   i 表示当前第i 次now存的是后8位,mark为第9位为0还是1 len第九位往高位还有几位和第9位相等。  只存后8位的原因:操作只有200次每次都为加法的话后8位可以表示,如果为乘法第八位已知再加上第九位 和往前的长度已知,所以可以表示所有状态。

所存在问题就是 10 1111 1111 此时加上1之后 会变成 11 0000 0000 但这样并处影响结果 如果之后操作都为加法,只有200次,他不可能影响到前面的1, 乘法相当于左移也不会影响。所以前面的1 不可能作为答案。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include <iostream>
using namespace std;
double d[210][260][2][260];
int a[15];
int main() {
    int x, k, p, h = 0;
    memset(d, 0, sizeof(d));
    memset(a, 0, sizeof(a));
    scanf("%d%d%d", &x, &k, &p);
    while (x) {
        a[h++] = x %2;
        x /= 2;
    }
    int now = 0;
    for (int i = 0; i < 8; ++i)
        if (a[i])
            now += (1 << i);

    if (h < 9) {
        d[0][now][0][0] = 1;
    } else {
        int cnt = 1;
        for (int i = 9; i < h; ++i) {
            if (a[i] != a[i - 1])
                break;
            cnt++;
        }
        d[0][now][a[8]][cnt] = 1;
    }
    for (int i = 0; i < k; ++i) {
        for (int j = 0; j <= 255; ++j) {
            for (int x = 0; x <= 250; ++x) {
                if (j != 255) {
                    d[i + 1][j + 1][0][x] += d[i][j][0][x] * (100 - p) / 100.0;
                    d[i + 1][j + 1][1][x] += d[i][j][1][x] * (100 - p) / 100.0;
                } else {
                    d[i + 1][0][0][x] += d[i][j][1][x] * (100 - p) / 100.0;
                    d[i + 1][0][1][1] += d[i][j][0][x] * (100 - p) / 100.0;
                }

                if (j & (1 << 7)) {
                    d[i + 1][(j << 1) % 256][1][1] += d[i][j][0][x] * p / 100.0;
                    d[i + 1][(j << 1) % 256][1][x + 1] += d[i][j][1][x] * p
                            / 100.0;
                } else {
                    d[i + 1][(j << 1) % 256][0][1] += d[i][j][1][x] * p / 100.0;
                    d[i + 1][(j << 1) % 256][0][x + 1] += d[i][j][0][x] * p
                            / 100.0;
                }
            }
        }
    }
    double sum=0;
    for(int i=1;i<255;++i)
    {
        for(int j=0;j<2;++j)
            for(int x=0;x<=250;++x)
            {
                int now=i;
                int cnt=0;
                while(now%2==0)
                {
                    cnt++;
                    now/=2;
                }
                sum+=d[k][i][j][x]*cnt;
            }
    }
    for(int x=0;x<=250;++x)
        sum+=d[k][0][1][x]*8;
    for(int x=0;x<=250;++x)
        sum+=d[k][0][0][x]*(x+8);
    printf("%.10lf\n",sum);

    return 0;
}

CodeForces 441E(Codeforces Round #252 (Div. 2))

时间: 2024-08-28 11:55:32

CodeForces 441E(Codeforces Round #252 (Div. 2))的相关文章

Codeforces Round #252 (Div. 2) A - Valera and Antique Items

水题 #include <iostream> #include <set> #include <vector> #include <algorithm> using namespace std; int main(){ int n,v; cin >> n >> v; vector<int> res; for(int i = 0; i < n; ++ i){ int k,s; bool flag = false; ci

Codeforces Round #252 (Div. 2)-C,D

C题就是一个简单的模拟,首先给每个人两个.然后把剩下的都给一个人就好了. 给的时候蛇形给. #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<queue> using namespace std; #define LL __int64 #define maxn 330000 int

codeforces Round #252 (Div. 2) C - Valera and Tubes

贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #include <algorithm> #include <utility> using namespace std; typedef pair<int,int> Point; int main(){ int n, m, k, flag = -1; cin >>

Codeforces Round #252 (Div. 2)

A. Valera and Antique Items 题目大意:有一场拍卖,有n个卖家,每个卖家有ki个物品并且底价知道,你想买东西并且只有V元钱,问可以从哪几个商家那里去买 思路:对每个卖家的每样商品作比较即可 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #define maxn 1000 5 using namespace std; 6 int ans[maxn],h,x,k; 7

codeforces Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) B Guess the Permutation

B. Guess the Permutation Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He wr

codeforces Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) C. Constellation

C. Constellation Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, thei-th star is located at coordinates (xi, yi). No two stars are located at the same position. In the

Codeforces 671B/Round #352(div.2) D.Robin Hood 二分

D. Robin Hood We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are n citizens in Kekoland, each person has ci coins. Each day, Robin Hood wi

CodeForces Contest #1114: Round #538 (Div. 2)

比赛传送门:CF #1114. 比赛记录:点我. 又 FST 了. [A]Got Any Grapes? 题意简述: 有三个人,第一个人需要吃绿色葡萄至少 \(a\) 个,第二个人需要吃绿色和紫色葡萄至少 \(b\) 个,第三个人需要吃绿色.紫色和黑色葡萄至少 \(c\) 个. 有 \(x\) 个绿色葡萄,\(y\) 个紫色葡萄,\(z\) 个黑色葡萄,问是否能够满足三个人的要求. 题解: #include <cstdio> int main() { int x, y, z, a, b, c;

终于在CoderForce冲上紫色了(Round #258, Div. 2)

一个多月来历尽艰难, 终于冲上了紫色. 17 Codeforces Round #258 (Div. 2) 93 3 +76 1751 Became Candidate Master htbb → htbb 16 Codeforces Round #257 (Div. 2) 200 3 +165 1675   15 Codeforces Round #256 (Div. 2) 1797 1 -98 1510   14 Codeforces Round #FF (Div. 2) 625 2 -88