记录编号 459840 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [SDOI 2010] 猪国杀 最终得分 100
用户昵称 GravatarBaDBoY 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2017-10-16 06:29:25 内存使用 0.00 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int top,thief,n,m,Left,king=1,zpre[11],znxt[11],dis[11][11];;
char Card_heap[2005];
bool like[11],dislike[11],simi_dislike[11];
bool End;
bool nanmanruqin(int) ;
bool wanjianqifa(int) ;
bool Kill(int,int) ;
bool Lets_fight(int,int) ;
char cread() {
	char ch=getchar();
	while(ch==32||ch==10||ch==13) ch=getchar();
	return ch;
}
class PIG {
	private:
		int pre[2005],nxt[2005],tail;
	public:
		char Card[2005],identity[5];
		int id,kill,protect,peach,fight,AOEkill,AOEprotect,wuxiekeji,wuqi,life;
		bool equip,dead;
		void add(char ch) {
			if(ch=='P') ++peach;
			if(ch=='K') ++kill;
			if(ch=='D') ++protect;
			if(ch=='F') ++fight;
			if(ch=='N') ++AOEkill;
			if(ch=='W') ++AOEprotect;
			if(ch=='J') ++wuxiekeji;
			if(ch=='Z') ++wuqi;
		}
		void write() {
			for(int j=nxt[0]; j<=tail; j=nxt[j]) {
				if(nxt[j]>tail) cout<<Card[j];
				else cout<<Card[j]<<" ";
			}
		}
		void reduce(char ch) {
			//cout<<endl<<id<<" "<<ch<<endl;
			//write();
			//cout<<endl;
			if(ch=='P') --peach;
			if(ch=='K') --kill;
			if(ch=='D') --protect;
			if(ch=='F') --fight;
			if(ch=='N') --AOEkill;
			if(ch=='W') --AOEprotect;
			if(ch=='J') --wuxiekeji;
			if(ch=='Z') --wuqi;
			for(int i=nxt[0]; i<=tail; i=nxt[i]) {
				if(Card[i]==ch) {
					pre[nxt[i]]=pre[i],nxt[pre[i]]=nxt[i];
					break;
				}
			}
		}
		void init(int e) {
			scanf("%s",identity);
			equip=false,life=4,id=e;
			kill=protect=peach=AOEkill=AOEprotect=wuxiekeji=wuqi=0;
			for(int i=1; i<=4; ++i) Card[++tail]=cread(),add(Card[tail]);
			for(int i=0; i<=2000; ++i) pre[i]=i-1,nxt[i]=i+1;
		}
		void take_card(int num) {
			//if(num==3) cout<<id<<endl;
			int i;
			for(i=1; i<=num&&top<m; ++i) Card[++tail]=Card_heap[++top],add(Card[tail])/*,cout<<Card[tail]<<" "*/;
			if(i<=num) for( ; i<=num; ++i) Card[++tail]=Card_heap[top],add(Card[tail])/*,cout<<Card[tail]<<" "*/;
			//cout<<endl;
		}
		void punish() {
			nxt[0]=tail+1;
			pre[tail+1]=0;
			equip=kill=protect=peach=AOEkill=AOEprotect=wuxiekeji=wuqi=0;
		}
		bool eat_peach() {
			if(life==4||!peach) return false;
			++life,reduce('P');
			return true;
		}
		void Equip() {
			if(!wuqi) return ;
			reduce('Z'),equip=true;
		}
		bool action() {
			bool used_kill=false;
			while(true) {
				bool if_action=false;
				for(int i=nxt[0]; i<=tail; i=nxt[i]) {
					if(life<=0) {if_action=false; break;}
					if(Card[i]=='N') {
						reduce(Card[i]);
						bool now=nanmanruqin(id);
						if(now) return true;
						if_action=true;
						break;
					}
					if(Card[i]=='W') {
						reduce(Card[i]);
						bool now=wanjianqifa(id);
						if(now) return true;
						if_action=true;
						break;
					}
					if(Card[i]=='P') {
						eat_peach();
						//if_action=true;
						//break;
						continue;
					}
					if(Card[i]=='Z') {
						Equip();
						if_action=true;
						break;
						//continue;
					}
					if(Card[i]=='K') {
						if(!used_kill||equip) {
							bool now=false;
							if(identity[0]=='M'&&(dislike[znxt[id]]||simi_dislike[znxt[id]])) {
								now=Kill(id,znxt[id]);
								if(now) return true;
								used_kill=if_action=true;
								break;
							}	
							if(identity[0]=='Z'&&dislike[znxt[id]]) {
								now=Kill(id,znxt[id]);
								if(now) return true;
								used_kill=if_action=true;
								break;
							}
							if(identity[0]=='F'&&(like[znxt[id]]||znxt[id]==1)) {
								now=Kill(id,znxt[id]);
								if(now) return true;
								used_kill=if_action=true;
								break;
							}
						}
						continue;
					}
					if(Card[i]=='F') {
						if(identity[0]=='M') {
							int ji=0;
							for(int i=znxt[id]; i!=id; i=znxt[i]) {
								if(dislike[i]||simi_dislike[i]) {
									ji=i;
									break;
								}
							}
							if(ji!=0) {
								bool now=Lets_fight(id,ji);
								if(now) return true;
								if_action=true;
								break;
							} 
							continue;
						}
						if(identity[0]=='Z') {
							int ji=0;
							for(int i=znxt[id]; i!=id; i=znxt[i]) if(dislike[i]) {
								ji=i;
								break;
							}
							if(ji!=0) {
								bool now=Lets_fight(id,ji);
								if(now) return true;
								if_action=true;
								break;
							} 
							continue;
						}
						if(identity[0]=='F') {
							bool now=Lets_fight(id,1);
							if(now) return true;
							if_action=true;
							break;
						}
					}
				}
				//cout<<if_action<<endl;
				if(if_action) continue;
				else break;
			}
			return false;
		}
} pig[11];
 
 
void divide_dis() {
	memset(dis,0x5f,sizeof(dis));
	int ji=0;
	for(register int i=1,now=0; i<=n; i=znxt[i],now=0) {
		if(i==1&&!ji) ++ji;
		if(i==1&&ji) break;
		for(register int j=znxt[i]; j<=n; ++j) dis[i][j]=++now,dis[j][i]=Left-now;
	}
}
int If_end() {
	if(!king) return 1;
	if(!thief) return 2;
	return 0;
}
bool Be_killed(int who,int who_kill) {
	if(pig[who].life>0) return false;
	--Left,pig[who].dead=true;
	if(pig[who].identity[0]=='M') --king;
	if(pig[who].identity[0]=='F') --thief;
	if(If_end()) {
		End=true;
		return true;
	}
	if(pig[who].identity[0]=='F') pig[who_kill].take_card(3);
	if(pig[who].identity[0]=='Z'&&pig[who_kill].identity[0]=='M') pig[who_kill].punish();
	zpre[znxt[who]]=zpre[who],znxt[zpre[who]]=znxt[who];
	divide_dis();
	return false;
}
void Start_init() {
	scanf("%d%d",&n,&m);
	Left=n;
	for(int i=1; i<=n; ++i) {
		pig[i].init(i);
		if(pig[i].identity[0]=='F') ++thief;
	}
	for(int i=1; i<=n; ++i) zpre[i]=i-1,znxt[i]=i+1;
	znxt[n]=1,zpre[1]=n;
	divide_dis();
	for(int i=1; i<=m; ++i) Card_heap[i]=cread();
}
bool love(int fr,int to) {
	if(pig[fr].identity[0]=='Z'&&(pig[to].id==1||like[to])) return true;
	if(pig[fr].id==1&&(like[to]||pig[to].id==1)) return true;
	if(pig[fr].identity[0]=='F'&&dislike[to]) return true;
	return false;
}
bool hate(int fr,int to) {
	if(pig[fr].identity[0]=='F'&&(pig[to].id==1||like[to])) return true;
	if(pig[fr].id==1&&dislike[to]) return true;
	if(pig[fr].identity[0]=='Z'&&dislike[to]) return true;
	return false;
}
void make(int fr) {
	if(pig[fr].identity[0]=='Z') like[fr]=true,dislike[fr]=false,simi_dislike[fr]=false;
	if(pig[fr].identity[0]=='F') like[fr]=false,dislike[fr]=true,simi_dislike[fr]=false;
}
bool wuxie(int now,int to,bool sta) { // 1 被攻击 0 已经被无懈 
	if(!like[to]&&!dislike[to]&&pig[to].id!=1) return 0;
	for(int i=now,bo=0; i!=now||bo==0; i=znxt[i]) {
		bo=1;
		if(!pig[i].wuxiekeji) continue;
		//printf("i=%d\n",i);
		if(love(i,to)&&sta) {make(i);pig[i].reduce('J');return wuxie(znxt[i],i,0)^1;}
		if(hate(i,to)&&!sta) {make(i);pig[i].reduce('J');return wuxie(znxt[i],i,0)^1;}
	}
	return 0;
}
int Main() {
	freopen("kopk.in","r",stdin);
	freopen("kopk.out","w",stdout);
	Start_init();
	for(int i=1,ji=1; !End; i=znxt[i],++ji) {
		//cout<<"Round "<<ji<<endl;
		pig[i].take_card(2);
		pig[i].action();
		//cout<<""<<i<<endl;
		/*for(int j=1; j<=n; ++j,cout<<endl) {
			cout<<pig[j].life<<" "<<pig[j].identity<<" "<<like[j]<<" "<<dislike[j]<<" "<<simi_dislike[j]<<" "<<pig[j].equip<<"   ";
			pig[j].write();
		}
		//cout<<i<<endl;
		system("pause");*/
	}
	if(If_end()==1) printf("FP\n");
	else printf("MP\n");
	for(int i=1; i<=n; ++i,printf("\n")) {
		if(pig[i].dead) printf("DEAD");
		else pig[i].write();
	}
	return 0;
}
int hehe=Main();
int main(){;}
bool nanmanruqin(int who_use) {
	for(int i=znxt[who_use]; i!=who_use; i=znxt[i]) {
		if(wuxie(who_use,i,true)) continue;
		if(!pig[i].kill) {
			--pig[i].life;
			if(!pig[i].life) {
				if(!pig[i].eat_peach())
					if(Be_killed(i,who_use))return true;
			}
			if(i==1) simi_dislike[who_use]=true;
		}
		if(pig[i].kill) pig[i].reduce('K');
	}
	return false;
}
bool wanjianqifa(int who_use) {
	for(int i=znxt[who_use]; i!=who_use; i=znxt[i]) {
		if(wuxie(who_use,i,true)) continue;
		if(!pig[i].protect) {
			--pig[i].life;
			if(!pig[i].life) {
				if(!pig[i].eat_peach()) {
					if(Be_killed(i,who_use))return true;
				}
			}
			if(i==1) simi_dislike[who_use]=true;
		} else pig[i].reduce('D');
	}
	return false;
}
bool Kill(int fr,int to) {
	pig[fr].reduce('K');
	if(!pig[to].protect) {
		--pig[to].life;
		if(!pig[to].life) {
			if(!pig[to].eat_peach()) {
				bool now=Be_killed(to,fr);
				if(now) {
					End=true;
					return true;
				}
			}
		}
	} else pig[to].reduce('D');
	if(pig[to].identity[0]=='M'||like[to]) dislike[fr]=true;
	if(dislike[to]) like[fr]=true;
	return false;
}
bool Lets_fight(int fr,int to) {
	if(pig[to].id==1||like[to]) dislike[fr]=true;
	if(dislike[to]) like[fr]=true;
	pig[fr].reduce('F');
	if(wuxie(fr,to,true)) return false;
	if((fr==1&&pig[to].identity[0]=='Z')) {
		--pig[to].life;
		if(!pig[to].life) if(!pig[to].eat_peach()) Be_killed(to,fr);
		return false;
	}
	int now=1;
	while(true) {
		int dd=now?to:fr;
		if(pig[dd].kill) {
			pig[dd].reduce('K');
			now^=1;
			continue;
		}
		if(!pig[dd].kill) {
			--pig[dd].life;
			if(!pig[dd].life) {
				if(pig[dd].eat_peach()) break;
				else {
					bool ss=Be_killed(dd,dd==fr?to:fr);
					if(ss) return true;
				}
			}
			break;
		}
		now^=1;
	}
	
	return false;
}