CSP考前须知
Lin_Yi_Rui · · 闲话
声明
以下内容基于山东 CSP,本地系统一律为 Windows。
试机阶段
-
检查硬件
包括:鼠标的左右键能否正常使用、键盘的每个按键都检查一遍、显示器是否正常等,若出问题需找老师更换。
观察电源的位置 不要轻易触碰它。 -
检查编译器
写一段简单程序运行,加上文件读写,检查是否正常。 -
模拟考前
30 分钟
模拟第二天考前30 分钟要做的事情,检查熟练程度。
(具体操作会在后面讲到) -
观察环境
看看空调位置等,根据温度准备好第二天的衣物。
确定考场及最近厕所位置。考前
30 分钟一般来说你会提前
30 分钟进入考场,能接触到电脑,但没有题目。 -
创建好文件夹及子文件夹
-
编译选项
在 DEV-C++ 中,点击上方工具->编译选项->编译时加入以下命令:并勾选,输入以下命令可还原评测环境,警告某些本地评测正常但上交后会报错的内容。注:评测机的栈空间为无限,但受限于题目空间限制 所以我们开的栈空间应与题目空间上限一致。
-O2 -std=c++14 -g -Wall -Wextra -Wl,--stack=1024000000
(O2 优化、版本 c++14、打开调试、启用警告、启用更多警告、开栈空间
- 写好你的代码框架和文件读写
#include<bits/stdc++.h>
using namespace std; typedef long long ll;
inline ll read() { ll x = 0,f = 1; char ch = getchar(); while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)) { x = (x<<3)+(x<<1)+(ch^48); ch = getchar(); } return x*f; }
int main() { freopen("XXX.in","r",stdin); freopen("XXX.out","w",stdout);
return 0;
}
- **写好对拍程序**
```cpp
//std.cpp 要检查的程序
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
int x = 0,f = 1;
char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-') f = -1;
ch = getchar();
}
while(isdigit(ch))
{
x = (x<<3)+(x<<1)+(ch^48);
ch = getchar();
}
return x*f;
}
int main()
{
freopen("data.in","r",stdin);
freopen("std.out","w",stdout);
return 0;
}
//bf.cpp 保证正解的程序(暴力代码)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
int x = 0,f = 1;
char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-') f = -1;
ch = getchar();
}
while(isdigit(ch))
{
x = (x<<3)+(x<<1)+(ch^48);
ch = getchar();
}
return x*f;
}
int main()
{
freopen("data.in","r",stdin);
freopen("bf.out","w",stdout);
return 0;
}
//data.cpp 数据生成器
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
freopen("data.in","w",stdout);
srand(time(0));
return 0;
}
//check.cpp 对拍
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
while(1)
{
system("data.exe");
system("std.exe");
system("bf.exe");
if(system("fc std.out bf.out"))
break;
}
return 0;
}
- 默写常考的模版
说不定就考上了呢。
比赛过程
时间分配
- 首先通读所有题目。
规则怪谈:T1 T2 不一定谁简单。 - 不要死磕一道题。
- 多争部分分。
策略与技巧
对于不会正解的题目。
数据分治
在小数据是使用暴力,大数据再使用优化算法。
if(n<=1000) work1(); else work2();时间检测
计算运行时间(CPU 时间),若时间超过题目要求,这里立刻输出已经算出的答案。
double start_time = double(clock())/CLOCKS_PER_SEC; double time_limit = 0.8;//一般会比时间上限小一点
...
for(int i ...) { if (i % 10000 == 0) //不要每次循环都检查是否超时 //改为定期检查是否超时 减小获取运行时间造成的开销 { double now_time = double(clock())/CLOCKS_PER_SEC; if(now_time-start_time > time_limit) { printf("%d\n",ans); break; } }
...
}
### 数据规模与时间复杂度
一般来说评测机每秒运算 $1 \times 10^7 \sim 1 \times 10^8$ 次左右。
还要注意常数的影响。
- $n$ 在 $10$ 以下:可能是暴力搜索/全排列枚举所有情况。
- $n$ 在 $20$ 以下:可以考虑二进制枚举 $O(2^n)$ 。
- $n$ 在 $40$ 以下:可能是搜索+优化,比如折半查找等。
- $n$ 在 $100 \sim 500$:$O(n^3)$。
- $n$ 在 $1000 \sim 10000$:$O(n^2)$。
- $n$ 在 $10^5 \sim 10^6$:$O(n \log n)$。
- $n$ 在 $10^6 \sim 10^7$:$O(n)$。
- $n \ge 10^7$:$O(\log n)$ 或 $O(1)$,如果不超过 $10^{16}$,也有可能是 $O(\sqrt{n})$ 等。
### 警告
- 变量名不用 `x1` `y1` `y0` `yn` `j1` `k0` `jn`。
- 变量名不用完整单词 `next` `time` `case` `array`。
- 别用 `#define int long long`。
# 结束前 $20$ 分钟
## 检查复杂度
计算时间复杂度和空间复杂度是否正确。
内存大小 $=$ 数组元素个数 $\times$ 类型字节数 $\div 1024 \div 1024$ (单位是 $MB$)。
```cpp
//空间计算工具
#include <bits/stdc++.h>
using namespace std;
bool ST;
int a[N];
int b[N][N];
...
bool ED;
int main()
{
cout << (&ED - &ST) / 1024.0 / 1024.0 << "MB" << endl;
return 0;
}
检查文件读写
每年都有文件读写被注释掉的。
然后查看输入输出的文件名是否正确。
检查格式
通常来说,提交的的答案应当在 姓名+考号 的文件夹下。
其中需包含每个题目的文件夹。
每个题目的文件夹中是你所写的代码,仅有 .cpp 文件,其他内容尽量都删除。
关于头文件
建议使用万能头。
#include <bits/stdc++.h>
防止部分函数在本地测评时可以运行,但在评测机上报错。