2021-2022年度第三届全国大学生算法设计与编程挑战赛(冬季赛)G. MP4

5 篇文章 0 订阅

Powered by:NEFU AB-IN

Link

G. MP4

  • 题意

    1~n的数字按字典序排序,求前50个

  • 思路

    dfs爆搜即可

    • dfs(l, r, k) 表示边界为l,r,找k个
    • 举个例子 n = 100 n = 100 n=100
    • 优先考虑大的数,所以10倍扩大范围(因为0是最优的),直到不能扩了,如 1 , 10 , 100 1, 10, 100 1,10,100
    • 其次开始在 l , r l, r l,r中枚举,如 11 , 12 , . . . 19 11,12,...19 11,12,...19
    • 当到了10的倍数时,意味着此位数字换了,也就是此位数字为 x x x的数枚举完了,return即可
  • 代码

    /*
    * @Author: NEFU AB-IN
    * @Date: 2022-03-27 10:13:00
    * @FilePath: \ACM\Contest\g.cpp
    * @LastEditTime: 2022-03-27 17:07:56
    */
    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    #define MP make_pair
    #define SZ(X) ((int)(X).size())
    #define IOS                                                                                                            \
        ios::sync_with_stdio(false);                                                                                       \
        cin.tie(0);                                                                                                        \
        cout.tie(0);
    #define DEBUG(X) cout << #X << ": " << X << endl;
    typedef pair<int, int> PII;
    const int INF = 0x3f3f3f3f;
    
    int n, sum;
    
    void dfs(int l, int r, int k)
    {
        if (r > n)
            r = n;
        for (int i = l; i <= r; i++)
        {
            if (i != l && i % 10 == 0)
                return;
            sum++;
            if (sum <= k)
            {
                printf("%lld.mp4\n", i);
                if (sum == k)
                    return;
            }
            if (i * 10 <= n)
                dfs(i * 10, i * 100 - 1, k);
        }
        return;
    }
    signed main()
    {
        scanf("%lld", &n);
        dfs(1, 9, 50);
        return 0;
    }
    
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NEFU AB-IN

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值