codeforces-305A Strange Addition(思维+模拟)

拼搏现实的明天。 2022-06-10 09:22 292阅读 0赞

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 (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, …, d**k.

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, …, d**k (0 ≤ d**i ≤ 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.

Examples

input

  1. 4
  2. 100 10 1 0

output

  1. 4
  2. 0 1 10 100

input

  1. 3
  2. 2 70 3

output

  1. 2
  2. 2 70

题解:

题意:

给你一堆数字,范围0-100,问最多能有几个数按照要求可以组合在一起,任意输出几个就行,要求如下:比如第一个样例的0可以看成000,1看成001,10看成010,这些随意组合都可以使得3位中每一位至少有一个0,又比如50和25就不行,因为50就是050,25就是025,他们的个位没有0,不能组合

思路:

很容易分析出0-100间这样的数最多有4个,0符合,100符合,然后两个可以是一个个位数和一个能被10整除的两位数,或者如果给的数字中没有个位,就可以拿一个任意的两位数,还有就是如果输出了一个不能被10整除的两位数的话,就不能再输出两位数和一位数了(想想),就是这种思路,如果觉得绕就仔细想想

代码:

  1. #include<algorithm>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<stdio.h>
  5. #include<math.h>
  6. #include<string>
  7. #include<stdio.h>
  8. #include<queue>
  9. #include<stack>
  10. #include<map>
  11. #include<vector>
  12. #include<deque>
  13. using namespace std;
  14. #define lson k*2
  15. #define rson k*2+1
  16. #define M (t[k].l+t[k].r)/2
  17. #define INF 1008611111
  18. int a[10];//存要输出的数字
  19. int vis[105];//看0-100间出现的情况
  20. int main()
  21. {
  22. int i,j,n,x,num=0,tag1=0,tag2=0;
  23. scanf("%d",&n);
  24. memset(vis,0,sizeof(vis));
  25. for(i=0;i<n;i++)
  26. {
  27. scanf("%d",&x);
  28. vis[x]=1;
  29. }
  30. if(vis[0])//如果0出现了直接加0
  31. {
  32. a[num]=0;
  33. num++;
  34. }
  35. if(vis[100])//100出现了直接加100
  36. {
  37. a[num]=100;
  38. num++;
  39. }
  40. for(i=1;i<=9;i++)//如果出现个位直接加上
  41. {
  42. if(vis[i])
  43. {
  44. a[num]=i;
  45. num++;
  46. tag1=1;//打上一个tag1,不能和不能被10整除的两位数同时出现
  47. break;
  48. }
  49. }
  50. for(i=1;i<=9;i++)//如果能被10整除的两位出现了直接加上一个
  51. {
  52. if(vis[i*10])
  53. {
  54. a[num]=i*10;
  55. tag2=1;//要打一个tag2,防止两位的不能整除的数和该数同时出现
  56. num++;
  57. break;
  58. }
  59. }
  60. if(!tag1&&!tag2)//如果没有以上两种情况才可以找一个不能被10整除的两位数
  61. {
  62. for(i=11;i<=99;i++)
  63. {
  64. if(i%10==0)
  65. continue;
  66. if(vis[i])
  67. {
  68. a[num]=i;
  69. num++;
  70. break;
  71. }
  72. }
  73. }
  74. printf("%d\n",num);
  75. printf("%d",a[0]);
  76. for(i=1;i<num;i++)
  77. printf(" %d",a[i]);
  78. printf("\n");
  79. return 0;
  80. }

发表评论

表情:
评论列表 (有 0 条评论,292人围观)

还没有评论,来说两句吧...

相关阅读