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 题目意思:给出一个序列,需要从中选择一些数,这些数需要满足:任意的两个数中每一位至少有一个数满足 ...
随机推荐
- angular 父组件调用子组件
import { Component, OnInit, ViewChild } from '@angular/core'; @Component({ selector: 'app-child', te ...
- 多态的作用-游戏编程展示------新标准c++程序设计
游戏软件的开发最能体现面向对象设计方法的优势.游戏中的人物.道具.建筑物.场景等都是很直观的对象,游戏运行的过程就是这些对象相互作用的过程.每个对象都有自己的属性和方法,不同对象也可能有共同的属性和方 ...
- JAVA格式化当前日期或者取年月日
Date d = new Date(); System.out.println(d); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M ...
- dubbo服务治理中间件,zookeeper注册中心 安装配置
对传统项目架构进行拆分: 集群概念: 面向服务分布式架构: 服务层提供被注册的对象需要实现序列化接口Serializable: 配置表现层和服务层: 依赖包: 服务层: <!-- 定义dubbo ...
- c++11时间相关库(chrono)
以下整理自:https://www.2cto.com/kf/201404/290706.html chrono 库主要包含了三种类型:时间间隔 Duration.时钟 Clocks 和时间点 Time ...
- [hadoop] map函数中使用FileSystem对象出现java.lang.NullPointerException的原因及解决办法
问题描述: 在hadoop中处理多个文件,其中每个文件一个map. 我使用的方法为生成一个文件,文件中包含所有要压缩的文件在HDFS上的完整路径.每个map 任务获得一个路径名作为输入. 在eclip ...
- 获取一个表中的字段总数(mysql) Navicat如何导出Excel格式表结构 获取某个库中的一个表中的所有字段和数据类型
如何获取一个表中的字段总数 1.function show columns from 表明: 结果 : 2.functiuon select count(*) from INFORMATION_SCH ...
- [Beta阶段]第一次Scrum Meeting
Scrum Meeting博客目录 [Beta阶段]第一次Scrum Meeting 基本信息 名称 时间 地点 时长 第一次Scrum Meeting 19/04/29 大运村寝室6楼 70min ...
- angular-ui-select (系列二)远程搜索,页面方框显示的值跟传给后台的值不一样解决方案
三:下拉单选远程搜索: 一个重点是: 这个方法,就是让我们去远程搜索的 refresh="ctrl.refreshAddresses($select.search)" refres ...
- php 缓冲函数
php.ini中有两个关键参数会影响到php的缓存输出控制: output_buffering :on/off 或者整数 .设置为 on 时,将在所有脚本中使用输出缓存控制,不限制缓存的大小.而设置为 ...