Codeforces1303D. Fill The Bag
1e18对应2进制有58位,可以直接暴力模拟,因为读入的数都是2次幂,__builtin_ctz这个内置gcc函数可以算出二进制下末尾有几个0,读入时统计,然后从n的最低位开始判断,注意每次升位的时候如果有2个相同的就要向上一位进位,当拆掉比他大的数时,必定对比他大的位各个产生一个1,因为>>1
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL; int bit[];
LL n; int solve() {
int ans = ;
for(int i = ; i < ; ++i) {
if(n&(1LL<<i)) {
for(int j = i; j <= ; ++j) {
if(j == ) return -;
if(bit[j]) {
bit[j]--;
for(int k = i; k < j; ++k)
bit[k]++;
break;
}
ans++;
}
}
bit[i+] += bit[i] /;
}
return ans;
} void run_case() {
int m, t;
memset(bit, , sizeof(bit));
cin >> n >> m;
for(int i = ; i < m; ++i) {
cin >> t; bit[__builtin_ctz(t)]++;
}
cout << solve() << "\n";
} int main() {
ios::sync_with_stdio(false), cin.tie();
//cout.setf(ios_base::showpoint);cout.precision(10);
int t; cin >> t;
while(t--)
run_case();
cout.flush();
return ;
}
Codeforces1303D. Fill The Bag的更多相关文章
- 题解【CF1303D Fill The Bag】
\[ \texttt{Preface} \] 不开 long long 见祖宗. \[ \texttt{Description} \] 你有一个 \(n\) 码的袋子,你还有 \(m\) 个盒子,第 ...
- [CF1303D] Fill The Bag - 贪心
Solution 考虑从低位往高位贪心,设当前在处理第 \(i\) 位,更低位剩余的部分一共可以拼出 \(cnt\) 个 \(2^i\) 如果 \(n\) 的这一位是 \(1\) ,那么这一位就需要处 ...
- I - Fill The Bag codeforces 1303D
题解:注意这里的数组a中的元素,全部都是2的整数幂.然后有二进制可以拼成任意数.只要一堆2的整数幂的和大于x,x也是2的整数幂,那么那一堆2的整数幂一定可以组成x. 思路:位运算,对每一位,如果该位置 ...
- Educational Codeforces Round 82 (Rated for Div. 2) A-E代码(暂无记录题解)
A. Erasing Zeroes (模拟) #include<bits/stdc++.h> using namespace std; typedef long long ll; ; in ...
- [CF百场计划]#3 Educational Codeforces Round 82 (Rated for Div. 2)
A. Erasing Zeroes Description You are given a string \(s\). Each character is either 0 or 1. You wan ...
- Codeforces题解集 1.0
记录 Codeforces 2019年12月19日到 2020年2月12日 的部分比赛题 Educational Codeforces Round 82 (Rated for Div. 2) D Fi ...
- 2021record
2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...
- 【题解】Educational Codeforces Round 82
比较菜只有 A ~ E A.Erasing Zeroes 题目描述: 原题面 题目分析: 使得所有的 \(1\) 连续也就是所有的 \(1\) 中间的 \(0\) 全部去掉,也就是可以理解为第一个 \ ...
- Bag标签之删除书包中的一条数据
删除书包中的一条数据 查询 <esql module=help id=list> Select ID,Subject,Writer,DayTime From Messages </e ...
随机推荐
- MyBatis XML常用配置
1.属性(properties) 可外部配置且可动态替换的,既可以在典型的 Java 属性文件中配置,亦可通过 properties 元素的子元素来传递. 可以外部定义好properties文件通过 ...
- 吴裕雄 python 神经网络TensorFlow实现LeNet模型处理手写数字识别MNIST数据集
import tensorflow as tf tf.reset_default_graph() # 配置神经网络的参数 INPUT_NODE = 784 OUTPUT_NODE = 10 IMAGE ...
- 【MySQL】常用增删改查
目录 1. 文件夹(库) 2. 文件(表) 3. 文件内容(数据) "@ ___ 1. 文件夹(库) # 增 create database db charset utf8; # 查 sho ...
- Spring Bean 有关的那些注解
尊重原著直接贴链接 https://mp.weixin.qq.com/s/7lhpEo73KG3-xPgbFiaLHw
- 国内免费可用的STUN服务器(webrtc 必备)
更新于2017年8月,本人亲测,国内可用,而且速度非常快! webRTC不可缺少的环节. 免费 STUN服务器列表(亲测有效)NO. STUN服务器 端口 有效 测试日期1 stun.xten.com ...
- centos610无桌面安装JDK
Centos610系列配置 1.使用yum查找jdk: yum search java|grep jdk 2.选择安装截图中选中的版本 yum install java-1.8.0-openj ...
- @ModelAttribute与@RequestBody的区别
一.@ModelAttribute与@RequestBody的区别 @ModelAttribute与@RequestBody都是用来注解解析前端发来数据,并自动对应到所定义的字段名称. 这里先放结论, ...
- 「题解」「POJ1322」Chocolate
目录 题目 原题目 简易题意 思路分析 代码 练习题 题目 原题目 点这里 简易题意 包裹里有无限个分布均匀且刚好 \(c\) 种颜色的巧克力,现在要依次拿 \(n\) 个出来放到桌子上.每次如果桌子 ...
- Hibernate学习(七)
Hibernate缓存 1.一级缓存:Session 级别的缓存 2.二级缓存: SessionFactory 级别的缓存 3.查询缓存:需二级缓存的支持,查询缓存依赖二级缓存 一级缓存 1.依赖于 ...
- 吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度
import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...