zoukankan      html  css  js  c++  java
  • CF 305A——Strange Addition——————【暴力加技巧】

    A. Strange Addition
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Unfortunately, Vasya can only sum pairs of integers (ab), such that for any decimal place at least one number has digit 0in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.

    Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.

    Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?

    Input

    The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers.

    The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).

    Output

    In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers.

    If there are multiple solutions, print any of them. You can print the numbers in any order.

    Sample test(s)
    input
    4
    100 10 1 0
    output
    4
    0 1 10 100
    input
    3
    2 70 3
    output
    2
    2 70

    题目大意:刚开始没读懂题,还以为是找含有0的数字,选出的这些数字最多有一个不含0。然后错了,又重新读了题目,发现题意理解错了。题意是说从这些数中挑出可以任意相加的数,这里的相加必须是对应位最少有一个0。如果是10、1那么结果就有2个满足,如果是12、1就只有一个满足,结果最少要输出一个数字。

    解题思路:因为数据范围比较小,所以用a,b,c,d,e分别代表0、只有1位且不为0(如9)、有两位且能被10整除(如20)、有两位且不能被10整除(25)、100。分析发现,对于25这种数,如果有9,则不能有25;如果有10则不能有25。这里只要特判就好了。其他的直接判断有就直接加上就好。


        #include<bits/stdc++.h>
        using namespace std;
        int main(){
            int n,i,j,k,a,b,c,d,e,tmp,num;
            int ord[120];
            while(scanf("%d",&n)!=EOF){
                a=b=c=d=e=-1;
                for(i=0;i<n;i++){
                    scanf("%d",&tmp);
                    if(tmp==0){
                        a=tmp;
                    }else if(tmp<10&&tmp>0){
                        b=tmp;
                    }else if(tmp%10==0&&tmp!=100){
                        c=tmp;
                    }else if(tmp!=100&&tmp%10!=0){
                        d=tmp;
                    }else{
                        e=tmp;
                    }
                }
                num=0;
                if(a!=-1){
                    ord[num++]=a;
                }
               if(c!=-1)
                ord[num++]=c;
               if(e!=-1)
                ord[num++]=e;
                if(b!=-1){
                    ord[num++]=b;
                }
                if(b==-1&&c==-1&&d!=-1){
                    ord[num++]=d;
                }
                printf("%d
    ",num);
                printf("%d",ord[0]);
                for(i=1;i<num;i++){
                    printf(" %d",ord[i]);
                }printf("
    ");
            }
            return 0;
        }
    

      



  • 相关阅读:
    变量
    匿名函数与内建函数
    Datanode denied communication with namenode because hostname cannot be resol
    0003.搭建Hadoop的环境
    0001.大数据课程概述与大数据背景知识
    享学首创年薪阿里60W+/对标P7岗移动 架构师成长路线V3.0 ---- Android移动互联网架构开发
    FFmpeg和WebRTC的区别
    查看每个文件下内存占用大小
    linux 删除中文乱码
    FFmpeg 命令大全
  • 原文地址:https://www.cnblogs.com/chengsheng/p/4540280.html
Copyright © 2011-2022 走看看