thupc F求调(有注释+悬关)
  • 板块学术版
  • 楼主紊莫turtle
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/12/17 16:15
  • 上次更新2023/12/17 18:16:33
查看原帖
thupc F求调(有注释+悬关)
443675
紊莫turtle楼主2023/12/17 16:15
//@紊莫 on Luogu (uid=443675)
#include <bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
int n,m,k;
struct Order{
	string name;
	int h,x,y,z;//这个指令本身的属性
	string cmdname;//TRIGGER触发条件
	int id;//TRIGGER或REPLACE要使用到的指令在ulst中的位置
	Order(){name=cmdname="";h=x=y=z=id=0;}
};
vector<Order> ulst;//指令里的指令
struct Robot{
	int l_hand,r_hand;
	vector<Order> lst;//操作表
}bot[105];
void Input();
Order Analyze();
void Work(int now);
void Trigger(int now,string t,int ist);
void Do(int now,Order x,int ist);
int main(){
	freopen("5.in","r",stdin);
	freopen("5.out","w",stdout);
	Input(); int now=0;
	while(k>0)
		Work(now),now=(now+1)%n;
    return 0;
}
void Input(){//读入
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m>>k;
	F(i,0,n-1){
		cin>>bot[i].l_hand>>bot[i].r_hand;
		F(j,1,m){
			Order res=Analyze();
			bot[i].lst.push_back(res);
		}
	}
}
Order Analyze(){//读入
	Order res; string s,cmd,cname; cin>>s;
	int H,X,Y,Z; res.name=s;
	if(s=="MOVE") cin>>H>>Z,res.h=H,res.z=Z;
	if(s=="SWAP") cin>>H>>X>>Y,res.h=H,res.x=X,res.y=Y;
	if(s=="MIRROR") cin>>H>>X,res.h=H,res.x=X;
	if(s=="ACTIVATE") cin>>H,res.h=H;
	if(s=="REPLACE") {
		cin>>H>>X,res.h=H,res.x=X;
		Order cmd=Analyze(); ulst.push_back(cmd);
		res.id=int(ulst.size())-1;
	}
	if(s=="TRIGGER"){
		cin>>cname; cname.pop_back(); res.cmdname=cname;
		Order cmd=Analyze();ulst.push_back(cmd);
		res.id=int(ulst.size())-1;
	}
	return res;
 }
void Work(int now){//依次操作
	for(auto x:bot[now].lst){
		Do(now,x,0);
	}
}
void Do(int now,Order x,int ist){//单步激活,now是被激活的人,x是操作,ist表示是不是trigger来的
	if(k<=0) exit(0);
	string t=x.name;
	if(t=="SLACKOFF"){
		cout<<"Robot "<<now<<" slacks off.\n";k--;
	} if(t=="MOVE"){
		int to;
		if(x.h==0) to=(bot[now].l_hand+=x.z)%=n;
		else to=(bot[now].r_hand+=x.z)%=n;
		cout<<"Robot "<<now<<" moves its "<<(x.h==0?"left":"right")<<" hand towards Robot "<<to<<".\n";k--;
	} if(t=="SWAP"){
		int to=(x.h==0)?bot[now].l_hand:bot[now].r_hand;
		cout<<"Robot "<<now<<" swaps a line of command with Robot "<<to<<".\n";k--;
		swap(bot[to].lst[x.x-1],bot[now].lst[x.y-1]);
	} if(t=="MIRROR"){
		int to=(x.h==0)?bot[now].l_hand:bot[now].r_hand;
		cout<<"Robot "<<now<<" modifies a line of command of Robot "<<to<<".\n";k--;
		if(bot[to].lst[x.x-1].name!="TRIGGER") bot[to].lst[x.x-1].h^=1;
		else ulst[bot[to].lst[x.x-1].id].h^=1;
	} if(t=="REPLACE"){
		int to=(x.h==0)?bot[now].l_hand:bot[now].r_hand;
		cout<<"Robot "<<now<<" replaces a line of command of Robot "<<to<<".\n";k--;
		bot[to].lst[x.x-1]=ulst[x.id];
	} if(t=="ACTIVATE"){
		int to=(x.h==0)?bot[now].l_hand:bot[now].r_hand;
		cout<<"Robot "<<now<<" activates Robot "<<to<<".\n";k--;
		Work(to);
	} if(k<=0) exit(0);
	if(t!="TRIGGER") Trigger(now,t,ist);
}
void Trigger(int now,string t,int ist){
	int to=bot[now].r_hand;
	if(to==now) return ;
	for(auto x:bot[to].lst){
		if(x.name!="TRIGGER") continue;
		if(x.cmdname==t||(x.cmdname=="TRIGGER"&&ist==1)){
			Do(to,ulst[x.id],1);break;
		}
	}
}
2023/12/17 16:15
加载中...