XCPC 常用技巧
命令行编译
如果用 vscode,sublime 这样的文本编辑器写代码的话,一般写完代码都需要在命令行进行编译运行(不是所有场次的 vscode 都会安装 Code Runner,所以有时需要手动编译运行)。
C++ 编译命令:
g++ A.cpp -o A -Wall -lm -std=c++20
./A
- 其中的
A.cpp
可以换成要编译的源文件。 - 第二个
A
是生成的可执行的名称,这个可执行文件的名称必须与第二行./
后的内容相同,这样才能运行相应的程序。 -std=c++20
是指定用C++20
,可以根据比赛环境换成相应的 C++ 版本
Linux 环境下的对拍
对拍一般是用一个暴力程序判断自己写的程序是否有错,比赛的操作系统一般都是 Linux 系统。
data.cpp:用于造数据
#include <bits/stdc++.h>
using namespace std;int main() {ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);srand(time(0));cout << rand() % 1000000 << " " << rand() % 1000000 << endl;return 0;
}
bf.cpp:暴力程序
#include <bits/stdc++.h>
using namespace std;int main() {ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);int a, b;cin >> a >> b;cout << a + b << endl;return 0;
}
std.cpp :待检测的程序
#include <bits/stdc++.h>
using namespace std;int main() {ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);int a, b;cin >> a >> b;cout << a - b << endl;return 0;
}
pai.cpp:对拍脚本
#include <bits/stdc++.h>
using namespace std;int main() {ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);int t = 1;while (1) {cout << "test " << t++ << endl;system("./data > data.in");system("./std < data.in > std.out");system("./bf < data.in> bf.out");if (system("diff bf.out std.out")) break;}return 0;
}