| Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|---|
| 436398 | 顾鑫辰 | 【C6-4】Hanoi双塔问题 | C++ | 通过 | 100 | 2 MS | 256 KB | 1047 | 2026-04-14 16:37:08 |
#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<int> mul2(vector<int> a) { vector<int> res; int carry = 0; for (int x : a) { carry += x * 2; res.push_back(carry % 10); carry /= 10; } while (carry) { res.push_back(carry % 10); carry /= 10; } return res; } vector<int> sub2(vector<int> a) { vector<int> res; int borrow = 2; for (int x : a) { if (x >= borrow) { res.push_back(x - borrow); borrow = 0; } else { res.push_back(x + 10 - borrow); borrow = 1; } } while (res.size() > 1 && res.back() == 0) res.pop_back(); return res; } int main() { int n; cin >> n; vector<int> ans = {1}; for (int i = 0; i < n + 1; i++) { ans = mul2(ans); } ans = sub2(ans); reverse(ans.begin(), ans.end()); for (int x : ans) cout << x; cout << endl; return 0; }