zoukankan      html  css  js  c++  java
  • CodeForces 464 B Restore Cube

    Restore Cube

    题解:

    x->yyy

    其实就是把x代替成yyy这个值。

    如果不好理解的话, 可以试想一下, 刚开始的话 0->0, 1->1, 2->2,...,9->9.

    现在有一条指令 1->23

    那么就是就是0->0, 1->23, 2->2,...,9->9.

    现在又有一条指令2->45

    那么就相当于0->0, 1->453, 2->45,...,9->9.

    就相当于我们求出0~9每个数字分别代表的是什么东西。

    然后我们倒着DP给定的指令。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
    #define LL long long
    #define ULL unsigned LL
    #define fi first
    #define se second
    #define pb push_back
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define lch(x) tr[x].son[0]
    #define rch(x) tr[x].son[1]
    #define max3(a,b,c) max(a,max(b,c))
    #define min3(a,b,c) min(a,min(b,c))
    typedef pair<int,int> pll;
    const int inf = 0x3f3f3f3f;
    const int _inf = 0xc0c0c0c0;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const LL _INF = 0xc0c0c0c0c0c0c0c0;
    const LL mod =  (int)1e9+7;
    const int N = 1e5 + 100;
    char s[N];
    string str[N];
    LL dp[15], base[15];
    void solve(string & sstr){
        int m = sstr[0] - '0';
        int len = sstr.size();
        LL tmp_base = 1; LL tmp_yu = 0;
        for(int i = 3; i < len; ++i){
            int id = sstr[i] - '0';
            tmp_base = (tmp_base * base[id]) % mod;
            tmp_yu = (tmp_yu * base[id] + dp[id]) % mod;
        }
        dp[m] = tmp_yu, base[m] = tmp_base;
    //    cout << m << ' ' << dp[m] << ' '  << base[m] << endl;
    }
    int main(){
        scanf("%s", s+1);
        int n;
        scanf("%d", &n);
        for(int i = 0; i < 10; ++i)
            dp[i] = i, base[i] = 10;
        for(int i = 1; i <= n; ++i){
            cin >> str[i];
        }
        for(int i = n; i >= 1; --i){
            solve(str[i]);
        }
        int m = strlen(s+1);
        LL ans = 0;
        for(int i = 1; i <= m; ++i){
            int id = s[i] - '0';
            ans = (ans * base[id] + dp[id]) % mod;
        }
        cout << ans << endl;
        return 0;
    }
    View Code
  • 相关阅读:
    第十二章学习笔记
    UVa OJ 107 The Cat in the Hat (戴帽子的猫)
    UVa OJ 123 Searching Quickly (快速查找)
    UVa OJ 119 Greedy Gift Givers (贪婪的送礼者)
    UVa OJ 113 Power of Cryptography (密文的乘方)
    UVa OJ 112 Tree Summing (树的求和)
    UVa OJ 641 Do the Untwist (解密工作)
    UVa OJ 105 The Skyline Problem (地平线问题)
    UVa OJ 100 The 3n + 1 problem (3n + 1问题)
    UVa OJ 121 Pipe Fitters (装管子)
  • 原文地址:https://www.cnblogs.com/MingSD/p/10868083.html
Copyright © 2011-2022 走看看