• 【codeforces 779B】Weird Rounding


    【题目链接】:http://codeforces.com/contest/779/problem/B

    【题意】

    问你要删掉几个数字才能让原来的数字能够被10^k整除;

    【题解】

    /*
        数字的长度不大;
        让你删掉最小的数字个数
        使得这个数字能被10^k整除;
        搜索;
        枚举哪些数字被删掉了;
        bool记录;
        最后再全部乘起来;
        枚举删掉1个,删掉两个即可、3、4...;   
        注意前导0只能有一个的情况就好
    */


    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%lld",&x)
    
    typedef pair<int, int> pii;
    typedef pair<LL, LL> pll;
    
    const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
    const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
    const double pi = acos(-1.0);
    const int N = 15;
    
    string s;
    int po_w[12],k,len,di,num;
    bool bo[15];
    
    void dfs(int x, int now)
    {
        if (now >= num)
        {
            int nu = 0,t = 0,fir=-1;
            rep1(i, 1, len)
                if (bo[i])
                {
                    if (fir == -1)
                        fir = s[i] - '0';
                    t++;
                    nu = nu * 10 + s[i] - '0';
                }
            if (fir == 0 && t > 1) return;
            if (nu%di == 0)
            {
                printf("%d
    ", num);
                exit(0);
            }
            return;
        }
        if (x > len)
            return;
        bo[x] = false;
        dfs(x + 1, now + 1);
        bo[x] = true;
        dfs(x + 1, now);
    }
    
    int main()
    {
        //freopen("F:\rush.txt", "r", stdin);
        po_w[0] = 1;
        rep1(i, 1, 9)
            po_w[i] = po_w[i - 1] * 10;
        cin >> s;
        len = s.size();
        s = ' ' + s;
        scanf("%d", &k);
        di = po_w[k];
        memset(bo, true, sizeof bo);
        for (num = 0;num <= len-1;num++)
            dfs(1, 0);
        return 0;
    }
  • 相关阅读:
    THUWC2020 游记
    USACO14MAR The Lazy Cow(Gold)
    luogu P3768 简单的数学题
    2017/9/22模拟赛
    2017/9/20模拟赛
    2017/9/15模拟赛
    刷屏代码·稳 from林凯
    2017/9/13模拟赛
    【9018:1368】八数码
    2017/9/10模拟赛
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626589.html
Copyright © 2020-2023  润新知