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 题目意思:给出一个序列,需要从中选择一些数,这些数需要满足:任意的两个数中每一位至少有一个数满足 ...
随机推荐
- CentOS 6.9下PXE+Kickstart无人值守安装操作系统
一.简介 1.1 什么是PXE PXE(Pre-boot Execution Environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持 ...
- cf555e
cf555e(缩点) 给一个 n 个点 m 条边的图,以及 q 对点 (s,t),让你给 m 条边定向.问是否存在一种方案,使每对点的 s 能走到 t. \(n,m,q≤ 2×10^5\). 首先,在 ...
- 用shell脚本安装apache
我们首先创建一个文件为test.sh,执行此文件的方法有以下四种方式: 1../test.sh(必须chmod赋予执行权限) 2.. test.sh 3.sourse test.sh 4.[shell ...
- 老男孩Day14作业:堡垒机
一.作业需求: 1.业务需求 兼顾业务安全目标与用户体验,堡垒机部署后,不应使用户访问业务系统的访问变的复杂,否则工作将很难推进,因为没人喜欢改变现状,尤其是改变后生活变得更艰难 保证堡垒机稳 ...
- redis读取自增时候指定的key问题
首先,此文章是接了如下文章写的 Spring boot redis自增编号控制 踩坑 上面这个问题解决后,公司这边功能其实已经实现了,但是考虑到一种情况,因为我们这边号的生成就是根据上面的自增编号来的 ...
- BZOJ4627 权值线段树
4627: [BeiJing2016]回转寿司 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1204 Solved: 475[Submit][St ...
- Query on a tree II 倍增LCA
You are given a tree (an undirected acyclic connected graph) with N nodes, and edges numbered 1, 2, ...
- WinForm 修改App.config不起作用(但是调试没有异常)
修改Bin下的.exe.config文件,就能达到效果了. appconfig的修改,会保留在项目中,似乎不会实时地更改到.exe.config中..
- 洛谷P2800 又上锁妖塔
放题解 题目传送门 放代码
- vim多行注释与删除
一.多行注释 1. 首先按esc进入命令行模式下,按下Ctrl + v,进入列(也叫区块)模式;2. 在行首使用上下键选择需要注释的多行;3. 按下键盘(大写)“I”键,进入插入模式:4. 然后输入注 ...