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\n",num);
printf("%d",ord[0]);
for(i=1;i<num;i++){
printf(" %d",ord[i]);
}printf("\n");
}
return 0;
}

  


CF 305A——Strange Addition——————【暴力加技巧】的更多相关文章

  1. zzulioj--1815--easy problem(暴力加技巧)

    1815: easy problem Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 98  Solved: 48 SubmitStatusWeb Bo ...

  2. Amr and Chemistry---cf558C(暴力,加技巧)

    题目链接:http://codeforces.com/problemset/problem/558/C 题意:有n个数,每个数都可以进行两个操作 *2 或者 /2,求最小的操作次数和,使得所有的数都相 ...

  3. Solution -「CF 1380F」Strange Addition

    \(\mathcal{Description}\)   Link.   定义两个数在进行加法时,进位单独作为一位.例如: .   给定一个 \(n\) 为数和 \(m\) 次修改操作,每次修改会修改 ...

  4. HDU 1496 Equations 等式(二分+暴力,技巧)

    题意:给出4个数字a,b,c,d,求出满足算式a*x1^2+b*x2^2+c*x3^2+d*x4^2=0的 (x1,x2,x3,x4) 的组合数.x的范围[-100,100],四个数字的范围 [-50 ...

  5. ACM 大神的经验加技巧(当然不是我的拉——

    大神 犯错合集及需要注意的东西 1.在一个地图求最大面积的类问题中,要注意障碍结点的影响. 2.ll(),表示的是在运算后把括号内强制转化为类型ll,而(ll)表示后面的每个玩意都强制转化为类型ll. ...

  6. Strange Addition

    http://codeforces.com/problemset/problem/305/A 这题就是意思没看懂,一开始以为只要个位数只要一个为0就能相加,没想到到CF里面提交第三组就过不了,才发现是 ...

  7. 暑假集训——cf热身赛部分题有感加其题解

    刚刚开始集训,集训队队长暂时还没有拉专题,而是拉了部分codeforces上过题人数在2000左右的题组成了一场热身赛(其实就是一场练习),花了一天时间终于把它刷完了,其中很多题让我学到了很多骚操作, ...

  8. uva_644暴力加字典树解法

    暴力 #include<iostream> #include<string.h> #include<cstdio> using namespace std; int ...

  9. codeforces A. Strange Addition 解题报告

    题目链接:http://codeforces.com/problemset/problem/305/A 题目意思:给出一个序列,需要从中选择一些数,这些数需要满足:任意的两个数中每一位至少有一个数满足 ...

随机推荐

  1. WPF 动态更换模板

    Window x:Class="模板选择器.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml ...

  2. kali linux之防火墙识别

    通过检查回包,可能识别端口是否经过防火墙过滤,设备多种多样,结果存在一定的误差 Send Response   Type SYN   NO    Filtered(先发送syn 如果不给回复 防火墙可 ...

  3. ajax标准格式

    jquery向服务器发送一个ajax请求后,可以返回多种类型的数据格式,包括:html,xml,json,text等. $.ajax({    url:"http://www.test.co ...

  4. [原创]用WinRAR实现VC源代码快速压缩创建

    [原创]用WinRAR实现VC源代码快速压缩创建 by edata @ cnblogs.com/edata 2017-5-8 22:31:57 我们有的时候需要对vc项目压缩打包,因为vc项目的无关文 ...

  5. SimpleDateFormat线程不安全及解决办法

    原文链接:https://blog.csdn.net/csdn_ds/article/details/72984646 以前没有注意到SimpleDateFormat线程不安全的问题,写时间工具类,一 ...

  6. linux上的那些查找的命令

    由于工作的需要,少不得要在linux系统上查找各种各样的文件,关于在linux查找的命令有不少,这里小小的总结下. 简单介绍下各个命令的用途: find:实际搜索硬盘查询文件名称: whereis:查 ...

  7. 【BZOJ 2679】[Usaco2012 Open]Balanced Cow Subsets(折半搜索+双指针)

    [Usaco2012 Open]Balanced Cow Subsets 题目描述 给出\(N(1≤N≤20)\)个数\(M(i) (1 <= M(i) <= 100,000,000)\) ...

  8. 搭建svn管理平台

    安装svn服务器:yum -y install subversion 创建svn的目录:mkdir -p /data/svn 初始化svn目录:svnadmin create /data/svn co ...

  9. 红蓝对抗 - 蓝队手册(BTFM)(转载)

    本文已发表在嘶吼RoarTalk,未经授权,请勿转载! http://www.4hou.com/technology/10173.html 最佳阅读体验版:https://stackedit.io/v ...

  10. pyhton学习,day1作业,用户名密码登录模块

    要求,通过用户名密码登录,登录错误3次,锁定用户名 # coding=utf-8 # Author: RyAn Bi import os, sys #调用系统自己的库 accounts_file = ...