- 臧启航 的博客
⚡国王游戏正解⚡
- @ 2026-8-1 20:11:03
以下代码由8192个long long拼接而成,由deepseek生成
#include <bits/stdc++.h>
using namespace std;
using u64 = unsigned long long;
using u128 = __uint128_t;
const int BLOCK = 8192; // 固定块数,足够大
struct BigInt {
u64 a[BLOCK]; // 低位在前
BigInt() { memset(a, 0, sizeof(a)); }
BigInt(u64 x) { memset(a, 0, sizeof(a)); a[0] = x; }
// 乘法:大数 × u64
BigInt operator*(u64 b) const {
BigInt res;
u64 carry = 0;
for (int i = 0; i < BLOCK; ++i) {
u128 tmp = (u128)a[i] * b + carry;
res.a[i] = (u64)tmp;
carry = (u64)(tmp >> 64);
}
// 如果 carry 非零,会丢失,但 BLOCK 足够大,不会出现
return res;
}
// 除法:大数 ÷ u64,返回商
BigInt operator/(u64 b) const {
if (b == 0) return BigInt(0);
BigInt res;
u64 rem = 0;
for (int i = BLOCK - 1; i >= 0; --i) {
u128 cur = ((u128)rem << 64) | a[i];
res.a[i] = (u64)(cur / b);
rem = (u64)(cur % b);
}
return res;
}
// 比较当前数是否大于 other
bool greaterThan(const BigInt& other) const {
for (int i = BLOCK - 1; i >= 0; --i) {
if (a[i] != other.a[i]) return a[i] > other.a[i];
}
return false;
}
// 打印十进制
void print() const {
// 找到最高非零块
int top = BLOCK - 1;
while (top > 0 && a[top] == 0) --top;
// 检查是否全零
bool zero = true;
for (int i = 0; i <= top; ++i) if (a[i]) { zero = false; break; }
if (zero) { cout << 0; return; }
// 临时复制,用于逐次除以10取余数
u64 tmp[BLOCK];
memcpy(tmp, a, sizeof(tmp));
string s;
while (!zero) {
u64 rem = 0;
for (int i = top; i >= 0; --i) {
u128 cur = ((u128)rem << 64) | tmp[i];
tmp[i] = (u64)(cur / 10);
rem = (u64)(cur % 10);
}
s.push_back('0' + rem);
// 更新 top
while (top > 0 && tmp[top] == 0) --top;
zero = true;
for (int i = 0; i <= top; ++i) if (tmp[i]) { zero = false; break; }
}
reverse(s.begin(), s.end());
cout << s;
}
};
struct Node {
u64 left, right;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<Node> a(n + 1);
for (int i = 0; i <= n; ++i) {
cin >> a[i].left >> a[i].right;
}
// 按 left * right 升序排序(用 u128 防溢出)
sort(a.begin() + 1, a.end(), [](const Node& x, const Node& y) {
return (u128)x.left * x.right < (u128)y.left * y.right;
});
BigInt sum = a[0].left;
BigInt ans = 0;
for (int i = 1; i <= n; ++i) {
BigInt cur = sum / a[i].right;
if (cur.greaterThan(ans)) ans = cur;
sum = sum * a[i].left;
}
ans.print();
cout << '\n';
return 0;
}