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;
}
题解 文章被收录于专栏

主要写一些题目的题解

全部评论

相关推荐

拉丁是我干掉的:把上海理工大学改成北京理工大学。成功率增加200%
点赞 评论 收藏
分享
1 1 评论
分享
牛客网
牛客企业服务