题目例如以下:

B. The Child and Set
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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?

Input

The first line contains two integers: sum, limit
(1 ≤ sum, limit ≤ 105).

Output

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.

Sample test(s)
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1

这道题求出二进制的低位(从最先出现1的位置截断),事实上就是位运算。恰好我不熟悉位运算。罪过啊。。

。于是恶补了位运算,求二进制低位用i&-i,求最后以为i&1,左移i<<1,右移i>>1,然后从limit枚举。假设小于sum,就增加答案中.

自己的代码太丑了。粘贴一下别人的美丽的代码:

Codeforces div.2 B. The Child and Set的更多相关文章

  1. 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 ...

  2. 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/ ...

  3. 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/ ...

  4. 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, ...

  5. Codeforces Round #250 (Div. 2)—A. The Child and Homework

         好题啊,被HACK了.曾经做题都是人数越来越多.这次比赛 PASS人数 从2000直掉 1000人  被HACK  1000多人! ! ! ! 没见过的科技啊 1 2 4 8 这组数 被黑的 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Convert Sorted List to Balanced Binary Search Tree leetcode

    题目:将非递减有序的链表转化为平衡二叉查找树! 参考的博客:http://blog.csdn.net/worldwindjp/article/details/39722643 利用递归思想:首先找到链 ...

  2. 在window下搭建即时即用的hyperledger fabric 的环境

    有版本号的严格按要求,遇到不少坑 1)安装git  版本无要求 2)安装go  1.9   配置环境变量 3)安装Vagrant  1.9.4 4)安装VirtualBox  5.1.28 5)在go ...

  3. ImportError: pycurl: libcurl link-time ssl backend (nss) is different

    reference pip uninstall pycurl export PYCURL_SSL_LIBRARY=nss easy_install pycurl

  4. js获取农历

    上一篇我们对upupoo网页壁纸改造时用到了农历,upupoo(网页壁纸)自主修改一:农历,这里记一下笔记: 获取当前农历的js 主js: //农历 var CalendarData=new Arra ...

  5. 洛谷——P3939 数颜色(暴力vecotr+二分)

    P3939 数颜色 $vecotr$里二分就是好用,全是$STL$ 颜色数目比较少,可以对每一种颜色弄一个$vector$记录一下,查找$l,r$内颜色数为$x$的兔子数,直接在$G[x]$这个$ve ...

  6. SSM整合shiro

    采用maven构建项目 1pom.xml中加入shiro依赖 <!-- shiro --> <dependency> <groupId>org.apache.shi ...

  7. PS学习笔记(04)

    Photoshop滤镜的安装 Photoshop滤镜的默认格式为.8bf(也有些滤镜为exe格式的可执行文件),如果你下载的是压缩包,请解压之后再安装. 方法一: 如果你下载的滤镜为exe的可执行文件 ...

  8. 有上下界的网络流 loj115 loj116 loj 117

    参考文章 无源汇有上下界的可行流 有源汇有上下界的最大流 有源汇有上下界的最小流 无源汇有上下界可行流 以 loj115 为例. 剥离出必要边与自由边. #include <iostream&g ...

  9. LoadRunner之并发用户数与迭代关系---并发数与迭代的区别

    Q1: 例如在LR里,我要测100个用户同时并发登陆所用时间,那我是不是在录制好脚本后,需要参数化“用户名”,“密码”以及在那个记事本里构造100个真实的用户名和密码? 然后运行Controller, ...

  10. python004 Python3 解释器

    Python3 解释器Linux/Unix的系统上,一般默认的 python 版本为 2.x,我们可以将 python3.x 安装在 /usr/local/python3 目录中.安装完成后,我们可以 ...