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 ...
随机推荐
- Mac 下用homebrew安装配置MongoDB
---恢复内容开始--- 1.首先安装homebrew,已有就跳过 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent. ...
- 【简●解】[USACO] 照片Photo
[简●解][USACO] 照片Photo [题目大意] 在\(1\)~\(N\)的序列上有\(M\)个区间,使得这\(M\)个小区间每个覆盖了且仅覆盖了一个点,求最多点数,如果无解,输出\(-1\). ...
- UVa-340-猜数字
#include <stdio.h> char ans[1000],gus[1000]; int num[10]; int main() { int n,cnt=1; while (sca ...
- set()集合基本操作
运用频次:☆☆ set是一个无序且不重复元素集,基本操作如下: 1. 创建set集合,会自动转换成set类型 2. add():添加元素 def add(self, *args, **kwargs): ...
- ubuntu安装远程桌面连接工具
1. 安装xrdp sudo apt-get -y install xrdp 2.安装vnc4server sudo apt-get install vnc4server 3.安装xubunt ...
- Nginx与python web服务配置(Uwsgi& FastCGI)
Uwsgi start uswgi uwsgi --harakiri 360000 --body-read-warning=10000 --max-fd=65536 -b 1000000 --http ...
- 大数据学习——mapreduce学习topN问题
求每一个订单中成交金额最大的那一笔 top1 数据 Order_0000001,Pdt_01,222.8 Order_0000001,Pdt_05,25.8 Order_0000002,Pdt_05 ...
- 大数据学习——hadoop集群搭建2.X
1.准备Linux环境 1.0先将虚拟机的网络模式选为NAT 1.1修改主机名 vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=itcast ### ...
- 省市区名称code
https://blog.csdn.net/hichinamobile/article/details/51725090 --省 create table t_base_provinces( id ) ...
- Python+selenium常用方法(Webdriver API)
小编整理了目前学习的Python+selenium常用的一些方法函数,以后有新增再随时更新. 加载浏览器驱动: webdriver.Firefox() 打开页面:get() 关闭浏览器:quit() ...