求条
查看原帖
求条
766112
Y__dream楼主2024/11/25 22:15
#include<bits/stdc++.h>
using namespace std;
struct zhiling{
    int type;
    int h,x,y,z;
    int cname;
    zhiling *rp;
    zhiling():rp(nullptr){}
    zhiling(zhiling *a){
        type=a->type;
        h=a->h;
        x=a->x;
        y=a->y;
        z=a->z;
        cname=a->cname;
        if(a->rp==nullptr) rp=nullptr;
        else rp=new zhiling(a->rp);
    }
    void read(){
        string name;
        cin>>name;
        if(name=="SLACKOFF") type=1;
        else if(name=="MOVE"){
            type=2;
            cin>>h>>z;
        }else if(name=="SWAP"){
            type=3;
            cin>>h>>x>>y;x--,y--;
        }else if(name=="MIRROR"){
            type=4;
            cin>>h>>x;x--;
        }else if(name=="REPLACE"){
            type=5;
            cin>>h>>x;x--;
            rp=new zhiling;
            rp->read();
        }else if(name=="ACTIVATE"){
            type=6;
            cin>>h;
        }else if(name=="TRIGGER"){
            type=7;
            string x;
            cin>>x;x.pop_back();
            if(x=="SLACKOFF") cname=1;
            else if(x=="MOVE") cname=2;
            else if(x=="SWAP") cname=3;
            else if(x=="MIRROR") cname=4;
            else if(x=="REPLACE") cname=5;
            else if(x=="ACTIVATE") cname=6;
            else if(x=="TRIGGER") cname=7;
            else assert("unknown zhiling");
            rp=new zhiling;
            rp->read();
        }else assert("unknown zhiling");
    }
    void rev(){
        h^=1;
        if(rp!=nullptr) rp->rev();
    }
};
struct Robot{
    vector<zhiling*> myzl;
    int h[2];
    void read(int m){
        cin>>h[0]>>h[1];
        myzl.resize(m);
        for(int i=0;i<m;++i){
            myzl[i]=new zhiling;
            myzl[i]->read();
        }
    }
}rb[110];
int n,m,k;
#define check if(k==0) exit(0);
#define out(s) cout<<s<<endl;k--;check;
#define SLACKOFF(id) ("Robot "+to_string(id)+" slacks off.")
#define MOVE(id,side,id2) ("Robot "+to_string(id)+" moves its "+(side?"rignt":"left")+" hand towards Robot "+to_string(id2)+".")
#define SWAP(id,id2) ("Robot "+to_string(id)+" swaps a line of command with Robot "+to_string(id2)+".")
#define MIRROR(id,id2) ("Robot "+to_string(id)+" modifies a line of command of Robot "+to_string(id2)+".")
#define REPLACE(id,id2) ("Robot "+to_string(id)+" replaces a line of command of Robot "+to_string(id2)+".")
#define ACTIVATE(id,id2) ("Robot "+to_string(id)+" activates Robot "+to_string(id2)+".")
void dfs(int,bool);
void zhixing(int id,zhiling* x,bool f){
    x=new zhiling(x);
    switch(x->type){
        case 1:out(SLACKOFF(id));break;
        case 2:(rb[id].h[x->h]+=x->z)%=n;out(MOVE(id,x->h,rb[id].h[x->h]))break;
        case 3:swap(rb[id].myzl[x->x],rb[rb[id].h[x->h]].myzl[x->y]);out(SWAP(id,rb[id].h[x->h]));break;
        case 4:out(MIRROR(id,rb[id].h[x->h]));rb[rb[id].h[x->h]].myzl[x->x]->rev();break;
        case 5:out(REPLACE(id,rb[id].h[x->h]));delete rb[rb[id].h[x->h]].myzl[x->x];rb[rb[id].h[x->h]].myzl[x->x]=new zhiling(x->rp);break;
        case 6:out(ACTIVATE(id,rb[id].h[x->h]));dfs(rb[id].h[x->h],f);break;
        case 7:break;
    }
    if(x->type!=7&&rb[id].h[1]!=id)
        for(auto it:rb[rb[id].h[1]].myzl)
            if(it->type==7)
                if((it->cname==7&&f)||(it->cname!=7&&it->cname==x->type)){
                    zhixing(rb[id].h[1],it->rp,1);
                    break;
                }
}
void dfs(int id,bool f){
    for(auto it:rb[id].myzl)
        zhixing(id,it,f);
}
int main(){
    // freopen("5.in","r",stdin);
    // freopen("out","w",stdout);
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<n;++i)
        rb[i].read(m);
    for(int i=0;;(i+=1)%=n)
        dfs(i,0);
    return 0;
}
2024/11/25 22:15
加载中...