求条
查看原帖
求条
639198
Steve_xh楼主2024/6/7 13:03

调试的东西可能有点多,影响观感致歉/

目前是大样例过不去,没trigger到

//#define OUTPUT_IMEDT
//#define POINTER_TEST
//#define FILE_IN
//#define FILE_OUT
//#define TRIGGER_OUTPUT
//#define LOG_OUT

#include<bits/stdc++.h>
using namespace std;
struct Slackoff;
struct Move;
struct Swap;
struct Mirror;
struct Replace;
struct Activate;
struct Trigger;
void check_pointer_good(int);
int n,m,k,last=0;
#ifdef LOG_OUT
ofstream flog("5.log");
#endif
struct Counter{
	int now;
	Counter(){}
	inline void init(){now=k;}
	void operator--(){if(!--now)exit(0);}
	void operator--(int){return --*this;}
}cnt;
enum{
	SLACKOFF=1,
	MOVE	=2,
	SWAP	=3,
	MIRROR	=4,
	REPLACE	=5,
	ACTIVATE=6,
	TRIGGER	=7
};
inline int getcmdtype(string s)
 {return s[0]=='S'?(s[1]=='L'?SLACKOFF:SWAP):(s[0]=='M'?(s[1]=='O'?MOVE:MIRROR):(s[0]=='R'?REPLACE:(s[0]=='A'?ACTIVATE:TRIGGER)));}
