zoukankan      html  css  js  c++  java
  • CF550C Divisibility by Eight

    原题链接

    • 题意:给一个数字,要求构造一个数字,只通过删除某些位的数,得到的是能整除 (8) 的数字。
    • 题解:
    • 代码:
        #include <bits/stdc++.h>
        using namespace std;
        typedef long long LL;
        const int N = 2e5 + 10;
        int dp[N][9];
        struct node {
            int pos, data;
            char ans;
        }pre[N][9];
        char a[N];
        int main() {
            cin >> (a  +1);
            int n = strlen(a + 1);
            dp[1][(a[1] - '0')%8] = 1;
            pre[1][(a[1]-  '0')%8] = {0, (a[1] - '0')%8, a[1]};
            for (int i = 2; i <= n; i ++) {
                for (int j = 0; j < 8; j ++) {
                    if (dp[i-1][j]) {
                        dp[i][(j*10 + a[i] - '0')%8] = 1;
                        pre[i][(j*10 + a[i] - '0')%8] = {i-1, j,a[i]};
                        dp[i][j] = 1;
                        //cout << "?";
                        pre[i][j] = pre[i-1][j];
                    }
                }
                if (!dp[i][(a[i] - '0')%8]) {
                    dp[i][(a[i] - '0')%8] = 1;
                    pre[i][(a[i] - '0')%8] = {0, (a[i] - '0')%8, a[i] };
                }
            }
            string ans = "";
            for (int i = 1; i <=n ; i ++) {
                if (dp[i][0]) {
                    node now =  pre[i][0];
                    int u = now.pos;
                    while (u) {
                        ans += now.ans;
                        now = pre[now.pos][now.data];
                        u = now.pos;
                    }
                    ans += now.ans;
                    reverse(ans.begin(), ans.end());
                    puts("YES");
                    cout << ans << endl;return 0;
                }
            }
            puts("NO");
            return 0;
        }
    
  • 相关阅读:
    js 比较日期的大小
    日历(从今天起后面的14天)
    数字转大写
    object对象进行深拷贝
    浏览器渲染机制
    t-5.倒计时(秒杀效果)--本地--服务器(待续)
    s-1.rem自适应
    t-3.跑马灯
    t-2.手机端简单轮播(无滑动效果)
    16.弹性布局
  • 原文地址:https://www.cnblogs.com/Xiao-yan/p/14738187.html
Copyright © 2011-2022 走看看