zoukankan      html  css  js  c++  java
  • Splitting into digits CodeForce#1104A

    题目链接:Splitting into digits 

    题目原文

    Vasya has his favourite number n. He wants to split it to some non-zero digits. It means, that he wants to choose some digits 1,2,,d1,d2,…,dk, such that 191≤di≤9 for all i and 1+2++=d1+d2+…+dk=n.

    Vasya likes beauty in everything, so he wants to find any solution with the minimal possible number of different digits among 1,2,,d1,d2,…,dk. Help him!

    思路

    一开始想的有点复杂,后来一看题目最下面的Note

    In the second test, there are 33 partitions of the number 44 into digits in which the number of different digits is 11. 
    This partitions are [1,1,1,1][1,1,1,1], [2,2][2,2] and [4][4]. Any of these partitions can be found.
    And, for example, dividing the number 44 to the digits [1,1,2][1,1,2] isn't an answer, because it has 22 different digits, that isn't the minimum possible number.

    发现原来[1, 1, 1, 1]也算一组。于是就想是不是只要输出全1就行了,结果就AC了。

    题解

     1 #include <iostream>
     2 #include <cstring>
     3 
     4 using namespace std;
     5 
     6 int main(int argc, char const *argv[])
     7 {
     8     int n;
     9     cin >> n;
    10     cout << n << endl;
    11     for(int i = 0; i < n; i++)
    12     {
    13         cout << "1 " ;
    14     }
    15     return 0;
    16 }
  • 相关阅读:
    QuickFlash
    第五课:类的封装性 M
    第六课:构造方法、匿名对象 M
    第四课:面向对象(基础) M
    第八课:引用传递 M
    第七课:String类 M
    第二课:数组 M
    第三课:方法 M
    ASP .Net的应用程序域(The Application Domain)
    js 解数独程序
  • 原文地址:https://www.cnblogs.com/SaltyFishQF/p/10310367.html
Copyright © 2011-2022 走看看