玄关求调,为什么下载样例过了但是超时
查看原帖
玄关求调,为什么下载样例过了但是超时
927833
1835202011qwe楼主2025/1/20 07:47
#include<bits/stdc++.h>
using namespace std;
//杀  闪  桃  决斗  南猪  万箭  无懈  连弩 
//K   D   P   F     N     W     J     Z 
struct Si{
	int sf,xl,ps;//0主公 1忠 2反   xl:血量   ps:牌数 
	char pa[200010];//牌 
	bool zb;//zb true 有猪哥连弩Z   
}pi[15];int ts[15];//ts:跳身份 0没身份 1类反 2反 3忠 4主 
bool zt[15];//zt true 活着
void sp(int nu,int si){//删去pi[nu]的第si张牌 
	int i;
	for(i=si;i<pi[nu].ps;i++)pi[nu].pa[i]=pi[nu].pa[i+1];
	pi[nu].pa[pi[nu].ps]=' ';
	pi[nu].ps--;
}
int n,m,men=0;//men:摸到第men张牌 
int fnu=0,sfn=0;//fnu:反数量  sfn:死的反猪数量 
char me[2010];//me:没摸的牌
void mp(int nu){//摸2牌 
	if(men+1<=m)pi[nu].pa[++pi[nu].ps]=me[++men];
	else pi[nu].pa[++pi[nu].ps]=me[men];
	if(men+1<=m)pi[nu].pa[++pi[nu].ps]=me[++men];
	else pi[nu].pa[++pi[nu].ps]=me[men];
}void mp3(int nu){//摸3牌 
	if(men+1<=m)pi[nu].pa[++pi[nu].ps]=me[++men];
	else pi[nu].pa[++pi[nu].ps]=me[men];
	if(men+1<=m)pi[nu].pa[++pi[nu].ps]=me[++men];
	else pi[nu].pa[++pi[nu].ps]=me[men];
	if(men+1<=m)pi[nu].pa[++pi[nu].ps]=me[++men];
	else pi[nu].pa[++pi[nu].ps]=me[men];
}
void out(){//输出 
	int i,j;
	for(i=1;i<=n;i++){
		if(zt[i])for(j=1;j<=pi[i].ps;j++)printf("%c ",pi[i].pa[j]);
		else printf("DEAD");
		printf("\n");
	}
}
void dead(int kier,int bekier){//kier杀掉bekier 
	zt[bekier]=false;
	if(pi[bekier].sf==2){
		sfn++;
		if(sfn==fnu){
			cout<<"MP"<<endl;
			out();exit(0);
		}
		mp3(kier);
	}else if(pi[bekier].sf==0){
		cout<<"FP"<<endl;
		out();exit(0);
	}else if(pi[bekier].sf==1&&kier==1){
		int i;
		for(i=1;i<=pi[1].ps;i++){
			pi[1].pa[i]=' ';
		}pi[1].ps=0;
		pi[1].zb=false;
	}
}void widead(int kier,int bekier){
	int i;
	for(i=1;i<=pi[bekier].ps;i++){
		if(pi[bekier].pa[i]=='P'){
			sp(bekier,i);pi[bekier].xl++;
			return;
		}
	}dead(kier,bekier);
}
void facek(int user,int nu){//user给第nu只猪吃杀 
	int i;
	for(i=1;i<=pi[nu].ps;i++){
		if(pi[nu].pa[i]=='D'){
			sp(nu,i);return;
		}
	}pi[nu].xl--;
	if(pi[nu].xl==0){
		widead(user,nu);
	}
}
void jue(int user,int beu){//user对beu使用决斗 
	bool ch=false;//false beu出  true user出 
	int i,j;
	if(user==1&&pi[beu].sf==1){
		pi[beu].xl--;
		if(pi[beu].xl==0)widead(user,beu);
		return;
	}
	while(1){
		if(ch){
			for(i=1;i<=pi[user].ps;i++)if(pi[user].pa[i]=='K'){sp(user,i);ch=false;break;}
			if(ch){
				pi[user].xl--;
				if(pi[user].xl==0)widead(beu,user);
				return;
			}
		}else{
			for(i=1;i<=pi[beu].ps;i++)if(pi[beu].pa[i]=='K'){sp(beu,i);ch=true;break;}
			if(!ch){
				pi[beu].xl--;
				if(pi[beu].xl==0)widead(user,beu);
				return;
			}
		}
	}
}
void nan(int user,int beu){//user对beu使用南 
	int i;
	for(i=1;i<=pi[beu].ps;i++)if(pi[beu].pa[i]=='K'){sp(beu,i);return;}
	pi[beu].xl--;
	if(beu==1&&ts[user]!=3&&ts[user]!=2)ts[user]=1;
	if(pi[beu].xl==0) widead(user,beu);
}
void wan(int user,int beu){//user对beu使用万 
	int i;
	for(i=1;i<=pi[beu].ps;i++)if(pi[beu].pa[i]=='D'){sp(beu,i);return;}
	pi[beu].xl--;
	if(beu==1&&ts[user]!=3&&ts[user]!=2)ts[user]=1;
	if(pi[beu].xl==0) widead(user,beu);	
}bool wu_w(int user){//无懈user的无懈 true:用了无懈 
	int i,j;
	for(i=user+1;i!=user;i++){i=(i-1)%n+1;
		if((pi[i].sf==0||pi[i].sf==1)&&(ts[user]==2)){
			for(j=1;j<=pi[i].ps;j++){
				if(pi[i].pa[j]=='J'){
					ts[i]=2;sp(i,j);
					if(wu_w(i))return false;
					else return true;
				}
			}
		}else if(pi[i].sf==2&&(ts[user]==3||ts[user]==4)){
			for(j=1;j<=pi[i].ps;j++){
				if(pi[i].pa[j]=='J'){
					ts[i]=2;sp(i,j);
					if(wu_w(i))return false;
					else return true;
				}
			}			
		}
	}
	return false;
}
bool wu(int beu){//无懈对beu的锦囊(非无懈)
	int i,j;//cout<<"*************************"<<endl;
	if(ts[beu]==0||ts[beu]==1)return false;	
	if(ts[beu]!=0&&ts[beu]!=1){
		for(j=1;j<=pi[beu].ps;j++){
			if(pi[beu].pa[j]=='J'){
				sp(beu,j);
				if(wu_w(beu))return false;
				else return true;
			}
		}
	}
	for(i=beu+1;i!=beu;i++,i=(i-1)%n+1){//cout<<' '<<beu;
		if((pi[i].sf==0||pi[i].sf==1)&&(ts[beu]==3||ts[beu]==4)){
			for(j=1;j<=pi[i].ps;j++){
				if(pi[i].pa[j]=='J'){
					if(ts[i]!=4)ts[i]=3;
					sp(i,j);
					if(wu_w(i))return false;
					else return true;
				}
			}
		}
		else if(pi[i].sf==2&&ts[beu]==2){
			for(j=1;j<=pi[i].pa[j];j++){
				if(pi[i].pa[j]=='J'){
					ts[i]=2;sp(i,j);
					if(wu_w(i))return false;
					else return true;
				}
			}
		}
	}
	return false;
}
void chu(int nu){//第nu只出牌 
	int i,j;mp(nu);bool cs=false;//本回合是否出过杀 
	for(i=1;i<=pi[nu].ps;i++){//cout<<pi[nu].zb<<endl;cout<<ts[1]<<'&'<<ts[2]<<'&'<<ts[3]<<'&'<<ts[4]<<'&'<<ts[5]<<endl;cout<<'*'<<nu<<'*'<<i<<'*'<<endl<<pi[1].xl<<'*'<<pi[2].xl<<'*'<<pi[3].xl<<'*'<<pi[4].xl<<'*'<<pi[5].xl<<endl;out();cout<<endl;
	
		if(pi[nu].pa[i]=='P'){
			if(pi[nu].xl<4){
				sp(nu,i);
				pi[nu].xl++;
				i--;
			}
		}
		else if(pi[nu].pa[i]=='Z'){//连弩 
			sp(nu,i);//cout<<1<<endl;
			if(!pi[nu].zb){
				pi[nu].zb=true;
				i=0; 
			}else i--;
		}else if(pi[nu].pa[i]=='K'){
			if(pi[nu].sf==0){//主公出杀 
				int t;
				for(j=2;j<=n;j++)if(zt[j]){t=j;break;}
				if((ts[t]==1||ts[t]==2)&&(!cs||pi[i].zb)){
					sp(1,i);facek(1,t);cs=true;i--;
				}				
			}else if(pi[nu].sf==1){//忠出杀 
				int t=-1;
				for(j=nu+1;j!=nu;j++){j=(j-1)%n+1;if(zt[j]){t=j;break;}}
				if((t!=-1)&&ts[t]==2&&(!cs||pi[i].zb)){
					sp(nu,i);facek(nu,t);cs=true;ts[nu]=3;i--;
				}
			}else if(pi[nu].sf==2){//反出杀 
				int t1;
				for(j=nu+1;;j++){j=(j-1)%n+1;if(zt[j]){t1=j;break;}}
				if(ts[t1]==4&&(!cs||pi[nu].zb)){sp(nu,i);facek(nu,t1);cs=true;ts[nu]=2;i--;}
				else if(ts[t1]==3&&(!cs||pi[nu].zb)){sp(nu,i);facek(nu,t1);cs=true;ts[nu]=2;i--;}
			}
		}
		if(pi[nu].pa[i]=='F'){//决斗 
			if(pi[nu].sf==2){
				sp(nu,i);ts[nu]=2;i=0;
				if(!(wu(1)))jue(nu,1);
			}else if(pi[nu].sf==1){
				int t=-1;
				for(j=nu+1;j!=nu;j++){j=(j-1)%n+1;if(ts[j]==2){t=j;break;}}
				if(t!=-1){
					ts[nu]=3;sp(nu,i);i=0;
					if(!(wu(t)))jue(nu,t);
				}
			}else if(pi[nu].sf==0){
				int t=-1;
				for(j=nu+1;j!=nu;j=(j)%n+1){if(ts[j]==2||ts[j]==1){t=j;break;}}
				if(t!=-1){
					sp(nu,i);i=0;
					if(!(wu(t)))jue(nu,t);
				}
			}if(!zt[nu])break;
		}
		else if(pi[nu].pa[i]=='N'){//南猪 
			for(j=nu+1;j!=nu;j++){
				j=(j-1)%n+1;
				if(!(wu(j)))nan(nu,j);
			}sp(nu,i);i--;
		}else if(pi[nu].pa[i]=='W'){//万箭 
			for(j=nu+1;j!=nu;j++){
				j=(j-1)%n+1;
				if(!(wu(j)))wan(nu,j);
			}sp(nu,i);i--;
		}
	}
}
void xd(){//主运行函数 
	int i=0;
	while(1){
		i++;
		i=(i-1)%n+1;//cout<<'&'<<zt[i]<<'&'<<endl;
		if(zt[i])chu(i);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	getchar();
	int i,j;string tts;
	for(i=1;i<=n;i++){
		getline(cin,tts,'\n');
		if(tts[0]=='M')pi[i].sf=0;
		else if(tts[0]=='Z')pi[i].sf=1;
		else pi[i].sf=2,fnu++;
		pi[i].ps=4;zt[i]=true;pi[i].xl=4;pi[i].zb=false;
		pi[i].pa[1]=tts[3];pi[i].pa[2]=tts[5];
		pi[i].pa[3]=tts[7];pi[i].pa[4]=tts[9];
	}ts[1]=4;
	for(i=1;i<=m;i++)cin>>me[i];
	if(fnu==0){
		out();return 0;
	}
	xd();
	return 0;
}
5 2000
MP K K P P
FP D K D K
ZP P P D K
FP D K P D
FP P K P P
D D D P D K P P D D P D D K P P D P D P P K K P D P K D P P D Z P P P K P P D P K K Z K K P D K K P D Z K D P D P K P P K K D P P K P P P P K P K P D K K D P D K D P K Z K K K K D D K K Z P K D D P K P D K Z K P P P K D P K P K K P K Z D K Z K D P P K D P K K D D D D P K D K D K Z D K D P P Z D P K P P P K D D D D K P K K D D K D K P D P D D K D P K P P K P P D P K P K K K D P K D D P K K K K P K D Z K K P K P Z K D P P P P D P P Z P K K P D K K D D Z D K P P D P D Z P D P Z K K P K Z D D D D P P P K P D P D K K Z P K Z D K D D P K K D K K P D K P K K D P K P Z D P P P P P D P K K D Z K D P D K K P Z P P D D K K Z P D P P D P D P D P P D K P D P P Z K K D D D K K K Z P K P D P K K D P K D P D D K D D P K K P P K K P K D P K P K P D D D P D K D P Z D P K D D D K D D Z D P K D K K P D D K K D P P K D D K K K P P P D K P Z P P P P K P D D K D D K D K P K P P K Z K P D K P K D K K P Z K D P P K P K P P K K K D K P K P P K D K K Z K P P D D K K P D P D D P K K P D P P K P D K P P K K P D D P K P K P P K P P K K D D D D P K P P Z D K K D K P P P K K P P K D K D K P D Z D K P K P P P K D Z D Z P K K D K D K P P D P P P P D D K P D D D K P D D D K K K K D D D P P K P P K P D P P P D P P D D P P Z Z P K D K D K K K K P K K D D P K K K K K P D K K K P K Z P D K P P K P K D K P D K P K D K D P K K Z P K P Z D D P K D D D K D K D P D D K P D K Z P K P D K Z D K D D P D D D P D D P P P D K D K D P Z P D D D D P D D D D K K P D D P D K D D P P D D K K P K D P P D Z K P D K K D P K K Z P D D P K P D K Z D P P D P K P D P P Z P P P K D P D Z P K P P K D K D K Z K K D P P D D D K P D K D P K D D K K P P D P P P K D P K D P D P D Z D K D P D K D P P K D P K D K K K P Z K D P Z P K P P K D K K D K P D P P P D K P K P D P P D D P P Z P Z K P P D D P P P K P K Z P D D D K P P P D K P K D D K D P D K Z P D P D P D P K P P P K D D D P K P P P D K K D K K K Z K P K K K K P K K P Z D D P D P D D P P D D D D K K D K K P K K P K K P D D D P P K D D K K P K K Z D P D K K K D P P P K P K P P D P D D K P P K D K K K P P K K D P D P D D P D P P K P P K D K D P P D K K P P P P P P P D P K D D K D P K D P P P D D K K Z P Z K D P D P K P K D D D Z D P K K K K K P P D K D D P P P P K K P K K D D P D D D D K P P P K K D P D P K K D P P Z D P P D D K P Z K P P P P D K D P D Z K Z K Z D D K P D D P D P D K K P K K P D P D K P P D P P D K K D K P K D K P D D D D D P K P D D K D P P P K D Z K K P D K D P P D D P P D K K P P P P P D K P K D K K D P D D P P D Z D P K K K K P Z K P P Z D P P P K K D K K P D K P D P P K D K P D K K K K D P K K Z D D D P P D P Z K D P P D P K P P Z D K K P D K P P Z D D K K P D D P K K D P K K D Z D P Z D P K D P Z K P K D K P D D D D P P Z K D D D P P K D D K D P P K K Z K D D P K K D P K P D D P P K P P D D P P K P K P P K Z K Z P D P D P D P P D P K K P P P K K P K P K K K D P D P P D P K D P Z D P K K P P K K D P K P D K D K D D K D P K D P P K K D K K D P K P K Z D P D P P K D P K K K P P P K P D P P K D D D K D K K P P K Z D K K K P K K P K K D D K P K D K K P P K D P K D K P K K P K K D Z P P P D D P D D P P P P K D K P K K P K P K P K K K P K P D K K K K P Z D K P D P D K P K P P P P K D P D P Z K Z D K D D K P P P D P D D K K Z D Z Z P D K P D D P K P D D K P P D K Z P P Z D P D K K K D D D D P D K K P K K K P K P D P K P K D D K K P D P D P Z P P K P K D K D D P K P D K P D K D K D P K D P D P K K Z P P K D P D K D D K D K D K K K P Z P P P D Z D D K P Z P D K K P K D P D D D D D P P K D K K K P D P D P D P K K P K K K P D D K D D D P P K K K P K K P D P D K D K P Z K P K D K P K P K K D K D P D Z P Z P K D K D K D P K D D K D P D D K K D P D D P D D P P K P K D P K D D D D D Z K K K P D P Z D K K K K P D K K K D D P D K D P K P P P P P D D K P P K P D K P K P D P D D K K P K P P Z D P D P D P K P K D P D K P P P P P D D K D P D D D D P P D K D P D K P K P P P K P P K P P P P D K P D K P K K P P D P D K P Z K D D P P P K P P P P K Z D D P D K P K K K Z D D Z D D K D P D K D K K D K D P P D K P K D K P P K D D D D K D P D D Z K

FP
DEAD
D K D K D P D K K P P P K K D D P K P P K K K P K D P D D K D P K D D K D P K D P K K P P D K D P P K K P D K P P K K P D P D K D D P K K D P K D P D D D K P K D K D D P P D K P K K P P D P K K P P K D D K D K D P K P K P P D K D D D P P K K K K P K P K K K D D K K P D D P D D K D K D K D K P K P D P K D D D D K D P K D P K P D K K P P K P P P P D P K K P K K P P P K P D P K P P D K P K D P P P P P K D P D D K P P K D D P D P P P P K P D D K D K D D P P D P P P K K D P P K P K P K K D D K D K P K K D D D D P K K P K D D K P D P K P D K P K D P P P K P K P P P P K P K K P K P D K D P K K K K P D P P P D K P P P D D K P D K P K P D K D K D D K D P K P K P D D D K P K P P K P D D P D K D K K K K D K D D K P P P P K P D P P P P P D P D P P D D D D D K P K D K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K
P P D K D K P P D P P K K P P D P K D K K P K K P K P P K P K P P D D K D P K P K K K P K D P K D D D D P K D D K D P D P P P D P D K K K D D P D P D K D K K P D D P K D K K P P P P K D K K P P K P P D P K P K D P P K D P P P D D P P P P P K K P D K D K P D D P D D K D P P D K D P P P P K D K D P D K K P K P K D P D D K P K P D D P K P K D K K P P P P K P D D D K K P K D P K P P P K D P K D K D P P P K D D P D K P D K P K D D D K D D K K P P P K P K K D P D P P D P K K D P D K D K D D P P K P K P K D P D D P K K P D P P P P K P K P K P K K D K K D K K K D K K K P P K P D P K P K K P K P K P D P D D D D P K P K P P K K P P D P D K K D K D P D K P K K D K K K K D K D K D D P P K K P P D D P K P D P D D P D K D K P K K P P D P K P D D K D D K D P K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K
D K P D P P D P K D P P D K P K P P K D K K D D P P K D P D K D D D K P P P K K K K P P D P D D D D K D P P K P P K D D D P D P P K P K K K K P D P D D D D K K P P D K K P K K K D K K P D P K P K P K P P P K P P K K D D D D D P K D P K D K D D K P P P K K P K D K D D P P D D K P P D D K D P P K K K D K P D P D K D K K P P P P P D P D P D P K P D P K D K K K D P D D P K D D D K K P K D P D P P K P K D P D P D D P K D K K P P K D K P D P K P P K D P D K P D K D P P D D D K K P P P D K K D P D P D K D D D K P P P D D D D D P K P D P K P K K D P K D D K D K P D P P D D D K D D K D K K D D K K P K D K P P D P D D K K P P D D K D P D P D K D K P K K D P P D D K K K P D D P D P K K D K D P D D D D D D P K K K P P K D D P D D K D P D P P P D K K P P P K P D K K D P P D D K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K
P P P D D D P P P D P P P P P P P D D P D D D P P D P P D P P D P D P D P D P P P D P D P D P P P P D D P P P D D D P D D P P D D P P D D P P P P P D D D P P D D D P P D D D D D D D P P D P P P P P P D P D P P P P D P P P D P D D P D P D D D D P D D D D D P P P D P D D P P D D P D P D D P P P D D D P P D P D D P P D P P P P P P D P D P P P P P D D P P P D P P P D P D P D P D P P P D P P D P P P P D P D P D D P D P D P P D P D D D D P P P D D D P D P P P D D P D D D P P D D D D P P P D P D P P D D D P P P P D P P P D

2025/1/20 07:47
加载中...