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 题目意思:给出一个序列,需要从中选择一些数,这些数需要满足:任意的两个数中每一位至少有一个数满足 ...
随机推荐
- ubuntu14.10,解决按照最新版Gnome 15.10后,经典Gnome桌面字体问题!
ubuntu14.10刚安装完毕,我首先按照了经典Gnome桌面,随后我发现ubuntu软件中心里面能找到的软件明显不如先前我安装过的ubuntu了,我觉得有可能是因为我以前安装的ubuntu14.1 ...
- 「BZOJ 2809」「APIO 2012」Dispatching「启发式合并」
题意 给定一个\(1\)为根的树,每个点有\(c,w\)两个属性,你需要从某个点\(u\)子树里选择\(k\)个点,满足选出来的点\(\sum_{i=1}^k w(i)\leq m\),最大化\(k\ ...
- Mybatis中的连接池
Mybatis中DataSource的存取 MyBatis是通过工厂模式来创建数据源DataSource对象的,MyBatis定义了抽象的工厂接口:org.apache.ibatis.datasour ...
- 20165219 2017-2018-2 《Java程序设计》第8周学习总结
20165219 2017-2018-2 <Java程序设计>第8周学习总结 教材学习内容总结 进程与线程 线程是比进程更小的单位:线程间可以共享进程中的某些内存单元 java的多线机制 ...
- .NET clickonce修改发布名称等
见图
- loj #2508. 「AHOI / HNOI2018」游戏
#2508. 「AHOI / HNOI2018」游戏 题目描述 一次小 G 和小 H 在玩寻宝游戏,有 nnn 个房间排成一列,编号为 1,2,…,n,相邻房间之间都有 111 道门.其中一部分门上有 ...
- 第八届山东ACM省赛F题-quadratic equation
这个题困扰了我长达1年多,终于在今天下午用两个小时理清楚啦 要注意的有以下几点: 1.a=b=c=0时 因为x有无穷种答案,所以不对 2.注意精度问题 3.b^2-4ac<0时也算对 Probl ...
- 【ExecutorService】概述
初试 今天做一个上传excel,后台异步导入数据功能,使用ExecutorService private final ExecutorService m_longPollingService; pub ...
- Nagios监控平台搭建及配置文件详解
Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员, ...
- _.each _.map _.filter javascript 语法
1.forEach():没有返回值,只是针对每个元素调用func 简单来说,就是将数组中的每个值,依次进行遍历,执行功能函数 如果只需对数组元素进行操作,不需返回任何值时适用 var ...