1 条题解
-
0
练44.1 比特童币
解题思路
枚举0~15,用bitset<4>输出四位二进制,紧跟B,再空格与十进制值。
正确性说明
计算规则直接来自题目定义。按所述顺序处理时,已完成部分的结果被准确保存在累加量、计数或当前状态中;下一步只加入新增贡献。最终得到完整要求的结果。
易错点
0对应0000B,所有数都固定四位。
复杂度
固定16个,时间O(1),空间O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); for (int n = 0; n < 16; n++) cout << bitset<4>(n) << "B " << n << "\n"; return 0; }
- 1