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

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. 在php中定义常量时,const和define的区别?

    使用const使得代码简单易读,const本身就是一个语言结构,而define是一个函数.另外const在编译时要比define快很多. 1.const用于类成员变量的定义,一经定义,不可修改.Def ...

  2. 安装Consul服务中心

    安装Consul服务中心 首先下载对应版本的安装程序.点击下载 我下载的是macOS64位版本,下载文件是一个ZIP文件,下载后解压缩到一个你喜欢的位置,以开发模式启动consul服务: #进入con ...

  3. Oracle学习笔记<4>

    多表查询 1.什么是多表查询? 一次select语句需要查询的内容来自于不止一张表. 同时从多张表中查询数据. 单表查询: select id,last_name,salary from s_emp ...

  4. CSS3 3D旋转下拉菜单--兼容性不太好

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  5. PHP include 与 require 区别

    include 与 require 语句同样用于向 PHP 代码中引用文件. include 与 require 有一个巨大的差异:  include 语句引用某个文件并且 PHP 无法找到它,脚本会 ...

  6. JQ的live学习

    $("#StartTime").live("blur keypress keyup",function(){ if($("#EndTime" ...

  7. 十万级百万级数据量的Excel文件导入并写入数据库

    一.需求分析 最近接到一个需求,导入十万级,甚至可能百万数据量的记录了车辆黑名单的Excel文件,借此机会分析下编码过程; 首先将这个需求拆解,发现有三个比较复杂的问题: 问题一:Excel文件导入后 ...

  8. Redis的备份与恢复

    备份 dump.rdb:RDB方式的备份文件 appendonly.aof:AOF方式的备份文件 rdb 备份处理 # 编辑redis.conf文件,找到如下参数,默认开启. save 900 1 s ...

  9. 西里尔字 俄语 - Cyrillic

    https://zh.wikipedia.org/wiki/%E8%A5%BF%E9%87%8C%E5%B0%94%E5%AD%97%E6%AF%8D 其他编码[编辑] 其他适用西里尔字母的字符编码系 ...

  10. 低门槛彻底理解JavaScript中的深拷贝和浅拷贝

    作者 | 吴胜斌 来源 | https://www.simbawu.com/article/search/9 在说深拷贝与浅拷贝前,我们先看两个简单的案例: //案例1var num1 = 1, nu ...