需要完整CSP、ACM板子可以去资源搜,我设置的0积分,如果要花钱可以B站私我!
错误解决
RE是Runtime Error(运行时错误)的缩写。
简单来说,这意味着你的代码成功通过了编译(语法没有错误),但在实际运行过程中,程序遇到了无法处理的情况,导致被操作系统或评测系统强制终止。
在算法竞赛(如 OJ 平台)中,RE 通常由以下几种原因引起:
1. 数组越界 (最常见)
这是新手最容易犯的错误,也是你上一段代码中存在的问题。
- 现象:访问了数组范围之外的内存。
- 例子:定义
int a[10],却访问了a[10](下标最大为 9)或a[-1]。 - 后果:程序试图读写未分配的内存区域,操作系统会立即杀掉进程。
2. 除以零
- 现象:代码中出现了除数为 0 的运算。
- 例子:
int a = 5 / 0;或int a = 5 / b;(此时 b 恰好为 0)。 - 后果:CPU 无法执行该指令,触发异常。
3. 栈溢出
- 现象:通常是递归太深,或者在函数内定义了过大的局部数组。
- 例子:递归函数没有正确的终止条件(死递归),或者写了
void solve() { int bigArray[1000000]; ... }。 - 后果:内存栈空间耗尽。
4. 指针错误 (C/C++)
- 现象:访问了空指针或野指针。
- 例子:
int *p = NULL; *p = 10;。
/tmp/compiler_7uvr2ihl/src:8:8: 错误:‘int y1’ redeclared as different kind of entity 8 | int x1,y1,x2,y2; | ^~ In file included from /nix/store/79624djlfdc0a6anji2rwqd9p9ycqi8h-glibc-2.34-210-dev/include/features.h:490, from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/os_defines.h:39, from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/c++config.h:524, from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/cassert:43, from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:33, from /tmp/compiler_7uvr2ihl/src:1: /nix/store/79624djlfdc0a6anji2rwqd9p9ycqi8h-glibc-2.34-210-dev/include/bits/mathcalls.h:224:1: 附注:previous declaration ‘double y1(double)’这是redeclared错误,要么自己命名重复,要么可能和库变量重名了。
如果是撞库了,直接移到main内即可。
还有一种可能,就是数组开的不够,或者爆int了,开大一些,并改为long long即可
缺少默认实参
struct Node { int x1, y1, x2, y2, lay; // ❌ 错误写法:前4个有默认值,第5个没有 Node(int a=0, int b=0, int c=0, int d=0, int e) : x1(a), y1(b), x2(c), y2(d), lay(e) {} };