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 }
  • 相关阅读:
    动手动脑——登录界面
    异常处理动手动脑问题
    继承与多态
    课程作业04——动手动脑(字符串String)
    创建过的对象的个数
    类和对象动手动脑问题
    第二周进度条
    构建之法阅读笔记01
    新课程界面
    软件工程概论课后作业01
  • 原文地址:https://www.cnblogs.com/SaltyFishQF/p/10310367.html
Copyright © 2011-2022 走看看