代码开头通用模板
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define lowbit(x) (x&(-x))
#define MP make_pair
#define fi first
#define se second
#define ls(x) (x << 1)
#define rs(x) ((x << 1) | 1)
#define rep(i,l,r) for (int i = l ; i <= r ; i++)
#define down(i,r,l) for (int i = r ; i >= l ; i--)
#define fore(i,x) for (int i = head[x] ; i ; i = e[i].next)
#define SZ(v) (int)v.size()
typedef long long ll;
typedef pair <int,int> pr;
const int maxn = 1e6 + 10;
int main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
}
对拍
#include<bits/stdc++.h>
#include<ctime>
using namespace std;
double times,times2;
int main(){
int t = 0;
while ( true ){
system("datamaker.exe");
times = clock();
system("1252D.exe < input.txt > 1.out"); //linux need modification
times = clock() - times;
times2 = clock();
system("std.exe < input.txt > 2.out");
times2 = clock() - times2;
if ( system("fc 1.out 2.out > log.txt") ){ //linux use : "diff" instead of "fc"
system("pause");
break;
}
cout<<"correct "<<++t<<endl;
cout<<times / 1000<<" "<<times2 / 1000<<endl;
}
return 0;
}
datamaker
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define lowbit(x) (x&(-x))
#define MP make_pair
#define fi first
#define se second
#define ls(x) (x << 1)
#define rs(x) ((x << 1) | 1)
#define rep(i,l,r) for (int i = l ; i <= r ; i++)
#define down(i,r,l) for (int i = r ; i >= l ; i--)
#define fore(i,x) for (int i = head[x] ; i ; i = e[i].next)
#define SZ(v) (int)v.size()
typedef long long ll;
typedef pair <int,int> pr;
const int maxn = 500 + 10;
const int ninf = -2147483648;
int main(){
freopen("1.cnt","r",stdin);
int cnt;
scanf("%d",&cnt);
fclose(stdin);
freopen("1.cnt","w",stdout);
cout<<++cnt;
fclose(stdout);
srand(cnt + time(0));
freopen("input.txt","w",stdout);
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
return 0;
}
为OOP课程准备的头文件
#include <vector>
#include <stack>
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <array>
#include <bitset>
数学、计数题
虽然用add,mul,sub函数很烦。但是可以避免很多取模错误、也可以优化常数。
所以应该渐渐学会这样减少错误的代码风格
//NOTES: 任意乘法需要用mul,或者强制用long long。
//注意取模
//====================================basic operation===============================
inline void add(int &x, int y) {
x += y;
if (x >= mod) {
x -= mod;
}
}
inline void sub(int &x, int y) {
x -= y;
if (x < 0) {
x += mod;
}
}
inline int mul(int x, int y) {
return (int) ((long long) x * y % mod);
}
inline int power(int x, int y) {
int res = 1;
while (y) {
if (y & 1) {
res = mul(res, x);
}
x = mul(x, x);
y >>= 1;
}
return res;
}
inline int inv(int a) {
int b = mod, u = 0, v = 1;
while (a) {
int t = b / a;
b -= t * a;
swap(a, b);
u -= t * v;
swap(u, v);
}
if (u < 0) {
u += mod;
}
return u;
}
//=======================================================================================