struct Command;
struct Robot{
	Robot(){}
	int id,l,r;
	vector<Command*> c;
}rob[505];
struct Command{
	int type,x,y,z;
	bool h;
	Command *cmd;
	Command(){}
	Command(const Command& o):type(o.type),x(o.x),y(o.y),z(o.z),h(o.h),cmd(o.cmd){}
	virtual ~Command(){};
	virtual void init()
//		{cmd=new Command;}
	=0;
	virtual void recall(int){}
	virtual Command *clone()
//		{return (new Command(*this));}
	=0;
	virtual Command *mirror()
//		{Command* reans=this->clone();reans->h^=1;return reans;}
	=0;
//	virtual void trigger(Robot&,int){};
};
#ifdef OUTPUT_IMEDT
#define cout cerr
#undef stdout
#define stdout stderr
#endif
inline void trigger(int x,int tp){
#ifdef POINTER_TEST
	check_pointer_good(__LINE__);
#endif
#ifdef TRIGGER_OUTPUT
	cerr<<"now trigger:"<<x<<" "<<tp<<'\n';
#endif
	for(int i=0;i<m;i++)
		if((rob[x].c[i]->type)==TRIGGER&&((rob[x].c[i]->x)==tp||(last&&(rob[x].c[i]->x)==TRIGGER))){
#ifdef TRIGGER_OUTPUT
			cout<<"trigger:\n";
#endif
			Command* tcmd=rob[x].c[i]->cmd->clone();
			last=1;
			tcmd->recall(x);
#ifdef TRIGGER_OUTPUT
			cerr<<"Trigger end and begin to trigger trigger.\n"
			<<(bool)(rob[x].c[i]->cmd)<<'\n'
#endif
			;
			if(rob[x].r!=x
//			&&(rob[x].c[i]->cmd)
			)
				trigger(rob[x].r,tcmd->type);
			last=0;
//			delete tcmd;
			return ;
		}
#ifdef TRIGGER_OUTPUT
	cerr<<"Nothing triggered.\n";
#endif
}
struct Slackoff : public Command{
	Slackoff(){}
//	~Slackoff(){}
	inline void init(){
		type=SLACKOFF;
		x=y=z=h=0;
	}
	inline void recall(int x){
		cout<<"Robot "<<x<<" slacks off.\n";
		--cnt;
	}
	inline Slackoff *clone(){
		return (new Slackoff(*this));
	}
	inline Slackoff *mirror(){
		return this->clone();
	}
};
struct Move : public Command{
	Move(){}
//	~Move(){}
	inline void init(){
		type=MOVE;
		cin>>h>>z;
		x=y=0;
	}
	inline void recall(int id){
		int& hand=(h?(rob[id].r):(rob[id].l));
		hand=(hand+z)%n;
		cout<<"Robot "<<id<<" moves its "<<(h?"right":"left")<<" hand towards Robot "
		<<hand
		<<".\n";
		--cnt;
	}
	inline Move *clone(){
		return (new Move(*this));
	}
	inline Move *mirror(){
		Move *reans=this->clone();
		reans->h^=1;
		return reans;
	}
};
struct Swap : public Command{
	Swap(){}
//	~Swap(){}
	inline void init(){
		type=SWAP;
		cin>>h>>x>>y;
		z=0;
	}
	inline void recall(int id){
		cout<<"Robot "<<id<<" swaps a line of command with Robot "
		<<(h?(rob[id].r):(rob[id].l))
		<<".\n";
#ifdef LOG_OUT
		flog<<"Robot "<<id<<" swaps a line of command with Robot "
		<<(h?(rob[id].r):(rob[id].l))
		<<".:"
		<<rob[(h?(rob[id].r):(rob[id].l))].c[(this->x)-1]->type<<' ';
		if(rob[(h?(rob[id].r):(rob[id].l))].c[(this->x)-1]->type==TRIGGER)
			flog<<rob[(h?(rob[id].r):(rob[id].l))].c[(this->x)-1]->cmd->type;
		flog<<'\n';
#endif
//		cout<<(h?(rob[id].r):(rob[id].l))<<'\n';
//		cout.flush();
		--cnt;
		swap(rob[id].c[(this->y)-1],rob[(h?(rob[id].r):(rob[id].l))].c[(this->x)-1]);
	}
	inline Swap *clone(){
		return (new Swap(*this));
	}
	inline Swap *mirror(){
		Swap *reans=this->clone();
		reans->h^=1;
		return reans;
	}
};
struct Mirror : public Command{
	Mirror(){}
//	~Mirror(){}
	inline void init(){
		type=MIRROR;
		cin>>h>>x;
		y=z=0;
	}
	inline void recall(int id){
		cout<<"Robot "<<id<<" modifies a line of command of Robot "<<(h?(rob[id].r):(rob[id].l))<<".\n";
		--cnt;
		rob[(h?(rob[id].r):(rob[id].l))].c[(this->x)-1]=(rob[(h?(rob[id].r):(rob[id].l))].c[(this->x)-1])->mirror();
	}
	inline Mirror *clone(){
		return (new Mirror(*this));
	}
	inline Mirror *mirror(){
		Mirror *reans=this->clone();
		reans->h^=1;
		return reans;
	}
};
struct Replace : public Command{
	Replace(){}
//	~Replace(){delete cmd;}
	inline void init();
	inline void recall(int id){
		cout<<"Robot "<<id<<" replaces a line of command of Robot "<<(h?(rob[id].r):(rob[id].l))<<".\n";
		--cnt;
		rob[(h?(rob[id].r):(rob[id].l))].c[(this->x)-1]=cmd;
	}
	inline Replace *clone(){
		return (new ::Replace(*this));
	}
	inline Replace *mirror(){
		Replace *reans=this->clone();
		reans->h^=1;
		return reans;
	}
};
struct Activate : public Command{
	Activate(){}
//	~Activate(){}
	inline void init(){
		type=ACTIVATE;
		cin>>h;
		x=y=z=0;
	}
	inline void recall(int id){
		cout<<"Robot "<<id<<" activates Robot "<<(h?(rob[id].r):(rob[id].l))<<".\n";
		--cnt;
		int hand=(h?(rob[id].r):(rob[id].l));
		for(int i=0;i<m;i++){
			Command* tcmd=rob[hand].c[i];
			if(tcmd->type==TRIGGER)
				continue;
			tcmd->recall(hand);
			trigger(rob[hand].r,tcmd->type);
//			delete tcmd;
		}
	}
	inline Activate *clone(){
		return (new Activate(*this));
	}
	inline Activate *mirror(){
		Activate *reans=this->clone();
		reans->h^=1;
		return reans;
	}
};
struct Trigger : public Command{
	Trigger(){}
//	~Trigger(){delete cmd;}
	inline void init(){
		type=TRIGGER;
		string cmt;
		cin>>cmt;
		cmt.pop_back();
		x=getcmdtype(cmt);
		cin>>cmt;
		switch(getcmdtype(cmt)){
		case SLACKOFF:
			cmd=new Slackoff;
//			cerr<<"Slackoff\n";
			break;
		case MOVE:
			cmd=new Move;
//			cerr<<"Move\n";
			break;
		case SWAP:
			cmd=new Swap;
//			cerr<<"Swap\n";
			break;
		case MIRROR:
			cmd=new Mirror;
//			cerr<<"Mirror\n";
			break;
		case REPLACE:
			cmd=new Replace;
//			cerr<<"Replace\n";
			break;
		default:
			cerr<<"Not alloc yet.\n";
		}
		cmd->init();
		y=z=0;
	}
	inline Trigger *clone(){
		return (new Trigger(*this));
	}
	inline Trigger *mirror(){
		Trigger *reans=this->clone();
		reans->cmd=(reans->cmd)->mirror();
		return reans;
	}
};
inline void Replace::init(){
	type=REPLACE;
	string cmt;
	cin>>h>>x>>cmt;
	switch(getcmdtype(cmt)){
	case SLACKOFF:
		cmd=new Slackoff;
		break;
	case MOVE:
		cmd=new Move;
		break;
	case SWAP:
		cmd=new Swap;
		break;
	case MIRROR:
		cmd=new Mirror;
		break;
	case REPLACE:
		cmd=new Replace;
		break;
	case ACTIVATE:
		cmd=new Activate;
		break;
	case TRIGGER:
		cmd=new Trigger;
		break;
	}
	cmd->init();
	y=z=0;
}
void check_pointer_good(int x){
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			if(rob[i].c[j]->type==TRIGGER&&!(rob[i].c[j]->cmd)){
				cerr<<"fail the pointer test in line "<<x<<"!\n";
				exit(114514);
			}
	cerr<<"pass the pointer test in line "<<x<<".\n";
}
int main(){
#ifdef FILE_IN
	freopen("5.in","r",stdin);
#endif
#ifdef FILE_OUT
//	freopen("5.out","w",stderr);
	freopen("5.out","w",stdout);
#endif
#ifndef OUTPUT_IMEDT
	cin.tie(nullptr)->sync_with_stdio(false);
#endif
    cin>>n>>m>>k;
    cnt.init();
	for(int i=0;i<n;i++){
		string cmt;
		cin>>rob[i].l>>rob[i].r;
		rob[i].c.resize(m);
		for(int j=0;j<m;j++){
			cin>>cmt;
			switch(getcmdtype(cmt)){
			case SLACKOFF:
				rob[i].c[j]=new Slackoff;
				break;
			case MOVE:
				rob[i].c[j]=new Move;
				break;
			case SWAP:
				rob[i].c[j]=new Swap;
				break;
			case MIRROR:
				rob[i].c[j]=new Mirror;
				break;
			case REPLACE:
				rob[i].c[j]=new Replace;
				break;
			case ACTIVATE:
				rob[i].c[j]=new Activate;
				break;
			case TRIGGER:
				rob[i].c[j]=new Trigger;
				break;
			}
			rob[i].c[j]->init();
		}
	}
#ifdef POINTER_TEST
	check_pointer_good(__LINE__);
#endif
	for(int i=0;;(++i)%=n)
		for(int j=0;j<m;j++){
#ifdef POINTER_TEST
				check_pointer_good(__LINE__);
#endif 
			if(rob[i].c[j]->type==TRIGGER)
				continue;
			rob[i].c[j]->recall(i);
//			cerr<<"recall end.\n";
			if(rob[i].r!=i)
				trigger(rob[i].r,rob[i].c[j]->type);
		}
#ifdef FILE_OUT
	system("fc 5.out 5.ans");
#endif
	return 0;
}
2024/6/7 13:03
加载中...