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

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. Logstash配置文件详情

    logstash 配置文件编写详解 说明 它一个有jruby语言编写的运行在java虚拟机上的具有收集分析转发数据流功能的工具能集中处理各种类型的数据能标准化不通模式和格式的数据能快速的扩展自定义日志 ...

  2. asp.net core 使用中间件拦截请求和返回数据,并对数据进行加密解密。

    原文:asp.net core 使用中间件拦截请求和返回数据,并对数据进行加密解密. GitHub demo https://github.com/zhanglilong23/Asp.NetCore. ...

  3. NULL合并操作符??

    参考官方手册: /** * NULL合并操作符 ?? */ // $a, $b, $c都未声明和定义 var_dump($a??$b??$c); // NULL // $a为数组,$b为100,$c为 ...

  4. .net Core AJAX使用Header传递参数,以JsonResult返回信息

    function postHeader() { $.ajax({ url : "/myTest/PostHeader?time="+ (new date()).getTime(), ...

  5. Centos6安装mysql5.7最新版

    最近因为公司的服务器需要做基线和漏洞扫描,基线方面问题不大,按照报告上的加固建议,选一些权重高的问题处理一下就好了.但是漏洞扫描就比较坑了,扫出来了十几个高危和一百六十多个中危漏洞,不过还好漏洞基本上 ...

  6. Apache+tomcat 动静分离

    环境准备: Centos7 需要软件 jdk-8u45-linux-x64.tar.gz apache-tomcat-.tar.gz apr-.tar.gz apr-util-.tar.gz pcre ...

  7. oracle10G锁查询、批量杀锁及常用sql

    前言 记录1.oracle10G锁查杀技巧 2.资源检查方面的sql 锁查杀 找出所有被锁的对象.注意:不一定是死锁,大部分应该是阻塞,如果发现大量的锁对象,一定要检查程序逻辑了,优化sql sele ...

  8. 深度解析双十一背后的阿里云 Redis 服务

    摘要: Redis是一个使用范围很广的NOSQL数据库,阿里云Redis同时在公有云和阿里集团内部进行服务,本文介绍了阿里云Redis双11的一些业务场景:微淘社区之亿级关系链存储.天猫直播之评论商品 ...

  9. spring在WEB中的应用。

    1:创建IOC容器.在WEB应用程序启动的时候就创建.利用到监听器. ServletContextListener类的contextInitialized方法中 package com.struts2 ...

  10. 膜神犇 DPH

    神犇 DPH 让我写博客.但是,似乎我已经开始写了?!! I am young and naïve!!! Let us orz DPH! 上节课讲DFS,这个是我最擅长的.“暴力出奇迹”!