一堆对于 code 来说有用的东西
Gcc_Gdb_7_8_1 · · 科技·工程
一堆对于 code 来说有用的东西:
代码
方便/加快用的宏:
namespace IO {
char buf[1 << 20], *p1 = buf, *p2 = buf;
char out[1 << 20], *p3 = out;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++)
#define putchar(ch) (p3 == out + (1 << 20) && fwrite(p3 = out, 1, 1 << 20, stdout), *p3++ = (ch))
class Flusher {
public:
~Flusher() {
fwrite(p3 = out, 1, 1 << 20, stdout);
}
} flusher;
template<typename T>
inline int read(T &x)
{
x = 0;
int op = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == EOF) {
return EOF;
}
if (ch == '-') {
op = -1;
}
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x *= op;
return 0;
}
template<typename T>
inline void write(T x)
{
if (x < 0) {
x = -x;
putchar('-');
}
static short obuf[50], top = 0;
do {
obuf[++top] = x % 10;
x /= 10;
} while(x);
while (top) {
putchar(obuf[top--] | 48);
}
}
};
手搓 STL
stack:
对拍器:
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define Pii pair<int, int>
#define ULL unsigned long long
namespace gdb7
{
int main() {
int f1 = system("g++.exe mine.cpp -o mine -O2 -std=c++14 > nul");
int f2 = system("g++.exe tj.cpp -o tj -O2 -std=c++14 > nul");
int f3 = system("g++.exe data.cpp -o data -O2 -std=c++14 > nul");
if (f1 || f2 || f3) {
printf("Not Found mine.cpp, tj.cpp or data.cpp");
system("pause");
exit(0);
}
int num = 0;
while (true) {
++num;
printf("Generating data\r");
system("data.exe > data.in");
system("tj.exe < data.in > data.out");
clock_t start2 = clock();
printf("Running on Test %d\r", num);
int retur = system("mine.exe < data.in > mine.out");
clock_t end2 = clock();
if (retur) { // RE
printf("Runtime Error on Test %d\nThe data is:\n input:\n", num);
system("type data.in");
printf("output:\n");
system("type data.out");
printf("Your Program return %d\n", retur);
system("pause");
} else if ((double)(end2 - start2) / CLOCKS_PER_SEC > 1000) { // TLE
printf("Time Limit Exceeded on Test %d\nThe data is:\ninput:\n", num);
system("type data.in");
printf("output:\n");
system("type data.out");
printf("Your Program used %.2lf s\n", (double)(end2 - start2) / CLOCKS_PER_SEC * 1000);
system("pause");
} else if (system("fc data.out mine.out > nul")) { // WA
printf("Wrong Answer on Test %d\nThe data is:\ninput:\n", num);
system("type data.in");
printf("output:\n");
system("type data.out");
printf("your output:\n");
system("type mine.out");
printf("diffrent: \n");
system("fc data.out mine.out");
putchar('\n');
system("pause");
} else { // AC
printf("Accepted on Test %d\n", num);
}
}
return 0;
}
};
int main()
{
return gdb7::main();
}
文档:
不常见但有用的函数:
inline _Ty accumulate(_InIt _First, _InIt _Last, _Ty _Val, _Fn2 _Func):求从_First到_Last的所有元素的和,以_Val为初值,以_Func为加法。