关于快读压行写法的悬疑
Zyc_zhouyuchen · · 闲话
晚自习时lr提出一个快读逆天压行做法,以建图过程为例:\ 原版代码
while(m--){
u=rd(),v=rd();
g[u].push_back(v);
}
压行代码
while(m--)g[rd()].push_back(rd());
当然有一定局限性,而且根据zyl的说法,这可能导致错误,因为g[a].push_back(b)中a,b优先级相同
#include <bits/stdc++.h>
using namespace std;
int m,u,v;vector<int>g[15];
inline int rd(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}
int main(){
cin>>m;
while(m--)g[rd()].push_back(rd());//1
while(m--){u=rd(),v=rd();g[u].push_back(v);}//2
for(int i=1;i<=10;i++){
if(!g[i].size())continue;
cout<<i<<':';for(auto it:g[i])cout<<' '<<it;cout<<'\n';
}
return 0;
}
Geany本地试验通过,但还需验证,不建议使用