CF 305A——Strange Addition——————【暴力加技巧】
2 seconds
256 megabytes
standard input
standard output
Unfortunately, Vasya can only sum pairs of integers (a, b), 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?
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).
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.
4
100 10 1 0
4
0 1 10 100
3
2 70 3
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——————【暴力加技巧】的更多相关文章
- zzulioj--1815--easy problem(暴力加技巧)
1815: easy problem Time Limit: 1 Sec Memory Limit: 128 MB Submit: 98 Solved: 48 SubmitStatusWeb Bo ...
- Amr and Chemistry---cf558C(暴力,加技巧)
题目链接:http://codeforces.com/problemset/problem/558/C 题意:有n个数,每个数都可以进行两个操作 *2 或者 /2,求最小的操作次数和,使得所有的数都相 ...
- Solution -「CF 1380F」Strange Addition
\(\mathcal{Description}\) Link. 定义两个数在进行加法时,进位单独作为一位.例如: . 给定一个 \(n\) 为数和 \(m\) 次修改操作,每次修改会修改 ...
- 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 ...
- ACM 大神的经验加技巧(当然不是我的拉——
大神 犯错合集及需要注意的东西 1.在一个地图求最大面积的类问题中,要注意障碍结点的影响. 2.ll(),表示的是在运算后把括号内强制转化为类型ll,而(ll)表示后面的每个玩意都强制转化为类型ll. ...
- Strange Addition
http://codeforces.com/problemset/problem/305/A 这题就是意思没看懂,一开始以为只要个位数只要一个为0就能相加,没想到到CF里面提交第三组就过不了,才发现是 ...
- 暑假集训——cf热身赛部分题有感加其题解
刚刚开始集训,集训队队长暂时还没有拉专题,而是拉了部分codeforces上过题人数在2000左右的题组成了一场热身赛(其实就是一场练习),花了一天时间终于把它刷完了,其中很多题让我学到了很多骚操作, ...
- uva_644暴力加字典树解法
暴力 #include<iostream> #include<string.h> #include<cstdio> using namespace std; int ...
- codeforces A. Strange Addition 解题报告
题目链接:http://codeforces.com/problemset/problem/305/A 题目意思:给出一个序列,需要从中选择一些数,这些数需要满足:任意的两个数中每一位至少有一个数满足 ...
随机推荐
- .NET架构转Java开发必须了解的历史
终于不在职守在.NET领域 .NET的winform和webform项目也开发了很多了 尤其是WEB领域 从ASP -> ASP.NET 2.0 -> ASP.NET MVC 4.0 - ...
- docker--基本命令
仅做学习参考,可能有误 part1:启动docker服务 在Windows上使用MySQL时候,有时无法直接使用MySQL -uroot -p 来进入MySQL,这是因为我们没有启动会MySQL服务此 ...
- 「BZOJ 2434」「NOI 2011」阿狸的打字机「AC自动机」
题意 有一个打字机,支持三种操作: 字符串末尾加一个小写字母 字符串末尾减一个字符 输出这个字符串 经过不超过\(n\)次操作后有\(m\)组询问:\((x,y)\),表示第\(x\)次输出第字符串在 ...
- IO模型《二》阻塞IO
阻塞IO(blocking IO) 在linux中,默认情况下所有的socket都是blocking,一个典型的读操作流程大概是这样: 当用户进程调用了recvfrom这个系统调用,kernel就开始 ...
- Scrapy 增量式爬虫
Scrapy 增量式爬虫 https://blog.csdn.net/mygodit/article/details/83931009 https://blog.csdn.net/mygodit/ar ...
- kali linux之手动漏洞挖掘三(sql注入)
服务器端程序将用户输入作为参数作为查询条件,直接拼写sql语句,并将结果返回给客户端浏览器 如判断登录 select * from users where user='uname' and passw ...
- 网站Seo纲领
1:准备工作和内容来源 2:域名注册 3:网站设计越简单越好 4:内容长度 5:四处一词 6:站内定向锚文本 7:内容编辑标准 8:外链建设 9:日志分析能力 10:更新频率和高质量的内容 1:准备工 ...
- ubuntu下的pycharm4中文路径乱码
修改字体: 设置(settings)->外观与行为(appearance & behavior) -> 外观(appearance) ->我选择的主题是Darcula 但其字 ...
- Opencv博文收藏列表
opencv识别二维码:https://blog.csdn.net/jia20003/article/details/77348170 opencv视频:http://www.opencv.org.c ...
- Android 连接服务器,并进行相关操作
1.连接服务器 (1)直接使用WINDOWS自带的远程桌面连接 win+R调出DOS操作窗口,输入mstsc.exe 点击确定,进入如下界面: 点击连接,输入用户名和密码登录,电脑会进入服务器界面.