ACM CSP竞赛笔记(二十六)——常见报错解决
需要完整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/cconfig.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 a0, int b0, int c0, int d0, int e) : x1(a), y1(b), x2(c), y2(d), lay(e) {} };