杂项处理
保留位数
printf("%.3f",a);
cout<<fixed<<setprecision(3)<<a;
对拍
::::info[扩展名改成 .bat]
makeExample.exe > testCode.in
testCode < testCode.in > testCode.out
correctCode < testCode.in > correctCode.out
fc testCode.out correctCode.out
if errorlevel==1 pause
%0
::::
spfa P3371 【模板】单源最短路径(弱化版)
dijkstra P4779 【模板】单源最短路径(标准版)
快读
::::info[同步流]
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
::::
::::info[代码]
int read(){
int x=0;int f=1;char c=getchar();
while(c<'0' or c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0' and c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
return x*f;
}
::::
快写
::::info[代码]
inline void mwrite(int a){
if(a>9)mwrite(a/10);
putchar((a%10)|48);
}
::::
重载运算符
::::info[代码]
struct node{
int w,id;
bool operator<(const node& other) const {
// 从小到大
return w<other.w;
}
};
::::
去重
::::info[代码]
sort(a.begin(),a.end());
a.erase(unique(a.begin(),a.end()),a.end());
::::
快速幂 P1226 【模板】快速幂
离散化
::::info[代码]
for(int i=1;i<=n;i++) b[i]=a[i];
sort(b+1,b+1+n);
for(int i=1;i<=n;i++)
if(b[i]!=b[i-1])
c[b[i]]=++ii;/*c[i]表示的是值为i的数离散化后的数*/
for(int i=1;i<=n;i++) b[i]=c[a[i]];/*b[i]是离散化后的数组*/
STL 版的:
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
::::
tarjan(连通性) P2863 [USACO06JAN] The Cow Prom S
博客园
::::info[代码]
void dfs(int u){
dfn[u]=low[u]=++cn;
st[++top]=u;
vis[u]=1;
for(int i=head[u];i!=-1;i=e[i].next){
int v=e[i].to;
if(!dfn[v]){
dfs(v);
low[u]=min(low[u],low[v]);
}
else if(vis[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(dfn[u]==low[u]){
int cur;
while(u!=cur){
cur=st[top--];
vis[cur]=0;
}
}
}
::::
::::success[
Tarjan 爷爷自己的解释: