赛场小寄巧
Part 1 卡常出奇迹
把这个玩意加在代码前面会有奇效~
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)
Part 2 对拍好东西
当你不知道正解有没有写挂时(或者大样例很水时),不妨试试数据生成~(一般来说挺好用的,但是除非样例有保证什么……)
// 万能头下可以直接使用,否则你还要加一个头文件:cstdlib
srand(time(0)); // 一定要在开头加这个,不然生成的随机数都一样
int x = rand(); // 此时 x 为 int 范围内的随机数
int x = rand() % y; // 此时 x 为 0 ~ y 范围的随机数
int x = rand() % y + z; // 此时 x 为 z ~ y + z - 1 范围的随机数
// sprintf 也可以了解一下,这可以写文件名
// freopen 不说了,懂得都懂
Part 3 system 是神器
假设你有一个暴力程序 Baoli.exe
,还有一个不知道有没有对的正解 Ture.exe
,还有一个用于数据生成的程序 Rand.exe
,然后暴力程序的输出是 BaoliAns.out
,正解输出的是 TureAns.out
,这时就可以拿出 system 屠杀了!!!
# include <bits/stdc++.h>
# include <ctime>
using namespace std;
const int S = 10; // S 越大,程序对的可能性越大
int main(){
for(int i = 1; i <= S; i ++){
system("Rand.exe");
double start = clock();
system("True.exe");
double end = clock();
system("Baoli.exe"); // 这里要保证暴力程序没有写错
if (system("fc TrueAns.out BaoliAns.out")){
puts("Wrong Answer!");
return 0;
}
else{
printf("Accepted! 测试点 %d 用时:%lf",i,end-start);
}
}
return 0;
}
标签:GCC,falign,int,赛场,functions,pragma,optimize,小寄巧
From: https://www.cnblogs.com/yh2021shx/p/16770541.html