题目例如以下:

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. 请简述HTML和XHTML最重要的4点不同?

    请简述HTML和XHTML最重要的4点不同? 不同: XHTML要求正确嵌套                   XHTML 所有元素必须关闭                   XHTML 区分大小 ...

  2. vs2010的资源视图中,对话框显示数字的解决方法之一

    以上是不正常显示. 我这次遇到该问题的原因是资源名IDD_DLG_INTENSITY重复定义导致的, 所以在resource.h文件中去除重复定义就好了. 正常应该显示DD_XXX,如下图所示

  3. AspNetCore容器化(Docker)部署(二) —— 多容器通信

    一.前言 着上一篇 AspNetCore容器化(Docker)部署(一) —— 入门,在单个容器helloworld的基础上引入nginx反向代理服务器组成多容器应用. 二.配置反向代理转接 配置转接 ...

  4. select onchange事件的使用

    <select name="expireDay" id="expireDay" class="form-control" onchan ...

  5. 22. SCHEMA_PRIVILEGES

    22. SCHEMA_PRIVILEGES SCHEMA_PRIVILEGES表提供有关schema(数据库)特权的信息.它从mysql.db系统表中获取其值. SCHEMA_PRIVILEGES表有 ...

  6. 9. InnoDB通用表空间

    9. InnoDB通用表空间 通用表空间是InnoDB 使用CREATE TABLESPACE语法创建的共享表空间.本节中的以下主题描述了常规表空间功能和功能: 通用表空间功能 创建通用表空间 将表添 ...

  7. 【java面试宝典】一年工作经验者适用

    时光转瞬即逝,一年时间已经过去,自己准备跳槽了,请了几天假,面试了几家公司之后,拿到了一份offer,有了一点儿小小的心得,记录下来分享给搞Java的朋友,面试主要是几个部分内容. 很多公司会要求笔试 ...

  8. mysql 建表规范

    常用字段 CREATE TABLE `che`.`<table_name>` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '索引id', ...

  9. configparser ,subprocess , xlrd ,xlwt 模块

    一,configparser模块 ''' configparser模块: 是什么: 用于解析配置文件的模块 配置文件的定义: 用于编写保存某个软件或某个系统的一系列参数的文件 设置参数 为什么需要配置 ...

  10. 一道在CF上WA了9次才AC的A题题目与10个版本的代码代码

    题目(题目链接:https://codeforces.com/problemset/problem/733/A):   A. Grasshopper And the String time limit ...