Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
84016 sh25_shenpy Hanoi双塔问题 C++ 解答错误 0 MS 252 KB 745 2026-02-05 16:14:39

Tests(0/10):


#include <iostream> #include <bitset> #include <algorithm> using namespace std; // 将 bitset 转换为字符串(高位在前) string bitset_to_string(const bitset<1000>& bs) { string s; for (int i = bs.size() - 1; i >= 0; --i) { s += bs[i] ? '1' : '0'; } // 移除前导零 s.erase(0, s.find_first_not_of('0')); return s.empty() ? "0" : s; } int main() { int n; while(cin >> n){ const int bits = 1000; // 足够大的位数 bitset<bits> result(1); // 初始化为 1 result <<= (n + 1); // 左移 n+1 位(相当于 2^(n+1)) result.set(0, 0); // 减去 2(即最低位置 0) cout << bitset_to_string(result) << endl;} return 0; }


测评信息: