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 0 in 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和100显然取。

    接下来可以取个位+十位 or 个,十位

    分类讨论即可

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<functional>
    #include<cmath>
    #include<cctype>
    using namespace std;
    #define For(i,n) for(int i=1;i<=n;i++)
    #define Rep(i,n) for(int i=0;i<n;i++)
    #define Fork(i,k,n) for(int i=k;i<=n;i++)
    #define ForD(i,n) for(int i=n;i;i--)
    #define Forp(x) for(int p=pre[x];p;p=next[p])
    #define RepD(i,n) for(int i=n;i>=0;i--)
    #define MAXN (100+10)
    int n,ans[MAXN],size=0;
    bool b1=0,b2=0;
    int main()
    {
    //	freopen(".in","r",stdin);
    //	freopen(".out","w",stdout);
    	scanf("%d",&n);
    	int p=0;
    	For(i,n)
    	{
    		int a;
    		scanf("%d",&a);
    		if (!a||a==100) ans[++size]=a;
    		else if (a<10&&!b1) b1=1,ans[++size]=a;
    		else if (!(a%10)&&!b2) b2=1,ans[++size]=a;
    		else p=a;
    	}	
    	if (!b1&&!b2&&p) ans[++size]=p;
    	cout<<size<<endl;
    	For(i,size-1) cout<<ans[i]<<' ';cout<<ans[size]<<endl; 
    	
    	return 0;
    }



  • 相关阅读:
    产品经理的创新思维
    大型互联网网站架构心得之二:并、换和其它(转)
    访问IIS元数据库失败解决方法(转)
    (转)SQL Server 假执行,预执行
    从LiveJournal后台发展看 大型网站系统架构以及性能优化方法(转)
    浏览器并发连接数
    转:Session服务器配置指南与使用经验
    转:安装IIS无法找到zClientm.exe文件的解决办法
    使用开源软件,设计高性能可扩展互动网站
    大型互联网网站架构心得之一:分(转)
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3089601.html
Copyright © 2011-2022 走看看