博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
A. Strange Addition 暴力
阅读量:5051 次
发布时间:2019-06-12

本文共 2774 字,大约阅读时间需要 9 分钟。

 
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

 答案最多4个最少1个

 

 

const int maxn = 30000;

int d[maxn];
int vis[4];
bool ok()
{
repf(i,0,2)
if(vis[i]) return false;
return true;
}
int main()
{
//freopen("in.txt","r",stdin);
int n;
while(cin>>n)
{
int ans = 0;
repf(i,1,n)
{
scanf("%d",&d[i]);
if(n>1 && d[i] == 0) ans++;
}
if(n == 1)
{
cout<<1<<endl;
cout<<d[1]<<endl;
continue;
}
int a = -1;
int b = -1;
int c = -1;
int tag = 0;
repf(i,1,n)
{
repf(j,i+1,n)
{
repf(k,0,2) vis[k] = 1;
if(d[i] == 0 || d[j] == 0) continue;
int t = 3;
int tt = d[i];
while(t > 0)
{
int tmp = tt%10;
tt/=10;
if(tmp == 0)
vis[t - 1] = 0;
t--;
}
tt = d[j];
t = 3;
while(t > 0)
{
int tmp = tt%10;
tt/=10;
if(tmp == 0)
vis[t - 1] = 0;
t--;
}
if(ok())
{
a = d[i];
b = d[j];
tag = 1;
}
}
}
if(tag == 0)
{
if(ans)
{
cout<<2<<endl;
int kk;
repf(i,1,n)
if(d[i] != 0)
kk = d[i];
cout<<0<<" "<<kk<<endl;
}else
{
cout<<1<<endl;
cout<<d[1]<<endl;
}
}else
{
int flag = 0;
//clr(vis)
repf(i,1,n)
repf(j,i+1,n)
repf(k,j+1,n)
{
if(d[i] == 0 || d[j] == 0 || d[k] == 0) continue;
int t = 3;
int tt = d[i];
clr(vis);
while(t > 0)
{
int tmp = tt%10;
tt/=10;
if(tmp)
{
vis[t - 1]++;
}
t--;
}
t = 3;
tt = d[j];
while(t > 0)
{
int tmp = tt%10;
tt/=10;
if(tmp)
vis[t - 1]++;
t--;
}
t = 3;
tt = d[k];
while(t > 0)
{
int tmp = tt%10;
tt/=10;
if(tmp)
vis[t - 1]++;
t--;
}
if(vis[0] == 1&& vis[1] == 1 && vis[2] == 1)
{
a = d[i];
b = d[j];
c = d[k];
flag = 1;
}
}
if(flag)
{
if(ans)
{
cout<<4<<endl;
printf("%d %d %d %d\n",0,a,b,c);
}else
{
cout<<3<<endl;
printf("%d %d %d\n",a,b,c);
}
}else
{
if(ans)
{
cout<<3<<endl;
printf("%d %d %d\n",0,a,b);
}else
{
cout<<2<<endl;
printf("%d %d\n",a,b);
}
}
}
}
return 0;
}

转载于:https://www.cnblogs.com/DreamHighWithMe/p/3441876.html

你可能感兴趣的文章
输入名字显示其生日,没有则让输入生日,做记录
查看>>
Kubernetes 运维学习笔记
查看>>
并查集 经典 畅通工程
查看>>
Spark MLlib 之 Naive Bayes
查看>>
php修改SESSION的有效生存时间
查看>>
spring security 11种过滤器介绍
查看>>
Hibernate一对多、多对一关联
查看>>
一、记录Git使用中遇到的问题及解决方法
查看>>
学习网址
查看>>
前端表格插件datatables
查看>>
内部类
查看>>
树链剖分入门
查看>>
图解算法时间复杂度
查看>>
UI_搭建MVC
查看>>
一个样例看清楚JQuery子元素选择器children()和find()的差别
查看>>
代码实现导航栏分割线
查看>>
Windows Phone开发(7):当好总舵主 转:http://blog.csdn.net/tcjiaan/article/details/7281421...
查看>>
VS 2010打开设计器出现错误
查看>>
SQLServer 镜像功能完全实现
查看>>
Vue-详解设置路由导航的两种方法
查看>>