CSP/NOIP 注意事项及技巧
注意事项
- 可以使用 __int128
- abs(__int128)/sqrt(__int128) 会 CE
- clock 在 windows 单位 ms, 在 linux 单位微秒
- 有返回值的函数不能不写返回值
- 开 long long
- 多测精确清空
- 滚动数组清空
- 输出 uint8_t/double/int8_t 等类型时转换为 int
- 调试代码一定要注释
- 不使用 y0, y1, yn, j0, j1, jn, time
技巧
编译选项
134217728 = 128 * 1024 * 1024
g++ -std=c++14 -O2 -Wall -Wextra -Wshadow -Wl,--stack,134217728 file.cpp -o file.exe
编译自动化
test.cpp
#include <iostream>
#include <sstream>
#include <string>
int main() {
int id = 0;
std::cin >> id;
std::string name = "file";
std::ostringstream comcmd;
comcmd << "cd " << name << " & g++ " << name
<< " -O2 -std=c++14 -Wall -Wextra -Wshadow -Wl,--stack,20000000 -o "
<< name << ".exe";
printf("Start Compiling...\n");
int cr = system(comcmd.str().c_str());
if (cr != 0) {
printf("Compile failed.Exit.\n");
return 1;
}
printf("Compile success.Start testing...\n");
for (int i = 1; i <= id; i++) {
std::string tmp = name + std::to_string(i);
std::ostringstream runcmd;
runcmd << "cd " << name << " & copy " << tmp << ".in " << name
<< ".in & " << name << ".exe fc " << name << ".out " << tmp
<< ".ans";
printf("Start testing of test %d...\n", i);
int tr = system(runcmd.str().c_str());
if (tr != 0) {
printf("WA on test %d.\n", i);
} else {
printf("AC on test %d.\n", i);
}
printf("-------------------------\n");
}
return 0;
}
#include <iostream>
#include <sstream>
#include <string>
#include <windows.h>
int main() {
std::string name = "file";
int id = 0;
std::cin >> id;
std::ostringstream comcmd;
comcmd << "cd " << name
<< " & g++ -std=c++14 -O2 -Wall -Wextra -Wshadow -Wl,--stack,134217728 "
<< name << ".cpp -o " << name << ".exe";
int cr = system(comcmd.str().c_str());
if (cr != 0) {
std::cout << "编译失败! 程序退出。\n";
return 1;
}
std::cout << "编译成功! 开始运行测试...\n";
for (int i = 1; i <= id; i++) {
std::string tmp = name + std::to_string(i);
std::ostringstream runcmd;
runcmd << "cd " << name << " & copy " << tmp << ".in " << name
<< ".in & " << name << ".exe & fc " << name << ".out " << tmp
<< ".ans";
std::cout << "运行测试 " << i << "...\n";
int tr = system(runcmd.str().c_str());
if (tr == 0) {
std::cout << "测试 " << i << " 通过\n";
} else {
std::cout << "测试 " << i << " 失败\n";
}
std::cout << "------------------------\n";
}
return 0;
}