前言
这些都是按照自己的习惯写的,代码风格因人而异。
板子
#include <bits/stdc++.h>
using namespace std;
#define upp(x,y,z) for(x=(y);x<=(z);++x)
#define low(x,y,z) for(x=(y);x>=(z);--x)
#define tt template<typename t0>
#define fs(x) fixed<<setprecision(x)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define debug(x) cout<<"Line "<<__LINE__<<","<<(x)<<"."<<endl
tt inline void chkmax(t0 &x,t0 y){if(x<y){x=y;}}
tt inline void chkmin(t0 &x,t0 y){if(x>y){x=y;}}
const int eps=0xf; const int inf=0x7fffffff; const ll infll=0x7fffffffffffffff; const ull infull=0xffffffffffffffff;
const int N=1e6+eps; const ll mod=998244353;
void code(); void perf();
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); code(); perf();
return 0;
}
bool memorybegin;
void code(){
//do something...
}
bool memoryend;
void perf(){
cout<<"CPU time used:"<<fs(3)<<(double)clock()/CLOCKS_PER_SEC<<"s."<<endl;
cout<<"Memory used:"<<fs(3)<<abs((&memoryend-&memorybegin)*1.0/1024.0/1024.0)<<"MB."<<endl;
}板子随时调整。
拍子
内容
板子(可能与最新板子不同):
#include <bits/stdc++.h>
using namespace std;
#define upp(x,y,z) for(x=(y);x<=(z);++x)
#define low(x,y,z) for(x=(y);x>=(z);--x)
#define tt template<typename t0>
#define fs(x) fixed<<setprecision(x)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ull unsigned long long
#define debug(x) cout<<"Line "<<__LINE__<<","<<(x)<<"."<<endl
tt inline void chkmax(t0 &x,t0 y){if(x<y){x=y;}}
tt inline void chkmin(t0 &x,t0 y){if(x>y){x=y;}}
const int eps=0xf; const int inf=0x7fffffff; const ll infll=0x7fffffffffffffff; const ull infull=0xffffffffffffffff;
const int N=1e6+eps;
void code(); void perf();
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); code(); perf();
return 0;
}
bool memorybegin;
void code(){
//do something...
}
bool memoryend;
void perf(){
cout<<"CPU time used:"<<fs(3)<<(double)clock()/CLOCKS_PER_SEC<<"s."<<endl;
cout<<"Memory used:"<<fs(3)<<abs((&memoryend-&memorybegin)*1.0/1024.0/1024.0)<<"MB."<<endl;
}正确程序(求 ):
#include <bits/stdc++.h>
using namespace std;
#define upp(x,y,z) for(x=(y);x<=(z);++x)
#define low(x,y,z) for(x=(y);x>=(z);--x)
#define tt template<typename t0>
#define fs(x) fixed<<setprecision(x)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ull unsigned long long
#define debug(x) cout<<"Line "<<__LINE__<<","<<(x)<<"."<<endl
tt inline void chkmax(t0 &x,t0 y){if(x<y){x=y;}}
tt inline void chkmin(t0 &x,t0 y){if(x>y){x=y;}}
const int eps=0xf; const int inf=0x7fffffff; const ll infll=0x7fffffffffffffff; const ull infull=0xffffffffffffffff;
const int N=1e6+eps;
void code(); void perf();
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); code(); //perf();
return 0;
}
bool memorybegin;
void code(){
freopen("random.in","r",stdin);
freopen("correct.out","w",stdout);
ull a,b; cin>>a>>b; cout<<(a^b)<<endl;
}
bool memoryend;
void perf(){
cout<<"CPU time used:"<<fs(3)<<(double)clock()/CLOCKS_PER_SEC<<"s."<<endl;
cout<<"Memory used:"<<fs(3)<<abs((&memoryend-&memorybegin)*1.0/1024.0/1024.0)<<"MB."<<endl;
}正确性待验证程序:
#include <bits/stdc++.h>
using namespace std;
#define upp(x,y,z) for(x=(y);x<=(z);++x)
#define low(x,y,z) for(x=(y);x>=(z);--x)
#define tt template<typename t0>
#define fs(x) fixed<<setprecision(x)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ull unsigned long long
#define debug(x) cout<<"Line "<<__LINE__<<","<<(x)<<"."<<endl
tt inline void chkmax(t0 &x,t0 y){if(x<y){x=y;}}
tt inline void chkmin(t0 &x,t0 y){if(x>y){x=y;}}
const int eps=0xf; const int inf=0x7fffffff; const ll infll=0x7fffffffffffffff; const ull infull=0xffffffffffffffff;
const int N=1e6+eps;
void code(); void perf();
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); code(); //perf();
return 0;
}
bool memorybegin;
void code(){
freopen("random.in","r",stdin);
freopen("solution.out","w",stdout);
ull a,b; cin>>a>>b; cout<<((a&(~b))|((~a)&b))<<endl;
}
bool memoryend;
void perf(){
cout<<"CPU time used:"<<fs(3)<<(double)clock()/CLOCKS_PER_SEC<<"s."<<endl;
cout<<"Memory used:"<<fs(3)<<abs((&memoryend-&memorybegin)*1.0/1024.0/1024.0)<<"MB."<<endl;
}随机数据生成器:
#include <bits/stdc++.h>
using namespace std;
#define upp(x,y,z) for(x=(y);x<=(z);++x)
#define low(x,y,z) for(x=(y);x>=(z);--x)
#define tt template<typename t0>
#define fs(x) fixed<<setprecision(x)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ull unsigned long long
#define debug(x) cout<<"Line "<<__LINE__<<","<<(x)<<"."<<endl
tt inline void chkmax(t0 &x,t0 y){if(x<y){x=y;}}
tt inline void chkmin(t0 &x,t0 y){if(x>y){x=y;}}
const int eps=0xf; const int inf=0x7fffffff; const ll infll=0x7fffffffffffffff; const ull infull=0xffffffffffffffff;
const int N=1e6+eps;
void code(); void perf();
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); code(); //perf();
return 0;
}
bool memorybegin;
void code(){
freopen("random.in","w",stdout);
srand(time(0)); ull a,b,c,d; a=rand(); b=rand(); c=rand(); d=rand();
cout<<a*b<<" "<<c*d<<endl;
}
bool memoryend;
void perf(){
cout<<"CPU time used:"<<fs(3)<<(double)clock()/CLOCKS_PER_SEC<<"s."<<endl;
cout<<"Memory used:"<<fs(3)<<abs((&memoryend-&memorybegin)*1.0/1024.0/1024.0)<<"MB."<<endl;
}对拍核心程序(Windows 11 下可用):
#include <bits/stdc++.h>
using namespace std;
#define upp(x,y,z) for(x=(y);x<=(z);++x)
#define low(x,y,z) for(x=(y);x>=(z);--x)
#define tt template<typename t0>
#define fs(x) fixed<<setprecision(x)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ull unsigned long long
#define debug(x) cout<<"Line "<<__LINE__<<","<<(x)<<"."<<endl
tt inline void chkmax(t0 &x,t0 y){if(x<y){x=y;}}
tt inline void chkmin(t0 &x,t0 y){if(x>y){x=y;}}
const int eps=0xf; const int inf=0x7fffffff; const ll infll=0x7fffffffffffffff; const ull infull=0xffffffffffffffff;
const int N=1e6+eps;
void code(); void perf();
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); code(); //perf();
return 0;
}
bool memorybegin;
void code(){
int T=10; int i; double t1,t2;
freopen("bat.out","w",stdout);
upp(i,1,T){
system("random.exe");
t1=(double)clock()/CLOCKS_PER_SEC; system("solution.exe");
t2=(double)clock()/CLOCKS_PER_SEC; system("correct.exe");
if(system("fc solution.out correct.out")){
cout<<"WA in #"<<i<<"."<<endl; return;
}
cout<<"AC in #"<<i<<", time used:"<<fs(3)<<t2-t1<<"s."<<endl;
}
}
bool memoryend;
void perf(){
cout<<"CPU time used:"<<fs(3)<<(double)clock()/CLOCKS_PER_SEC<<"s."<<endl;
cout<<"Memory used:"<<fs(3)<<abs((&memoryend-&memorybegin)*1.0/1024.0/1024.0)<<"MB."<<endl;
}规范
- 要尽量压行,每个代码块之间空一个空格。
例子
要尽量写成:
int a,b; cin>>a; cin>>b; cout<<a+b<<endl;而不要写成:
int a,b;
cin>>a;
cin>>b;
cout<<a+b<<endl;- 括号里内容比较少就不换行。
例子
如板子中的 和 。
一些标识符
pow2[i]表示 的值。
lg2[i]表示 的值。