Codeforces div.2 B. The Child and Set
题目例如以下:
1 second
256 megabytes
standard input
standard output
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
- its elements were distinct integers from 1 to
limit; - the value of was equal to
sum; here lowbit(x) equals
2k where
k is the position of the first one in the binary representation of
x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002
(binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
The first line contains two integers: sum, limit
(1 ≤ sum, limit ≤ 105).
In the first line print an integer n
(1 ≤ n ≤ 105), denoting the size of
S. Then print the elements of set
S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print
-1.
5 5
2
4 5
4 3
3
2 3 1
5 1
-1
这道题求出二进制的低位(从最先出现1的位置截断),事实上就是位运算。恰好我不熟悉位运算。罪过啊。。
。于是恶补了位运算,求二进制低位用i&-i,求最后以为i&1,左移i<<1,右移i>>1,然后从limit枚举。假设小于sum,就增加答案中.
自己的代码太丑了。粘贴一下别人的美丽的代码:
Codeforces div.2 B. The Child and Set的更多相关文章
- Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸
D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #250 (Div. 1) B. The Child and Zoo 并查集
B. The Child and Zoo Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...
- Codeforces Round #250 (Div. 1) A. The Child and Toy 水题
A. The Child and Toy Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)
题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...
- Codeforces Round #250 (Div. 2)—A. The Child and Homework
好题啊,被HACK了.曾经做题都是人数越来越多.这次比赛 PASS人数 从2000直掉 1000人 被HACK 1000多人! ! ! ! 没见过的科技啊 1 2 4 8 这组数 被黑的 ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence(线段树)
D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence
D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #250 (Div. 2) D. The Child and Zoo 并查集
D. The Child and Zoo time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #250 (Div. 2)B. The Child and Set 暴力
B. The Child and Set At the children's day, the child came to Picks's house, and messed his house ...
随机推荐
- python基础一 day6 序列操作集合
列表删除:pop([index])有返回值 remove('元素‘)没有返回值 按元素删,元素是什么,就写什么,是数字就写数字,不要加引号,加引号就变成字符串了,没有就报错. 字典删除:pop( ’键 ...
- 数位DP || Gym 101653R Ramp Number
每一位都大于等于前一位的数叫Ramp Number 给一个数,如果不是Ramp Number输出-1,如果是Ramp Number输出比它小的Ramp Number的个数 只和每一位上的数字有关 #i ...
- 尺取法 || POJ 2739 Sum of Consecutive Prime Numbers
给一个数 写成连续质数的和的形式,能写出多少种 *解法:先筛质数 然后尺取法 **尺取法:固定区间左.右端点为0,如果区间和比目标值大则右移左端点,比目标值小则右移右端点 ...
- 找回Settings Sync的gist id和token
方法一:如果你本地有缓存参考:https://www.cnblogs.com/zhang1028/p/9514471.html 方法二:如果你电脑重装系统了 1.找回gist id 登陆你的githu ...
- npm的替代品
npm安装依赖包太慢,cnpm也快不到哪里去,偶然发现了yarn,特快特好用! 安装yarn:npm install -g yarn 查看版本号:yarn -v 安装依赖项:yarn install
- Mysql数据库事件使用与示例
1 事件简介 事件(event)是MySQL在相应的时刻调用的过程式数据库对象.一个事件可调用一次,也可周期性的启动,它由一个特定的线程来管理的,也就是所谓的“事件调度器”. 事件和触发器类似,都是在 ...
- phpstorm的全局操作快捷键ctrl+shift+f被搜狗占用处理方法
1.找到搜狗软件,右键选择属性设置 2.如图选择系统功能快捷键 3.去掉简繁切换快捷方式,确定后即可使用phpstorm的ctrl+shift+f来进行全局查找
- linux 05
日期与时间命令:date.日历的命令:cal.计算器:bc 要使用quit退出 在命令行模式里执行命令时,会有两种主要情况: 一种是该命令会直接显示结果然后回到命令提示符等待下一个命令的输入 dat ...
- 【EL&JSTL】学习笔记
一.EL表达式(形式:${ }) 1. 1 EL运算符 算术运算符: +.-.*./.% 示例 结果 ${1+1} 2 ${1-1} 0 ${1*3} 3 ${3/2} 1.5 ${5%3} 2 关系 ...
- vue 单独页面定时器 离开页面销毁定时器
data: { return { timer: null } }, created() { this.timer = setInterval(....); }, beforeDestroy() { i ...