zoukankan      html  css  js  c++  java
  • CF 277.5 C.Given Length and Sum of Digits.. 构造

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    int a[1000];
    int main()
    {
        int m,s;
        cin>>m>>s;
        if(m==1&&s==0)
        {
            cout<<"0 0"<<endl;
            return 0;
        }
        if(s==0)
        {
            cout<<"-1 -1"<<endl;
            return 0;
        }
        if(s>9*m)
        {
            cout<<"-1 -1"<<endl;
            return 0;
        }
        int t=s-1;//精湛的-1 屌不屌?
        for(int i=0;i<m;i++)
        {
            int r=min(t,9);
            a[i]=r;
            t-=r;
        }
        a[m-1]++;
        for(int i=m-1;i>=0;i--)
            cout<<a[i];
        cout<<" ";
        t=s;
        for(int i=0;i<m;i++)
        {
            int r=min(9,t);
            cout<<r;
            t-=r;
        }
        cout<<endl;
        return 0;
    }
  • 相关阅读:
    POJ
    POJ
    BZOJ
    HDU
    codeforces
    BZOJ
    SPOJ
    SPOJ
    SPOJ
    HDU
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4105786.html
Copyright © 2011-2022 走看看