zoukankan      html  css  js  c++  java
  • [hdu5255]枚举

    思路:这题与csu1392题目类似,方法类似。枚举最高位,最低位和中间数字的长度,然后列等式,计算中间的数字,看长度是不是跟枚举的一致,需要注意的是中间数字可以有前导0,如果根据等式算出来的中间数字为K,枚举的长度为L,也就是说需要满足length(K)<=L。

    csu1392: http://www.cnblogs.com/jklongint/p/4419007.html

    代码:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    #pragma comment(linker, "/STACK:10240000,10240000")
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <vector>
    #include <algorithm>
    #include <queue>
    using namespace std;
     
    long long ans[1234], MI[12], X;
    int cnt;
    int length(long long x) {
        int ans = 0;
        while (x) {
            ans ++;
            x /= 10;
        }
        return ans;
    }
    void solve(long long L, long long a, long long b) {
        long long ga = (a * X - b * MI[6]) * MI[L + 1] + b * X - a * MI[6];
        long long gb = MI[7] - X * 10, K = ga / gb;
        if (ga % gb == 0 && K >= 0 && length(K) <= L) ans[cnt ++] = a * MI[L + 1] + K * 10 + b;
    }
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("in.txt""r", stdin);
    #endif // ONLINE_JUDGE
        MI[0] = 1;
        for (int i = 1; i < 12; i ++) MI[i] = MI[i - 1] * 10;
        int T, cas = 0;
        cin >> T;
        while (T --) {
            printf("Case #%d: ", ++ cas);
            double x;
            cin >> x;
            X = (long long)(x * MI[6] + 0.1);
            if (X == MI[6]) {
                cout << 0 << endl;
                continue;
            }
            cnt = 0;
            for (int L = 0; L < 9; L ++) {
                for (int a = 1; a < 10; a ++) {
                    for (int b = 0; b < 10; b ++) {
                        solve(L, a, b);
                    }
                }
            }
            cout << cnt << endl;
            for (int i = 0; i < cnt; i ++) {
                printf("%I64d%c", ans[i], i == cnt - 1? ' ' ' ');
            }
        }
        return 0;
    }
  • 相关阅读:
    Python命名规范
    安装pywin32模块
    深度学习框架
    更快速的学习掌握新知识
    使用 Docker + SSH代理 来实现访问内网网站
    magento Too many arguments, expected arguments "command".
    使用 Prestissimo 提高 composer 下载速度
    使用Lebab 将 Javascript ES5 转 ES6
    分享网络上学习英语的方法或技巧
    使用 Expo 的错误 WebSocket connection to 'ws://localhost:19002/debugger-proxy?role=debugger&name=Chrome' failed: Error during WebSocket handshake: Unexpected response code: 400
  • 原文地址:https://www.cnblogs.com/jklongint/p/4579007.html
Copyright © 2011-2022 走看看