如何在P1001 A+B Problem中凑齐RE,TLE,AC,WA,MLE
YANGZIMU2013 · · 算法·理论
这不是题解!!!
挑战在P1001 A+B Problem中凑齐AC,WA,RE,TLE,MLE
- 实现后结果类似如下图
PS:每种的概率为
\frac{1}{5} 实现方法
- AC:正常输入和输出
- WA:输出
A + b + 1 - TLE:
while (true)无限循环 - MLE: 持续分配100MB大小的内存块
- RE: 使用
÷0 错误 -
随机数生成:使用
chrono::high_resolution_clock获取当前时间的微秒数作为随机种子保证在多个测试点几乎同时运行时不会出现完全一样的情况上代码:
#include <iostream> #include <random> #include <chrono> #include <vector>
using namespace std;
int main() { auto now = chrono::high_resolution_clock::now(); auto micros = chrono::time_point_cast<chrono::microseconds>(now); long seed = micros.time_since_epoch().count();
mt19937 gen(seed);
uniform_int_distribution<> dis(0, 4);
int random = dis(gen);
int a, b;
cin >> a >> b;
if (random == 0) {
cout << a + b << endl;
} else if (random == 1) {
cout << a + b + 1 << endl;
} else if (random == 2) {
while (true) {}
} else if (random == 3) {
vector<char*> memory_blocks;
try {
while (true) {
char* block = new char[100000000];
memory_blocks.push_back(block);
}
} catch (const bad_alloc& e) {
cout << a + b << endl;
}
} else {
int x = 0;
int y = 1 / x;
cout << y << endl;
}
return 0;
}
# 再次申明:这不是题解!!!!!
# 这不是题解!!!!!
# 这不是题解!!!!!