Quasi Binary

Quasi Binary

https://ac.nowcoder.com/acm/problem/110925

题意:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.

You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
题解:
因为分出来得数字只能是十进制,并且只可以用0和1组成,那么最少需要几个数,取决于给定得数得 从最低位到最高位中 数字最大得那一位。
其次我们对于那个数进行减操作即可,某位不为0就输出1,为0就输出0,直到全为0为止。

/*Keep on going Never give up*/
//#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>

#define int long long
#define endl '\n'
#define Accepted 0
#define AK main()
#define I_can signed
using namespace std;
const int maxn =2e5+10;
const int MaxN = 0x3f3f3f3f;
const int MinN = 0xc0c0c00c;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
using namespace std;

int sol(int x){
    int res=0;
    while(x){
        res=max(res,x%10);
        x/=10;
    }
    return res;
}
I_can AK{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int x=sol(n);
    cout<<x<<endl;
    string s=to_string(n);
    for(int i=0;i<x;i++){
        bool flag=false;
        for(auto &j:s){
            if(j>='1') flag=true;
            if(j=='0'&&flag) cout<<"0";
            else if(j!='0'){
                j=j-1;
                cout<<"1";
            }
        }
        cout<<" ";
    }
    //cout<<s<<endl;
    return 0;
}
题解 文章被收录于专栏

主要写一些题目的题解

全部评论

相关推荐

2本硕,在这一个下午真的绷不住了,浪费了太多时间,现在的技术栈还停在C语言和stm32上,找嵌入式的实习面试被拷打,找杭州的一个也找不到,真的心里难受,linux没学过,研二了开始慌了。
一条淡水魚:嵌入式这行的面试我认为实际项目比较重要,技术栈简单的提一嘴就行,面试官在乎的关键点在于你用了这些技术做了哪些工作解决了什么问题,而不是停留在离散的那些个技术栈上,那除了教课没有意义,好比你提到的c语言和32,你用32做过哪些具体的项目?接触过什么外设?使用过哪些公司的SDK?有没有实际产品落地?以及各种只有进入真正的生产环节当中才会积累到的经验......主动去和面试官讨论这些实际的问题,甚至还能就某个具体参数的合理性与他去简单探讨一下,只要技术栈对口,基本上就稳啦~(另外linux和RTOS是嵌入式的标配哦,选一个方向走下去吧)
点赞 评论 收藏
分享
2025-12-01 15:50
内蒙古工业大学 Java
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务