https://www.cnblogs.com/sunshine-chen/p/11364856.html
sub 1
node 1
read 0 a
write a 0
sub 2
#include<bits/stdc++.h>
using namespace std;
#define fp(i,l,r) for(register int (i)=(l);(i)<=(r);++(i))
#define fd(i,l,r) for(register int (i)=(l);(i)>=(r);--(i))
#define fe(i,u) for(register int (i)=front[(u)];(i);(i)=e[(i)].next)
#define mem(a) memset((a),0,sizeof (a))
#define O(x) cerr<<#x<<':'<<x<<endl
#define int long long
inline int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return x*f;
}
void wr(int x){
if(x<0)putchar('-'),x=-x;
if(x>=10)wr(x/10);
putchar('0'+x%10);
}
int cnt,fib[100];
main(){
freopen("oldcomputer2.out","w",stdout);
fib[cnt=1]=1;
while(fib[cnt]<=1e9)++cnt,fib[cnt]=fib[cnt-1]+fib[cnt-2];
--cnt;
puts("node 1");
puts("read 0 a");
puts("add a 4");
puts("jmp a");
fp(i,0,cnt)printf("write %lld 0
",fib[i]);
return 0;
}
sub 3
#include<bits/stdc++.h>
using namespace std;
#define fp(i,l,r) for(register int (i)=(l);(i)<=(r);++(i))
#define fd(i,l,r) for(register int (i)=(l);(i)>=(r);--(i))
#define fe(i,u) for(register int (i)=front[(u)];(i);(i)=e[(i)].next)
#define mem(a) memset((a),0,sizeof (a))
#define O(x) cerr<<#x<<':'<<x<<endl
inline int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return x*f;
}
void wr(int x){
if(x<0)putchar('-'),x=-x;
if(x>=10)wr(x/10);
putchar('0'+x%10);
}
const int MAXN=105;
int n,m,dis[MAXN],pre[MAXN];
vector<int>G[MAXN];
main(){
freopen("oldcomputer3.in","r",stdin);freopen("oldcomputer3.out","w",stdout);
read();n=read();m=read();
fp(i,1,m){
int x=read(),y=read();
G[x].push_back(y);G[y].push_back(x);
}
queue<int>q;q.push(1);dis[1]=1;
while(!q.empty()){
int u=q.front();q.pop();
for(int v:G[u])if(!dis[v])dis[v]=dis[u]+1,q.push(v),pre[v]=u;
}
for(int u=100,v=0;u;v=u,u=pre[u]){
printf("node %d
",u);
printf("read %d a
",pre[u]);
printf("write a %d
",v);
}
return 0;
}
sub 4
#include<bits/stdc++.h>
using namespace std;
#define fp(i,l,r) for(register int (i)=(l);(i)<=(r);++(i))
#define fd(i,l,r) for(register int (i)=(l);(i)>=(r);--(i))
#define fe(i,u) for(register int (i)=front[(u)];(i);(i)=e[(i)].next)
#define mem(a) memset((a),0,sizeof (a))
#define O(x) cerr<<#x<<':'<<x<<endl
inline int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return x*f;
}
void wr(int x){
if(x<0)putchar('-'),x=-x;
if(x>=10)wr(x/10);
putchar('0'+x%10);
}
const int MAXN=1005;
int n,m,dis[MAXN],pre[MAXN];
vector<int>G[MAXN];
vector<pair<int,int> >buc[MAXN];
main(){
freopen("oldcomputer4.in","r",stdin);freopen("oldcomputer4.out","w",stdout);
read();n=read();m=read();
fp(i,1,m){
int x=read(),y=read();
G[x].push_back(y);G[y].push_back(x);
}
queue<int>q;
fp(i,51,100)q.push(i),dis[i]=1;
while(!q.empty()){
int u=q.front();q.pop();
for(int v:G[u])if(!dis[v])dis[v]=dis[u]+1,q.push(v);
}
fp(i,1,50)q.push(i),buc[i].push_back({0,0});
while(!q.empty()){
int u=q.front(),v=0;q.pop();
for(int x:G[u])if(dis[x]==dis[u]-1&&buc[v].size()<3){v=x;break;}
sort(buc[u].begin(),buc[u].end());
printf("node %d
",u);
for(auto x:buc[u]){
printf("read %d a
write a %d
",x.second,v);
buc[v].push_back({x.first+1,u});
}
if(v)q.push(v);
}
return 0;
}
sub 5(取了inf个随机数种子。。。)
#include<bits/stdc++.h>
using namespace std;
#define fp(i,l,r) for(register int (i)=(l);(i)<=(r);++(i))
#define fd(i,l,r) for(register int (i)=(l);(i)>=(r);--(i))
#define fe(i,u) for(register int (i)=front[(u)];(i);(i)=e[(i)].next)
#define mem(a) memset((a),0,sizeof (a))
#define O(x) cerr<<#x<<':'<<x<<endl
inline int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return x*f;
}
void wr(int x){
if(x<0)putchar('-'),x=-x;
if(x>=10)wr(x/10);
putchar('0'+x%10);
}
const int MAXN=105,inf=1e9;
struct node{
int u,v,t;
inline bool operator<(const node &b)const{return t<b.t;}
};
int n,m,dis[MAXN],pre[MAXN],id[20];
bool inq[MAXN],vis[MAXN][MAXN*2];
vector<int>G[MAXN];
vector<node>buc[MAXN];
inline void spfa(int S,int T){
fp(i,1,n)dis[i]=inf;queue<int>q;mem(inq);inq[S]=1;dis[S]=0;q.push(S);pre[S]=0;
while(!q.empty()){
int u=q.front();q.pop();inq[u]=0;
for(auto v:G[u]){
int t=dis[u]+1;
while(vis[v][t]||vis[v][t+1])++t;
if(t<dis[v]){
dis[v]=t;pre[v]=u;
if(!inq[v])inq[v]=1,q.push(v);
}
}
}
for(int u=T,v=0;u;v=u,u=pre[u]){
vis[u][dis[u]]=vis[u][dis[u]+1]=1;
buc[u].push_back({pre[u],v,dis[u]});
}
}
main(){
freopen("oldcomputer5.in","r",stdin);freopen("oldcomputer5.out","w",stdout);
read();n=read();m=read();srand(19198103);
fp(i,1,m){
int x=read(),y=read();
G[x].push_back(y);G[y].push_back(x);
}
fp(i,1,n)random_shuffle(G[i].begin(),G[i].end());
fp(i,1,10)id[i]=i;random_shuffle(id+1,id+11);
fp(i,1,10)spfa(id[i],101-id[i]);
fp(i,1,n){
printf("node %d
",i);
sort(buc[i].begin(),buc[i].end());
for(auto x:buc[i]){
printf("read %d a
write a %d
",x.u,x.v);
}
}
return 0;
}