cf 305A
2015-01-12 11:14
316 查看
E - Strange Addition
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 305A
Appoint description:
System Crawler (2015-01-10)
Description
Unfortunately, Vasya can only sum pairs of integers (a, b), 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 Input
Input
Output
Input
Output
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 305A
Appoint description:
System Crawler (2015-01-10)
Description
Unfortunately, Vasya can only sum pairs of integers (a, b), 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 Input
Input
4 100 10 1 0
Output
4 0 1 10 100
Input
3 2 70 3
Output
2 2 70
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<algorithm> #include<queue> #include<vector> #include<set> using namespace std; int k,a[110],b[110],t,j; int main() { scanf("%d",&k); for(int i=0;i<k;i++) scanf("%d",&a[i]); sort(a,a+k); int n=1; b[0]=a[0]; for(int i=1;i<k;i++) { int x=a[i]%10; t=a[i]/10; int y=t%10; t=t/10; int z=t; for(j=0;j<n;j++) { int x1=b[j]%10; t=b[j]/10; int y1=t%10; t=t/10; int z1=t; if((x==0||x1==0)&&(y==0||y1==0)&&(z==0||z1==0)) { continue; } else { break; } } if(j==n) { b[n++]=a[i]; } } printf("%d\n",n); printf("%d",b[0]); for(int i=1;i<n;i++) printf(" %d",b[i]); printf("\n"); return 0; }
相关文章推荐
- CF 305A(Strange Addition-贪心+分类讨论)
- CF 305A(Strange Addition-贪心+分类讨论)
- CF305A
- CF 305A——Strange Addition——————【暴力加技巧】
- CF 600D(Area of Two Circles' Intersection-2圆面积并)
- cf Guess a number!
- CF 603B 数学,同余
- CF# Educational Codeforces Round 3 E. Minimum spanning tree for each edge
- CF Good Bye 2015 A- New Year and Days(CF611A)
- CF-edu#5 E - Sum of Remainders -数学-枚举
- cf 620C Pearls in a Row(贪心)
- cf#Wunder Fund Round 2016 -A - Slime Combining-简单数学
- cf#AIM Tech Round -B. Making a String-贪心/set
- CF 602C The Two Routes(dij+邻接矩阵)
- CF 559E
- CF #633A(暴力枚举)
- CF 615 B Longtail Hedgehog(dfs/dp)
- CF 345 div2 D题
- CF 598A Tricky Sum【规律】
- CF_1B_Spreadsheets 进制转换