版权声明:本文为博主原创文章,未经博主同意不得转载。

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的更多相关文章

  1. Codeforces #250 (Div. 2) C.The Child and Toy

    之前一直想着建图...遍历 可是推例子都不正确 后来看数据好像看出了点规律 就抱着试一试的心态水了一下 就....过了..... 后来想想我的思路还是对的 先抽象当前仅仅有两个点相连 想要拆分耗费最小 ...

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

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

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

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

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

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

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

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

随机推荐

  1. select 和 order by

    select 的优先级要高于order by,相当于是select先创建了一个临时表,再通过临时表去排序.所以,对于一些sum()的汇总,在进行排序,实际是排序的select后的字段,而不是表里的那个 ...

  2. vs 删除代码中空行

    原文:vs 删除代码中空行 ^\s*\n 正则表达式

  3. db2缓冲池

    CREATE BUFFERPOOL DEMOBP IMMEDIATE  SIZE 250 AUTOMATIC PAGESIZE 4 K ; CREATE BUFFERPOOL DEMOBP IMMED ...

  4. js不加alert后面的代码不工作

    问题:用Ajax从后台拿到了json,append到select的option里面,然后想用for循环来设置某个作为默认值,发现在for循环外面加了个alert()的话,就能实现成功,没有加这个ale ...

  5. 七、OIDC

    在 OAuth 中,这些授权被称为scope. OpenID-Connect也有自己特殊的scope--openid , 它必须在第一次请求“身份鉴别服务器”(Identity Provider,简称 ...

  6. go语言从例子开始之Example21.协程

    Go 协程 在执行上来说是轻量级的线程. golang使用协程用go关键字.后边正常调用函数. Example: package main import "fmt" func ak ...

  7. 在脚本中使用set命令调试脚本

    当脚本文件较长时,可以使用set命令指定调试一段脚本.在脚本中使用set -x命令开启调式模式:使用set +x命令关闭调式模式. 例如: #!/bin/bash #Scriptname: greet ...

  8. 最长上升子序列(LIS)长度及其数量

    例题51Nod-1376,一个经典问题,给出一个序列问该序列的LIS以及LIS的数量. 这里我学习了两种解法,思路和代码都是参考这两位大佬的: https://www.cnblogs.com/reve ...

  9. go(一)基础知识

    一.第一个程序 基本程序结构 package main // 包 import "fmt" // 引入依赖代码 // 功能实现 func main() { fmt.Println( ...

  10. 【JavaWeb项目】一个众筹网站的开发(一)架构搭建

    本项目是@尚硅谷相关视频的记录. 本项目使用Maven构建,工程架构如下图所示: 一.公司的公共父工程和工具类包 1.父工程 每个公司都有自己的父工程 父工程作用:对公司使用的jar包进行统一管理,别 ...