zoukankan      html  css  js  c++  java
  • 1023 组个最小数 (20分)

    贪心策略是:先从1 ~ 9中选择个数不为0的最小的数输出,然后从0~9输出数字,每个数字输出次数为其剩余个数。

    策略正确性的证明:首先,由于所有数字都必须参与组合,因此最后结果的位数是确定的。然后,由于最高位不能为0,因此需要从[1, 9]中选择最小的数输出( 如果存在两个长度相同的数的最高位不同,那么一定是最高位小的数更小)。最后,针对除最高位外的所有位,也是从高位到低位优先选择[0,9]中还存在的最小的数输出。

    const int N=15;
    int cnt[N];
    
    int main()
    {
        for(int i=0;i<10;i++) cin>>cnt[i];
    
        for(int i=1;i<10;i++)
            if(cnt[i])
            {
                cout<<i;
                cnt[i]--;
                break;
            }
    
        for(int i=0;i<10;i++)
            for(int j=0;j<cnt[i];j++)
                cout<<i;
        cout<<endl;
        //system("pause");
        return 0;
    }
    
  • 相关阅读:
    第五章
    第四章
    第三章
    第二章
    第一章
    configparser-xml-subprocess-shutil
    sys,os,模块-正则表达式
    %----format 格式化字符串---- 生成器---- 迭代器
    python 内置函数
    python 内置函数!
  • 原文地址:https://www.cnblogs.com/fxh0707/p/14338214.html
Copyright © 2011-2022 走看看