2023.10.19 复习的时候重新修了一下
快读快写
封装版
namespace FIO {
const short wr_bs = 10;
bool rd_f;
short rd_c, wr_s[1000005];
int wr_l = 0;
template<typename Ty> inline void read(Ty &x) {
for (rd_c = getchar(), rd_f = 0; rd_c < '0' || rd_c > '9'; rd_c = getchar()) if (rd_c == '-') rd_f = 1;
for (x = 0; rd_c >= '0' && rd_c <= '9'; rd_c = getchar()) x = (x << 1) + (x << 3) + (rd_c ^ 48);
x = rd_f ? -x : x;
}
template<typename Ty> inline void write(Ty x) {
if (!x) return (void)(putchar('0'));
if (x < 0) putchar('-'), x = -x;
for (; x; x /= wr_bs) wr_s[++wr_l] = x % wr_bs ^ 48;
for (; wr_l; wr_l--) putchar(wr_s[wr_l]);
}
}
using namespace FIO;
快读
template<typename Ty> inline void read(Ty &x) {
short c = getchar(), f = 1;
for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
快写
int wr_l = 0, wr_s[1000005];
template<typename Ty> inline void write(Ty x) {
if (x == 0) return (void)(putchar('0'));
if (x < 0) putchar('-'), x = -x;
for (; x; x /= 10) wr_s[++wr_l] = x % 10 + '0';
for (; wr_l; wr_l--) putchar(wr_s[wr_l]);
}
调用
read(x);
write(x);
template<typename Ty>
的作用是生成一个适用于多个类型的模板,里面的参数
x
x
x 的变量的类型名会自动读取为 Ty
,对于常见的不同数据类型都可以处理。
__int128
只可以快读快输。
对拍
对拍模板(以a+b为例)
pai.cpp
对拍程序
写法1:
#include <bits/stdc++.h>
using namespace std;
int main() {
while (1) {
system("gendata.exe");
system("a+b.exe");
system("baoli.exe");
if (system("fc /w a+b.out baoli.out")) {
printf("Wrong Answer\n");
break;
}
printf("Accepted\n");
}
return 0;
}
/w
的作用是去除行末空格和文末回车。也可以不用。
写法2:
个人比较喜欢用这种。
#include <bits/stdc++.h>
using namespace std;
int main() {
while (1) {
system("gendata");
system("a+b");
system("baoli");
if (system("fc /w a+b.out baoli.out")) {
printf("Wrong Answer\n");
break;
}
printf("Accepted\n");
}
return 0;
}
写法3:
#include <bits/stdc++.h>
using namespace std;
int main() {
while (1) {
system("gendata.exe > data.in");
system("a+b.exe < data.in > std.out");
system("baoli.exe < data.in > baoli.out");
if (system("fc a+b.out baoli.out")) {
printf("Wrong Answer\n");
break;
}
printf("Accepted\n");
}
return 0;
}
批处理写法:(文件名为pai.bat)
@echo off
:loop
gen.exe > a+b.in
a+b.exe < a+b.in > a+b.out
baoli.exe < a+b.in > baoli.out
fc a+b.out baoli.out
if %errorlevel%==0 goto loop
pause
gendata.cpp
数据生成器
#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("data.in", "w", stdout);
srand(time(0));
int a = rand(), b = rand();
printf("%d %d", a, b);
return 0;
}
a+b.cpp
正解代码
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
freopen("data.in", "r", stdin);
freopen("a+b.out", "w", stdout);
scanf("%d%d", &a, &b);
printf("%d", a + b);
return 0;
}
baoli.cpp
暴力代码
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
freopen("data.in", "r", stdin);
freopen("baoli.out", "w", stdout);
scanf("%d%d", &a, &b);
for (int i = 1; i <= b; i++) a++;
printf("%d", a);
return 0;
}