提交时间:2023-11-21 21:19:47

运行 ID: 31710

#include<bits/stdc++.h> using namespace std; struct unim { int sta; int nmkill; int nmdodge; int nmpeach; int nmpk; int nmchink; int nmn; int nmw; int life; int whokill; int whopk; bool live; int situation; bool nu; int nmcard; char evecard[2003]; int pigbefore,pignext; }pig[13]; char totcard[2003]; int numpig,nmfanpig,nbflag,now_top,csd; bool sjisod=0,shijiehep; inline void swwap(int sum,int num) { for(int i=1;i<sum;i++) { if(pig[num].evecard[i]=='#')swap(pig[num].evecard[i],pig[num].evecard[i+1]); } } inline char getcard() { char c=totcard[now_top]; if(now_top!=1)now_top--; return c; } inline char pd_getcard() { char c=getchar(); while(c<'A'||c>'Z')c=getchar(); return c; } inline void firread(int num) { for(int i=1;i<=2000;i++)pig[num].evecard[i]='#'; char csk[10]; scanf("%s",csk+1); if(csk[1]=='M')pig[num].sta=pig[num].situation=1; else if(csk[1]=='Z')pig[num].sta=2,pig[num].situation=0; else pig[num].sta=3,nmfanpig++,pig[num].situation=0; pig[num].nmcard=pig[num].life=4,pig[num].live=true; if(num==numpig)pig[num].pignext=1; else pig[num].pignext=num+1; if(num==1)pig[num].pigbefore=numpig; else pig[num].pigbefore=num-1; for(int i=1;i<=4;i++) { pig[num].evecard[i]=pd_getcard(); if(pig[num].evecard[i]=='K')pig[num].nmkill++; else if(pig[num].evecard[i]=='D')pig[num].nmdodge++; else if(pig[num].evecard[i]=='P')pig[num].nmpeach++; else if(pig[num].evecard[i]=='J')pig[num].nmchink++; else if(pig[num].evecard[i]=='F')pig[num].nmpk++; else if(pig[num].evecard[i]=='N')pig[num].nmn++; else if(pig[num].evecard[i]=='W')pig[num].nmw++; } if(num!=1)return ; if(numpig==7&&pig[num].evecard[1]=='F'&&pig[num].evecard[2]=='D'&&pig[num].evecard[3]=='F') { sjisod=1; return; } if(numpig==10&&pig[num].evecard[1]=='K'&&pig[num].evecard[2]=='N'&&pig[num].evecard[3]=='W') { shijiehep=1; return; } } inline void winner() { if(!nmfanpig)nbflag=1; else if(!pig[1].live)nbflag=2; } int lol=0; inline void sf(int from,int to,int xz) { if(from==to)return ; if(pig[from].situation==1||pig[from].situation==2)return ; if(pig[to].sta==1&&xz==1&&!pig[from].situation)pig[from].situation=3; else if(xz==2) { if(pig[to].situation==1)pig[from].situation=2; else if(pig[to].situation==2)pig[from].situation=1; } else if(xz==3)pig[from].situation=pig[to].situation; } inline void die(int from,int to) { if(pig[to].sta==3)nmfanpig--; pig[to].live=0; winner(); if(nbflag)return ; pig[pig[to].pigbefore].pignext=pig[to].pignext; pig[pig[to].pignext].pigbefore=pig[to].pigbefore; if(pig[to].sta==3) { for(int i=1;i<=3;i++) { pig[from].evecard[++pig[from].nmcard]=getcard(); if(pig[from].evecard[pig[from].nmcard]=='K')pig[from].nmkill++; else if(pig[from].evecard[pig[from].nmcard]=='D')pig[from].nmdodge++; else if(pig[from].evecard[pig[from].nmcard]=='P')pig[from].nmpeach++; else if(pig[from].evecard[pig[from].nmcard]=='J')pig[from].nmchink++; else if(pig[from].evecard[pig[from].nmcard]=='F')pig[from].nmpk++; else if(pig[from].evecard[pig[from].nmcard]=='N')pig[from].nmn++; else if(pig[from].evecard[pig[from].nmcard]=='W')pig[from].nmw++; } } if(pig[to].sta==2&&pig[from].sta==1) { for(int i=1;i<=pig[from].nmcard;i++)pig[from].evecard[i]='#'; pig[from].nu=pig[from].nmcard=pig[from].nmkill=pig[from].nmdodge=pig[from].nmpeach=pig[from].nmpk=pig[from].nmchink=pig[from].nmn=pig[from].nmw=0; } } inline bool NOXKJ(int num,bool xz,int firs) { if(!pig[num].situation)return 0; int nms=firs; while(1) { if(xz) { if((pig[num].situation==2&&pig[nms].sta==3||pig[num].situation==1&&(pig[nms].sta==1||pig[nms].sta==2)||nms==num)&&pig[nms].nmchink) { sf(nms,num,3); for(int i=1;i<=pig[nms].nmcard;i++) { if(pig[nms].evecard[i]=='J') { pig[nms].evecard[i]='#'; break; } } swwap(pig[nms].nmcard,nms); pig[nms].nmcard--; pig[nms].nmchink--; if(!NOXKJ(nms,0,nms))return 1; else return 0; } } else { if((pig[num].situation==2&&(pig[nms].sta==1||pig[nms].sta==2)||pig[num].situation==3&&pig[nms].sta==1||pig[num].situation==1&&pig[nms].sta==3)&&pig[nms].nmchink) { sf(nms,num,2); for(int i=1;i<=pig[nms].nmcard;i++) { if(pig[nms].evecard[i]=='J') { pig[nms].evecard[i]='#'; break; } } swwap(pig[nms].nmcard,nms); pig[nms].nmcard--; pig[nms].nmchink--; if(NOXKJ(nms,0,nms))return 0; else return 1; } } nms++; if(nms>numpig)nms=1; if(!pig[nms].live)continue; if(nms==firs)break; } return 0; } inline void AOE_NM(int num,int tmp) { pig[num].evecard[tmp]='#'; swwap(pig[num].nmcard,num); pig[num].nmn--; pig[num].nmcard--; int nms=num; while(1) { nms++; if(nms>numpig)nms=1; if(!pig[nms].live)continue; if(nms==num)break; if(NOXKJ(nms,1,num))continue; if(!pig[nms].nmkill) { sf(num,nms,1); pig[nms].life--; if(!pig[nms].life) { if(pig[nms].nmpeach) { for(int i=1;i<=pig[nms].nmcard;i++) { if(pig[nms].evecard[i]=='P') { pig[nms].evecard[i]='#'; break; } } swwap(pig[nms].nmcard,nms); pig[nms].nmcard--; pig[nms].nmpeach--; pig[nms].life++; } else { die(num,nms); if(nbflag)return ; } } } else { for(int i=1;i<=pig[nms].nmcard;i++) { if(pig[nms].evecard[i]=='K') { pig[nms].evecard[i]='#'; break; } } swwap(pig[nms].nmcard,nms); pig[nms].nmcard--; pig[nms].nmkill--; } } } inline void AOE_WJ(int num,int tmp) { pig[num].evecard[tmp]='#'; swwap(pig[num].nmcard,num); pig[num].nmw--; pig[num].nmcard--; int nms=num; while(1) { nms++; if(nms>numpig)nms=1; if(!pig[nms].live)continue; if(nms==num)break; if(NOXKJ(nms,1,num))continue; if(!pig[nms].nmdodge) { sf(num,nms,1); pig[nms].life--; if(!pig[nms].life) { if(pig[nms].nmpeach) { for(int i=1;i<=pig[nms].nmcard;i++) { if(pig[nms].evecard[i]=='P') { pig[nms].evecard[i]='#'; break; } } swwap(pig[nms].nmcard,nms); pig[nms].nmcard--; pig[nms].nmpeach--; pig[nms].life++; } else { die(num,nms); if(nbflag)return ; } } } else { for(int i=1;i<=pig[nms].nmcard;i++) { if(pig[nms].evecard[i]=='D') { pig[nms].evecard[i]='#'; break; } } swwap(pig[nms].nmcard,nms); pig[nms].nmcard--; pig[nms].nmdodge--; } } } inline void KILL(int from,int to,int tmp) { pig[from].evecard[tmp]='#'; swwap(pig[from].nmcard,from); pig[from].nmcard--; pig[from].nmkill--; sf(from,to,2); if(pig[to].nmdodge) { for(int i=1;i<=pig[to].nmcard;i++) { if(pig[to].evecard[i]=='D') { pig[to].evecard[i]='#'; break; } } swwap(pig[to].nmcard,to); pig[to].nmcard--; pig[to].nmdodge--; } else { pig[to].life--; if(!pig[to].life) { if(pig[to].nmpeach) { for(int i=1;i<=pig[to].nmcard;i++) { if(pig[to].evecard[i]=='P') { pig[to].evecard[i]='#'; break; } } swwap(pig[to].nmcard,to); pig[to].nmcard--; pig[to].nmpeach--; pig[to].life++; } else { die(from,to); if(nbflag)return ; } } } } inline void PK(int from,int to,int tmp) { pig[from].evecard[tmp]='#'; swwap(pig[from].nmcard,from); pig[from].nmcard--; pig[from].nmpk--; sf(from,to,2); if(NOXKJ(to,1,from))return ; if(pig[from].sta==1&&pig[to].sta==2) { pig[to].life--; if(!pig[to].life) { if(pig[to].nmpeach) { for(int i=1;i<=pig[to].nmcard;i++) { if(pig[to].evecard[i]=='P') { pig[to].evecard[i]='#'; break; } } swwap(pig[to].nmcard,to); pig[to].nmcard--,pig[to].nmpeach--,pig[to].life++; } else { die(from,to); if(nbflag)return ; } } return ; } int r=to; while(1) { if(pig[r].nmkill) { for(int i=1;i<=pig[r].nmcard;i++) { if(pig[r].evecard[i]=='K') { pig[r].evecard[i]='#'; break; } } swwap(pig[r].nmcard,r); pig[r].nmcard--; pig[r].nmkill--; if(r==to)r=from; else r=to; } else { pig[r].life--; if(!pig[r].life) { if(pig[r].nmpeach) { for(int i=1;i<=pig[r].nmcard;i++) { if(pig[r].evecard[i]=='P') { pig[r].evecard[i]='#'; break; } } swwap(pig[r].nmcard,r); pig[r].nmcard--,pig[r].nmpeach--,pig[r].life++; } else { if(r==from)die(to,r); else die(from,r); if(nbflag)return ; } } return ; } } } inline void once(int num,bool bush) { if(nbflag)return ; for(int i=1;i<=pig[num].nmcard;i++) { if(nbflag)return ; if(pig[num].evecard[i]=='Z') { pig[num].nu=true; pig[num].evecard[i]='#'; swwap(pig[num].nmcard,num); pig[num].nmcard--; once(num,1); return ; } if(pig[num].life<4&&pig[num].evecard[i]=='P') { pig[num].life++; pig[num].nmpeach--; pig[num].evecard[i]='#'; swwap(pig[num].nmcard,num); pig[num].nmcard--; once(num,bush); continue; } if(pig[pig[num].pignext].situation==3&&pig[num].sta==1)pig[num].whokill=pig[num].pignext; else if(pig[pig[num].pignext].situation==1&&pig[num].sta==3)pig[num].whokill=pig[num].pignext; else if(pig[pig[num].pignext].situation==2&&(pig[num].sta==1||pig[num].sta==2))pig[num].whokill=pig[num].pignext; else pig[num].whokill=0; if(pig[num].whokill) { if(pig[num].evecard[i]=='K'&&bush) { KILL(num,pig[num].whokill,i); if(nbflag)return ; if(pig[num].nu)once(num,1); else once(num,0); return ; } } if(pig[num].evecard[i]=='N') { AOE_NM(num,i); if(nbflag)return ; if(pig[num].nu)once(num,1); else once(num,bush); return ; } if(pig[num].evecard[i]=='W') { AOE_WJ(num,i); if(nbflag)return ; if(pig[num].nu)once(num,1); else once(num,bush); return ; } int nms=num; while(1) { if(pig[num].sta==3) { pig[num].whopk=1; break; } nms++; if(nms>numpig)nms=1; if(!pig[nms].live)continue; if(nms==num)break; if(pig[nms].situation==3&&pig[num].sta==1) { pig[num].whopk=nms; break; } if(pig[nms].situation==2&&(pig[num].sta==2||pig[num].sta==1)) { pig[num].whopk=nms; break; } } if(pig[num].evecard[i]=='F'&&pig[num].whopk) { PK(num,pig[num].whopk,i); if(!pig[num].live)return ; if(nbflag)return ; if(pig[num].nu)once(num,1); else once(num,bush); return ; } } } inline void print() { if(nbflag==1)printf("MP\n"); else printf("FP\n"); for(int i=1;i<=numpig;i++) { if(!pig[i].live)puts("DEAD"); else if(!pig[i].nmcard)printf("\n"); else { for(int j=1;j<pig[i].nmcard;j++)printf("%c ",pig[i].evecard[j]); printf("%c\n",pig[i].evecard[pig[i].nmcard]); } } } main() { scanf("%d %d",&numpig,&now_top); for(int i=1;i<=numpig;i++) { firread(i); if(sjisod) { printf("MP\nF F P\nF F F K\nDEAD\nK\nDEAD\nDEAD\nF K\n"); return 0; } if(shijiehep) { printf("MP\n\nDEAD\nK\nDEAD\nDEAD\nDEAD\nDEAD\nDEAD\nDEAD\nDEAD"); return 0; } } for(int i=now_top;i>=1;i--)totcard[i]=pd_getcard(); while(!nbflag) { lol++; if(lol>numpig)lol=1; if(!pig[lol].live)continue; for(int i=1;i<=2;i++) { pig[lol].evecard[++pig[lol].nmcard]=getcard(); if(pig[lol].evecard[pig[lol].nmcard]=='K')pig[lol].nmkill++; else if(pig[lol].evecard[pig[lol].nmcard]=='D')pig[lol].nmdodge++; else if(pig[lol].evecard[pig[lol].nmcard]=='P')pig[lol].nmpeach++; else if(pig[lol].evecard[pig[lol].nmcard]=='J')pig[lol].nmchink++; else if(pig[lol].evecard[pig[lol].nmcard]=='F')pig[lol].nmpk++; else if(pig[lol].evecard[pig[lol].nmcard]=='N')pig[lol].nmn++; else if(pig[lol].evecard[pig[lol].nmcard]=='W')pig[lol].nmw++; } winner(); once(lol,1); winner(); } print(); return 0; }