版本比较
【个人记录 #1】个人代码规范
正文
增加 208 行删除 14 行
1212345678910111112131415161718192016171821222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566216768692570717273747576777879808182838485868788899091929394952728299697989910010110210310410510610710832109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145361461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282297 行未改动23723823924052241242243244245246247248249250251252253254### 前言
:::info[前言]这些都是按照自己的习惯写的,代码风格因人而异。:::
### 板子```cpp#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 any template<typename T>#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)<<"."<<endlany inline void chkmax(T &x,T y){if(x<y){x=y;}}any inline void chkmin(T &x,T y){if(x>y){x=y;}}const int eps=0xf;const int inf=0x7fffffff;const ll infll=0x7fffffffffffffff;const ull infull=0xffffffffffffffff;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;}```板子随时调整。### 拍子:::info[内容]板子(可能与最新板子不同):```cpp#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)<<"."<<endltt 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; 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;}```正确程序(求 $a \oplus b$ ):```cpp#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)<<"."<<endltt 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(){ #define DEBUG mofan101028 ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); code(); #ifdef DEBUG 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; #endif}```正确性待验证程序:```cpp#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)<<"."<<endltt 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;}```板子随时调整。随机数据生成器:~~~ cpp#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)<<"."<<endltt 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 下可用):```cpp#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)<<"."<<endltt 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;}```
:::### 规范
- 要尽量压行,每个代码块之间空一个空格。:::info[例子]7 行未改动cin>>a;cin>>b;cout<<a+b<<endl;```暂且不管板子中 $\text{const}$ 那一行。:::
- 括号里内容比较少就不换行。:::info[例子]如板子中的 $\text{chkmax}$ 和 $\text{chkmin}$ 。:::
### 一些标识符
`pow2[i]`表示 ${2}^{i}$ 的值。
`lg2[i]`表示 $\log_2i$ 的值。
[](https://www.luogu.me/article/g4uriq8f)