zoukankan      html  css  js  c++  java
  • 0和5

    题目来源: CodeForces
    基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题
     收藏
     关注

    小K手中有n张牌,每张牌上有一个一位数的数,这个字数不是0就是5。小K从这些牌在抽出任意张(不能抽0张),排成一行这样就组成了一个数。使得这个数尽可能大,而且可以被90整除。

    注意:

    1.这个数没有前导0,

    2.小K不需要使用所有的牌。

    Input
    每个测试数据输入共2行。
    第一行给出一个n,表示n张牌。(1<=n<=1000)
    第二行给出n个整数a[0],a[1],a[2],…,a[n-1] (a[i]是0或5 ) 表示牌上的数字。
    Output
    共一行,表示由所给牌组成的可以被90整除的最大的数,如果没有答案则输出”-1”(没有引号)
    Input示例
    4
    5 0 5 0
    Output示例
    0

    #include<iostream>
    #include<vector>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    typedef long long LL;
    using namespace std;
    /*
    要求由0和5组成能被90整除的最大的数字!
    所有数字加起来能被9整除,该数字就能被9整除,保证至少有一个0(没有前置0),
    该数字就能被90整除
    */
    int n5=0,n0=0;
    int main()
    {
        int n,a;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>a;
            if(a==0)
                n0++;
            else
                n5++;
        }
        if(!n0)
        {
            cout<<-1<<endl;
        }
        else
        {
            int cnt = n5/9;
            if(!cnt)
            {
                cout<<0<<endl;
            }
            else
            {
                while(cnt--)
                {
                    cout<<"555555555";
                }
                while(n0--)
                {
                    cout<<'0';
                }
                cout<<endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    CNN的学习记录
    softmax和softmax loss的学习记录
    Vue2.0 生命周期
    Vue methods 方法
    Vue2.0 全局操作 Vue.set
    Vue2.0 自定义指令 vuedirective
    Vue2.0 构造器的延伸 Vue.extend
    vue computed
    vuecli 脚手架分析
    h5表单介绍与案例
  • 原文地址:https://www.cnblogs.com/joeylee97/p/6323654.html
Copyright © 2011-2022 走看看