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 ...
随机推荐
- Python快速设置Excel表格边框
import xlwings as xw #打开存好的excel app = xw.App() #设置应用 wb = xw.Book("E:/Data/小蜜蜂超市销售报表.xlsx" ...
- Java中synchronized 修饰在static方法和非static方法的区别
[问题描述]关于Java中synchronized 用在实例方法和对象方法上面的区别 [问题分析]大家都知道,在Java中,synchronized 是用来表示同步的,我们可以synchronized ...
- 安装软件 学习linux命令
nm -D /usr/lib64/libstdc++.so.6 | grep GLIBCnm dumps named symbols, -D for dynamic libs, and grep fo ...
- Web前端基础学习-2
盒子模型 在页面中,我们将所有的元素全部看做是一个盒子,页面布局就是将大大小小不同的盒子堆砌在一起,而一个盒子由以下几部分组成: padding:内边距,内容到边框的距离: margin:外边距,其他 ...
- 绘图matplotlib
前言 matplotlib是python的一个绘图库,如果你没有绘制过图,可以先试试js的绘图库http://www.runoob.com/highcharts/highcharts-line-lab ...
- Web.xml配置详解(转)
Web.xml配置详解 Posted on 2010-09-02 14:09 chinaifne 阅读(295105) 评论(16) 编辑 收藏 1 定义头和根元素 部署描述符文件就像所有XML文件一 ...
- 静态部署TOMCAT
常见部署方式:静态部署和容器化部署 一.下载tomcat安装包 下载地址:https://tomcat.apache.org/download-90.cgi 图上是显示最新版本,而我下载的是9.0.8 ...
- 24.循环栅栏 CyclicBarrier
import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; /** * ...
- An Easy Introduction to CUDA C and C++
An Easy Introduction to CUDA C and C++ This post is the first in a series on CUDA C and C++, which i ...
- Go(二)函数
函数是一等公民 与其他主要编程语言的差异 1.可以有多个返回值 2.所有参数都是值传递 slice.map.channel会有传引用是错觉,如切片背后是数组,是一个数据结构,里面包含了指向对应数组的指 ...