Codeforces #250 (Div. 2) B. The Child and Set
版权声明:本文为博主原创文章,未经博主同意不得转载。
https://blog.csdn.net/u011639256/article/details/28100041
题读错了啊。。。
一直跪,但刚開始我的思路是正确的
假设做出来了rating一定会暴涨的
我的方法是找出1到100000全部数相应的lowbit()值
再暴力,可惜题读错了,lowbit的意思是找出该数二进制数从右向左1出现的最早位置相应的数值
代码例如以下:
#include <cmath>
#include <stack>
#include <cstdio>
#include <iostream>
#include <algorithm>
#define MAXN 100010
#define ll long long
using namespace std;
int a[] = {1, 2, 4, 8, 16, 32, 64, 128,
256, 512, 1024, 2048, 4096, 8192,
16384, 32768, 65536, 131072};
int b[MAXN];
int c[MAXN];
ll sum[MAXN];
void f(void) {
sum[0] = 0;
for(int i=1; i<MAXN; ++i) {
for(int j=0; j<18; ++j) {
if(i & a[j]) {
b[i] = a[j];
break;
}
}
sum[i] = sum[i-1]+b[i];
}
return ;
}
int main(void) {
ll s, k;
int tmp;
f();
while(cin >> s >> k) {
int cnt = 0;
if(s > sum[k]) {
printf("-1\n");
continue;
}
for(int i=k; i>0; --i) {
if(s-b[i] > 0) {
s -= b[i];
c[cnt++] = i;
}
else if(s-b[i] == 0) {
c[cnt++] = i;
break;
}
}
printf("%d\n", cnt);
printf("%d", c[0]);
for(int i=1; i<cnt; ++i)
printf(" %d", c[i]);
cout << endl;
}
return 0;
}
Codeforces #250 (Div. 2) B. The Child and Set的更多相关文章
- Codeforces #250 (Div. 2) C.The Child and Toy
之前一直想着建图...遍历 可是推例子都不正确 后来看数据好像看出了点规律 就抱着试一试的心态水了一下 就....过了..... 后来想想我的思路还是对的 先抽象当前仅仅有两个点相连 想要拆分耗费最小 ...
- 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 ...
随机推荐
- 使用vue配合组件--转载
1.由饿了么 UED (知乎专栏)设计的桌面端组件库已经开源,文档:Element,仓库: GitHub - ElemeFE/element: Desktop UI elements for Vue. ...
- python学习第四天-函数
函数 def开头 函数参数 其中name.age.sex为形参,'王锦时',21,'男'为实参 函数返回值 默认参数 关键字参数 收集参数 相当于把所有实参存在一个元组当中 收集参数和关键字参数的混 ...
- HDU 4366 Successor( DFS序+ 线段树 )
Successor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- java虚拟机规范(se8)——java虚拟机的编译(三)
3.6 接受参数 如果n个参数传给一个实例的方法,按照约定,它们被接受并放在这个新方法创建的栈帧中的局部变量表里,在局部变量表中的序号从1到n.这些参数按照它们传递过来的顺序存放.例如: int ad ...
- 解决MVC中textarea出现多余空格的问题
public static MvcHtmlString FixedTextAreaFor<TModel, TProperty>(this HtmlHelper<TModel> ...
- Java模拟HttpClient进行Get和Post提交
使用Java模拟客户端进行提交,需要用到apache http client jar,这里用的是4.4版本 GET: public void GetURL(){ String strResp=&qu ...
- 2018-2-13-关于Host(主机)
title author date CreateTime categories 关于Host(主机) lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23:3 ...
- linux-tomcat-install
1.解压: tar zxvf xxx.tar.gz 配置JDK的环境变量,在etc/profile文件中添加 2.修改Tomcat启动端口 cd tomcat/conf/server.xml中的con ...
- 【虚拟机】:"该虚拟机似乎正在使用中。 如果该虚拟机未在使用,请按“获取所有权(T)”按钮获取它的所有权。否则,请按“取消(C)”按钮以防损坏。"
1.可能是由于上次使用虚拟机,没有正常关闭出现了这种情况,于是把问题复制粘贴搜了一下. 2.出现了如下可行的解决方法:把后缀名为.vmdk.lck的都删除掉. 3.然后再打开虚拟机就可以了.
- jenkins发送邮箱配置,出现Error sending to the following VALID addresses,解决方案
Jenkins发送邮箱配置,需要的插件:Extended E-mail Notification,邮件通知 1.Manage Jenkins -> Configure System 2.下图是“ ...