zoukankan      html  css  js  c++  java
  • [Offer收割]编程练习赛38

    漏写的数字

    #pragma comment(linker, "/STACK:102400000,102400000")
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<vector>
    #include<algorithm>
    #include<iostream>
    #include<map>
    #include<queue>
    #include<stack>
    #include<string>
    #include<functional>
    //#include<bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    
    
    
    int cmp(const void * x, const void * y) {
    #define datatype int
        datatype dx = *((datatype *)(x)), dy = *((datatype *)(y));
        //x < y
        return dx > dy ? 1 : -1;
    #undef datatype
    }
    
    char str[500];
    int s[500];
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
        std::ios::sync_with_stdio(0), cin.tie(0);
        cin >> str;
        bool f, f1;
        int n = strlen(str);
        for (int i = 0; i < n; i++) s[i] = str[i] - '0';
        int ans;
        f = true, f1 = false;
        int b = s[0];
        int ptr = 1;
        while (ptr < n) {
            b++;
            if (b < 10) {
                if (s[ptr] == b) {
                    ptr++;
                    continue;
                } else {
                    if (f1) {
                        f = false;
                        break;
                    } else {
                        f1 = true;
                        ans = b;
                    }
                }
            } else {
                if (s[ptr] == b / 10 && s[ptr + 1] == b % 10) {
                    ptr += 2;
                    continue;
                } else {
                    if (f1) {
                        f = false;
                        break;
                    } else {
                        f1 = true;
                        ans = b;
                    }
                }
            }
        }
        if (f && f1) {
            cout << ans << endl;
            return 0;
        }
        f = true, f1 = false;
        b = s[0] * 10 + s[1];
        ptr = 2;
        while (ptr < n) {
            b++;
            if (b < 10) {
                if (s[ptr] == b) {
                    ptr++;
                    continue;
                } else {
                    if (f1) {
                        f = false;
                        break;
                    } else {
                        f1 = true;
                        ans = b;
                        ptr++;
                    }
                }
            } else {
                if (s[ptr] == b / 10 && s[ptr + 1] == b % 10) {
                    ptr += 2;
                    continue;
                } else {
                    if (f1) {
                        f = false;
                        break;
                    } else {
                        f1 = true;
                        ans = b;
                    }
                }
            }
        }
        if (f && f1) {
            cout << ans << endl;
            return 0;
        }
        return 0;
    }
    View Code

    扁平化管理

    #pragma comment(linker, "/STACK:102400000,102400000")
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<vector>
    #include<algorithm>
    #include<iostream>
    #include<map>
    #include<queue>
    #include<stack>
    #include<string>
    #include<functional>
    //#include<bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    
    
    
    int cmp(const void * x, const void * y) {
    #define datatype int
        datatype dx = *((datatype *)(x)), dy = *((datatype *)(y));
        //x < y
        return dx > dy ? 1 : -1;
    #undef datatype
    }
    
    lint a[100][100];
    const lint inf = 0x7FFFFFFFFFFFFFFF;
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
        std::ios::sync_with_stdio(0), cin.tie(0);
        for (int i = 0; i < 100; i++) {
            for (int j = 1; j < 100; j++) {
                lint aaa = 1, tmp = 1;
                if (i < j - 1) continue;
                for (int k = 1; k < j; k++) {
                    aaa *= (i - k + 1);
                    tmp += aaa;
                    if (tmp > 1e18) break;
                }
                if (tmp > 1e18) a[i][j] = inf;
                else a[i][j] = tmp;
            }
        }
        lint n, l;
        cin >> n >> l;
        bool f = false;
        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < min((lint)100, l + 1); j++) {
                if (a[i][j] >= n && !f) {
                    cout << i << endl;
                    f = true;
                }
            }
        }
        if (!f) {
            if (l == 2) cout << n - 1 << endl;
            else if (l == 3) {
                lint tmp = (lint)sqrt(n);
                if (tmp * tmp + 1 >= n) cout << tmp << endl;
                else cout << tmp + 1 << endl;
            } else {
                for (int i = 0;; i++) {
                    if (i < l - 1) continue;
                    lint aaa = 1, tmp = 1;
                    for (int k = 1; k < l; k++) {
                        aaa *= (i - k + 1);
                        tmp += aaa;
                        if (tmp > 1e18) break;
                    }
                    if (tmp > n) {
                        cout << i << endl;
                        break;
                    }
                }
            }
        }
        return 0;
    }
    View Code

    小球染色

    动态规划:dp[i][j]表示决定了前i个的颜色,最后j个颜色相同的方法数。

    #pragma comment(linker, "/STACK:102400000,102400000")
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<vector>
    #include<algorithm>
    #include<iostream>
    #include<map>
    #include<queue>
    #include<stack>
    #include<string>
    #include<functional>
    //#include<bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    
    
    
    int cmp(const void * x, const void * y) {
    #define datatype int
        datatype dx = *((datatype *)(x)), dy = *((datatype *)(y));
        //x < y
        return dx > dy ? 1 : -1;
    #undef datatype
    }
    
    lint dp[1005][1005];
    const int mod = 1000000007;
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
        std::ios::sync_with_stdio(0), cin.tie(0);
        int n, m, k;
        cin >> n >> m >> k;
        memset(dp, 0, sizeof(dp));
        dp[1][1] = m;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j < k; j++) {
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod;
                dp[i + 1][1] = (dp[i + 1][1] + dp[i][j] * (m - 1)) % mod;
            }
        }
        lint ans = 0;
        for (int i = 1; i < k; i++) ans = (ans + dp[n][i]) % mod;
        cout << ans << endl;
        return 0;
    }
    View Code

    三角形面积和2

  • 相关阅读:
    css-断网图片加载失败,图片表情与文字对齐
    工作中遇到一些不会写的样式
    基础知识题目
    前端基础知识html css
    js match
    jquery.extend()与jquery.fn.extend()的区别
    js apply 与 call
    jdk安装
    js数组操作各种方法
    js获取日期
  • 原文地址:https://www.cnblogs.com/dramstadt/p/7968372.html
Copyright © 2011-2022 走看看