题目例如以下:

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. JavaScript/JQuery radioButton(单选按钮)练习20190409

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. python3查询Excel中A表在B表没有的数据,并保存到新的Excel,这里用的是“xlrd”和“xlwt”

    import xlrd import xlwt # 打开A表,将A表的数据存放到cols1中,这里打印出来是方便查看测试数据. data1 = xlrd.open_workbook(r'F:\cars ...

  3. Redis进阶例子

    工作中用到的RabbitMQ例子 , 但是最后没有用 , 用的CMQ , 顺便说下CMQ社区真的少 , 并且功能少 . 一.消息体 package com.bootdo.common.rabbitmq ...

  4. 万能的搜索--之BFS(三)

    接着(一)start (二)广度优先搜索(BFS) 广度优先搜索(又称宽度优先搜索算法)是最简便的图的搜索算法之一,这一算法也是很多重要的图的算法的原型.   Dijkstra单源最短路径算法和Pri ...

  5. Android 图片设置圆角 方法之二

    Android中经常会遇到对图片进行二次处理,例如加圆角,或者显示圆形图片.接下来我们再介绍一种方法. 首先, 自定义ImageView: android:id="@+id/iv" ...

  6. 《算法导论》— Chapter 11 散列表

    1 序 在很多应用中,都要用到一种动态集合结构,它仅支持INSERT.SEARCH以及DELETE三种字典操作.例如计算机程序设计语言的编译程序需要维护一个符号表,其中元素的关键字为任意字符串,与语言 ...

  7. Centos 虚拟机 和宿主机 文件共享

    我虚拟机下安装的是一个命令行式的centos ,想要把虚拟机里面的源文件移到宿主机上.于是我就想着搞一个文件共享. 网上有很多办法,比如Samba .ftp之类的.我选择了vmware自带的文件共享功 ...

  8. Flask--修改默认的static文件夹的方法

    修改的flask默认的static文件夹只需要在创建Flask实例的时候,把static_folder和static_url_path参数设置为空字符串即可. app = Flask(__name__ ...

  9. springboot注释详解

    1.属性注入 @ConfigurationProperties(prefix="...") spring会从classpath下的/config目录或者classpath的根目录查 ...

  10. Python的另一种开发环境--Anaconda中的Spyder

    本文作者LucyGill,转载请注明出处(虽然我觉得并不会有人转载). 刚开始学Python的时候,我用的是其自带的idle(安装Python后,在开始菜单里可以找到),后来发现在eclipse中设置 ...