跳到正文

题解

题解:P17073 [ICPC 2017 Shenyang R] Little Boxes

zgaius约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年7月5日
收录
2026年7月6日
更新
2026年8月28日
篇幅
约 2 分钟
题目
P17073

版本

  1. v1当前

按题意模拟,将 44 个数相加即可。

坑点

俗话说得好,十年 OI 一场空,不开 long long 见祖宗。

但是这样还不够, 4×262=2644 \times 2^{62}=2^{64} ,会爆 long long ,得用 unsigned long long 。

但这样还会被 hack ,数据如下:

hack数据

in:

代码
1
4611686018427387904 4611686018427387904 4611686018427387904 4611686018427387904

out:

0

ans:

18446744073709551616

此时如果是 C++ 选手就要特判了。

AC代码
C++
#include <iostream>
using namespace std;
typedef unsigned long long ull;
const ull TWO62 = 4611686018427387904ULL;
int main() {
    int t;
    cin >> t;
    while (t--) {
        ull a, b, c, d;
        cin >> a >> b >> c >> d;
        if (a == TWO62 && b == TWO62 && c == TWO62 && d == TWO62) cout << "18446744073709551616\n";
        else cout << a + b + c + d << endl;
        }
    return 0;
}
原文