P2482 [SDOI2010] 猪国杀 DEBUG 记录

· · 题解

P2482 [SDOI2010] 猪国杀

省流:1.5h 读题 + 3.5h 写题 + 13.5h 调试。

First Code:

1.5h 读题,3.5h 写题。

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

#define pb push_back

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)

namespace io{
    char getdigit(){char c=getchar();while(!isdigit(c))c=getchar();return c;}
    char getupper(){char c=getchar();while(!isupper(c))c=getchar();return c;}
    char getlower(){char c=getchar();while(!islower(c))c=getchar();return c;}
    char getalpha(){char c=getchar();while(!isalpha(c))c=getchar();return c;}
    char getachar(){char c=getchar();while(c=='\n'||c==' ')c=getchar();return c;}
    void read(){}template<typename T,typename...T2>inline void read(T &x,T2 &... oth){x=0;int c=getchar(),f=0;while(!isdigit(c)){if(c=='-')f=1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}if(f)x=-x;read(oth...);}
    void write(int x){if(x<0)x=-x;if(x>9)write(x/10);putchar(x%10+'0');}
    void print(int x,char end='\n'){write(x),putchar(end);}
}
namespace math{
    int gcd(int a,int b){return __gcd(a,b);}
    int lcm(int a,int b){return a/__gcd(a,b)*b;}
    int pow(int a,int b,int mod){int res=1%mod;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
    int inv(int a,int mod){return pow(a,mod-2,mod);}
    void Min(int &a,int b){a=min(a,b);}
    void Max(int &a,int b){a=max(a,b);}
}
using namespace io;
using namespace math;

struct Pigs{
    int Type,Show,SumCards;
    int Blood,IsAgain;
    int Cards[2005];
}Pig[15];

int n,m,SumFP;

namespace Defines{
    #define M_MP 0
    #define Z_ZP 1
    #define F_FP 2
    #define F_SP 3
    #define Died 4
    #define P_Peach 11
    #define K_Kills 12
    #define D_Dodge 13
    #define F_Fight 21
    #define N_North 22
    #define W_Arrow 23
    #define J_Safer 24
    #define Z_Again 31
    int TypePig(char c){
        if(c=='M') return M_MP;
        if(c=='Z') return Z_ZP;
        if(c=='F') return F_FP;
    }
    int TypeCard(char c){
        if(c=='P') return P_Peach;
        if(c=='K') return K_Kills;
        if(c=='D') return D_Dodge;
        if(c=='F') return F_Fight;
        if(c=='N') return N_North;
        if(c=='W') return W_Arrow;
        if(c=='J') return J_Safer;
        if(c=='Z') return Z_Again;
    }
    char ToChar(int c){
        if(c==P_Peach) return 'P';
        if(c==K_Kills) return 'K';
        if(c==D_Dodge) return 'D';
        if(c==F_Fight) return 'F';
        if(c==N_North) return 'N';
        if(c==W_Arrow) return 'W';
        if(c==J_Safer) return 'J';
        if(c==Z_Again) return 'Z';
    }
}
using namespace Defines;

namespace Card_Stack{
    int CardStack[2005],top;
    int GetCard(){
        top=min(top+1,m);
        return CardStack[top];
    }
}
using namespace Card_Stack;

void Input(){
    read(n,m);
    FOR(i,1,n){
        Pig[i].Type=TypePig(getalpha());
        if(Pig[i].Type==F_FP) SumFP++;
        getalpha();
        FOR(j,1,4){
            Pig[i].Cards[j]=TypeCard(getalpha());
        }Pig[i].SumCards=Pig[i].Blood=4;
    }
    Pig[1].Show=Z_ZP;
    FOR(i,1,m){
        CardStack[i]=TypeCard(getalpha());
    }
}

void Clear(int i){
    int tot=0;
    FOR(j,1,Pig[i].SumCards){
        if(Pig[i].Cards[j]!=0){
            Pig[i].Cards[++tot]=Pig[i].Cards[j];
        }
    }
    Pig[i].SumCards=tot;
}

int Find_Next(int i){
    for(int j=i%n+1;;j=j%n+1){
        if(Pig[j].Type!=Died) return j;
    }
}

bool TryHate(int i,int j){
    switch(Pig[i].Type){
        case M_MP:
            if(Pig[j].Show==F_FP or Pig[j].Show==F_SP){
                return true;
            }return false;
        case Z_ZP:
            if(Pig[j].Show==F_FP){
                Pig[i].Show=Z_ZP;
                return true;
            }return false;
        case F_FP:
            if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                Pig[i].Show=F_FP;
                return true;
            }return false;
    }
}

bool TryLove(int i,int j){
    if(Pig[j].Show==0 or Pig[j].Show==F_SP){
        return false;
    }else{
        switch(Pig[i].Type){
            case M_MP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    return true;
                }return false;
            case Z_ZP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    Pig[i].Show=Z_ZP;
                    return true;
                }return false;
            case F_FP:
                if(Pig[j].Show==F_FP){
                    Pig[i].Show=F_FP;
                    return true;
                }return false;
        }
    }
}

bool TryKills(int i){
    FOR(j,1,Pig[i].SumCards){
        if(Pig[i].Cards[j]==K_Kills){
            Pig[i].Cards[j]=0;
            Clear(i);
            return true;
        }
    }return false;
}

bool TryFight(int i,int j){
    if(Pig[i].Type==Z_ZP and Pig[j].Type==M_MP){
        return false;
    }else{
        FOR(j,1,Pig[i].SumCards){
            if(Pig[i].Cards[j]==K_Kills){
                Pig[i].Cards[j]=0;
                Clear(i);
                return true;
            }
        }return false;
    }
}

bool TryDodge(int i){
    FOR(j,1,Pig[i].SumCards){
        if(Pig[i].Cards[j]==D_Dodge){
            Pig[i].Cards[j]=0;
            Clear(i);
            return true;
        }
    }return false;
}

bool TryHealth(int i){
    FOR(j,1,Pig[i].SumCards){
        if(Pig[i].Cards[j]==P_Peach){
            Pig[i].Blood++;
            Pig[i].Cards[j]=0;
            Clear(i);
            return true;
        }
    }
    return false;
}

int TrySafer(int i,int j,bool s){
    if((s==true and TryLove(i,j)) or (s==false and TryHate(i,j))){
        FOR(j,1,Pig[i].SumCards){
            if(Pig[i].Cards[j]==J_Safer){
                Pig[i].Cards[j]=0;
                Clear(i);
                int k=Find_Next(i);
                while(k!=i){
                    int op=TrySafer(k,i,1-s);
                    if(op==2) return 0;
                    if(op==1) return 2;
                    else      continue;
                }return 2;
            }
        }
    }
    return 0;
}

void CheckHurtAll(int i,int j){
    if(Pig[j].Type==M_MP){
        Pig[i].Type=F_SP;
    }
}

void CheckKill(int i,int j){
    if(Pig[j].Type==F_FP){
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        SumFP--;
    }else if(Pig[j].Type==Z_ZP and Pig[i].Type==M_MP){
        Pig[i].IsAgain=false;
        Pig[i].SumCards=0;
    }
    if(Pig[1].Type==Died or SumFP==0){
        if(Pig[1].Type!=Died) puts("MP");
        else                  puts("ZP");
        FOR(i,1,n){
            if(Pig[i].Type==Died){
                puts("DEAD");
            }else{
                FOR(j,1,Pig[i].SumCards){
                    printf("%c ",ToChar(Pig[i].Cards[j]));
                }puts("");
            }
        }
    }
    exit(0);
}

void Action(int I){
    bool IsAction=true,Iskill=false;
    while(IsAction){
        IsAction=false;
        FOR(i,1,Pig[i].SumCards){
            char card=Pig[i].Cards[i];
            if(card==P_Peach and Pig[i].Blood!=4){
                Pig[i].Blood++;
                IsAction=true;break;
            }else if(card==K_Kills and (!Iskill or Pig[i].IsAgain)){
                int j;
                if(Pig[i].Type==F_FP and TryHate(i,1)){
                    j=1;
                }else{
                    j=Find_Next(i);
                    while(!TryHate(i,j) and i!=j){
                        j=Find_Next(j);
                    }
                }
                if(i!=j){
                    if(TryDodge(j)==false){
                        Pig[j].Blood--;
                        if(Pig[j].Blood<=0 and TryHealth(j)==false){
                            CheckKill(i,j);
                            Pig[j].Type=Died;
                        }
                        Iskill=true;
                    }
                    Clear(i);
                    Clear(j);
                    IsAction=true;break;
                }
            }else if(card==F_Fight){
                int j;
                if(Pig[i].Type==F_FP and TryHate(i,1)){
                    j=1;
                }else{
                    j=Find_Next(i);
                    while(!TryHate(i,j) and i!=j){
                        j=Find_Next(j);
                    }
                }
                if(i!=j){
                    int j=0;
                    int Out=1;
                    while(TryFight((Out==0)?i:j,(Out==0)?j:i)){
                        Out=1-Out;
                    }
                    j=((Out==0)?i:j);
                    Pig[j].Blood--;
                    if(Pig[j].Blood<=0 and TryHealth(j)==false){
                        CheckKill(i,j);
                        Pig[j].Type=Died;
                    }
                    Iskill=true;
                    Clear(i);
                    Clear(j);
                    IsAction=true;break;
                }
            }else if(card==N_North){
                int j=Find_Next(i);
                while(j!=i){
                    if(!TryKills(j)){
                        if(TrySafer(j,i,true)==2){
                            Pig[j].Blood--;
                            CheckHurtAll(i,j);
                            if(Pig[j].Blood<=0 and TryHealth(j)==false){
                                CheckKill(i,j);
                                Pig[j].Type=Died;
                            }
                            Iskill=true;
                        }
                    }
                    j=Find_Next(j);
                }
                IsAction=true;break;
            }else if(card==W_Arrow){
                int j=Find_Next(i);
                while(j!=i){
                    if(!TryDodge(j)){
                        if(TrySafer(j,i,true)==2){
                            Pig[j].Blood--;
                            CheckHurtAll(i,j);
                            if(Pig[j].Blood<=0 and TryHealth(j)==false){
                                CheckKill(i,j);
                                Pig[j].Type=Died;
                            }
                            Iskill=true;
                        }
                    }
                    j=Find_Next(j);
                }
                IsAction=true;break;
            }
        }
    }
}


signed main()
{
    Input();
    int now=1;
    while(true){
        Pig[now].Cards[++Pig[now].SumCards]=GetCard();
        Pig[now].Cards[++Pig[now].SumCards]=GetCard();
        Action(now);
        now=Find_Next(now);
    }
    return 0;
}

Debug List

Day1: 2025/04/28

  1. 发现一些锦囊牌使用后未从牌堆中消除导致死循环;
  2. 南猪入侵/万箭齐发时没有整理牌堆;
  3. 无懈可击的成功性判断错误;
  4. 南猪入侵/万箭齐发时把身份设置成了类反猪;
  5. 决斗的杀不算出杀;
  6. 局部变量冲突;
  7. 对于猪死亡的判定存在问题;
  8. 反猪胜利时输出了 ZP。

成就:1.5h,过样例,0pts。

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

#define pb push_back

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)

namespace io{
    char getdigit(){char c=getchar();while(!isdigit(c))c=getchar();return c;}
    char getupper(){char c=getchar();while(!isupper(c))c=getchar();return c;}
    char getlower(){char c=getchar();while(!islower(c))c=getchar();return c;}
    char getalpha(){char c=getchar();while(!isalpha(c))c=getchar();return c;}
    char getachar(){char c=getchar();while(c=='\n'||c==' ')c=getchar();return c;}
    void read(){}template<typename T,typename...T2>inline void read(T &x,T2 &... oth){x=0;int c=getchar(),f=0;while(!isdigit(c)){if(c=='-')f=1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}if(f)x=-x;read(oth...);}
    void write(int x){if(x<0)x=-x;if(x>9)write(x/10);putchar(x%10+'0');}
    void print(int x,char end='\n'){write(x),putchar(end);}
}
namespace math{
    int gcd(int a,int b){return __gcd(a,b);}
    int lcm(int a,int b){return a/__gcd(a,b)*b;}
    int pow(int a,int b,int mod){int res=1%mod;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
    int inv(int a,int mod){return pow(a,mod-2,mod);}
    void Min(int &a,int b){a=min(a,b);}
    void Max(int &a,int b){a=max(a,b);}
}
using namespace io;
using namespace math;

struct Pigs{
    int Type,Show,SumCards;
    int Blood,IsAgain;
    int Cards[2005];
}Pig[15];

int n,m,SumFP;

namespace Defines{
    #define M_MP 0
    #define Z_ZP 1
    #define F_FP 2
    #define F_SP 3
    #define Died 4
    #define P_Peach 11
    #define K_Kills 12
    #define D_Dodge 13
    #define F_Fight 21
    #define N_North 22
    #define W_Arrow 23
    #define J_Safer 24
    #define Z_Again 31
    int TypePig(char c){
        if(c=='M') return M_MP;
        if(c=='Z') return Z_ZP;
        if(c=='F') return F_FP;
    }
    int TypeCard(char c){
        if(c=='P') return P_Peach;
        if(c=='K') return K_Kills;
        if(c=='D') return D_Dodge;
        if(c=='F') return F_Fight;
        if(c=='N') return N_North;
        if(c=='W') return W_Arrow;
        if(c=='J') return J_Safer;
        if(c=='Z') return Z_Again;
    }
    char ToChar(int c){
        if(c==P_Peach) return 'P';
        if(c==K_Kills) return 'K';
        if(c==D_Dodge) return 'D';
        if(c==F_Fight) return 'F';
        if(c==N_North) return 'N';
        if(c==W_Arrow) return 'W';
        if(c==J_Safer) return 'J';
        if(c==Z_Again) return 'Z';
    }
}
using namespace Defines;

namespace Card_Stack{
    int CardStack[2005],top;
    int GetCard(){
        top=min(top+1,m);
        return CardStack[top];
    }
}
using namespace Card_Stack;

void Input(){
    read(n,m);
    FOR(i,1,n){
        Pig[i].Type=TypePig(getalpha());
        if(Pig[i].Type==F_FP) SumFP++;
        getalpha();
        FOR(j,1,4){
            Pig[i].Cards[j]=TypeCard(getalpha());
        }Pig[i].SumCards=Pig[i].Blood=4;
    }
    Pig[1].Show=Z_ZP;
    FOR(i,1,m){
        CardStack[i]=TypeCard(getalpha());
    }
}

void Clear(int i){
    int tot=0;
    FOR(j,1,Pig[i].SumCards){
        if(Pig[i].Cards[j]!=0){
            Pig[i].Cards[++tot]=Pig[i].Cards[j];
        }
    }
    Pig[i].SumCards=tot;
}

int Find_Next(int i){
    for(int j=i%n+1;;j=j%n+1){
        if(Pig[j].Type!=Died) return j;
    }
}

bool TryHate(int i,int j){
    switch(Pig[i].Type){
        case M_MP:
            if(Pig[j].Show==F_FP or Pig[j].Show==F_SP){
                return true;
            }return false;
        case Z_ZP:
            if(Pig[j].Show==F_FP){
                Pig[i].Show=Z_ZP;
                return true;
            }return false;
        case F_FP:
            if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                Pig[i].Show=F_FP;
                return true;
            }return false;
    }
}

bool TryLove(int i,int j){
    if(Pig[j].Show==0 or Pig[j].Show==F_SP){
        return false;
    }else{
        switch(Pig[i].Type){
            case M_MP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    return true;
                }return false;
            case Z_ZP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    Pig[i].Show=Z_ZP;
                    return true;
                }return false;
            case F_FP:
                if(Pig[j].Show==F_FP){
                    Pig[i].Show=F_FP;
                    return true;
                }return false;
        }
    }
}

bool TryKills(int i){
    FOR(j,1,Pig[i].SumCards){
        if(Pig[i].Cards[j]==K_Kills){
            Pig[i].Cards[j]=0;
            Clear(i);
            return true;
        }
    }return false;
}

bool TryFight(int i,int j){
    if(Pig[i].Type==Z_ZP and Pig[j].Type==M_MP){
        return false;
    }else{
        FOR(j,1,Pig[i].SumCards){
            if(Pig[i].Cards[j]==K_Kills){
                Pig[i].Cards[j]=0;
                Clear(i);
                return true;
            }
        }return false;
    }
}

bool TryDodge(int i){
    FOR(j,1,Pig[i].SumCards){
        if(Pig[i].Cards[j]==D_Dodge){
            Pig[i].Cards[j]=0;
            Clear(i);
            return true;
        }
    }return false;
}

bool TryHealth(int i){
    FOR(j,1,Pig[i].SumCards){
        if(Pig[i].Cards[j]==P_Peach){
            Pig[i].Blood++;
            Pig[i].Cards[j]=0;
            Clear(i);
            return true;
        }
    }
    return false;
}

int TrySafer(int i,int j,bool s){
    if((s==true and TryLove(i,j)) or (s==false and TryHate(i,j))){
        FOR(j,1,Pig[i].SumCards){
            if(Pig[i].Cards[j]==J_Safer){
                Pig[i].Cards[j]=0;
                Clear(i);
                int k=Find_Next(i);
                while(k!=i){
                    int op=TrySafer(k,i,1-s);
                    if(op==2) return 0;
                    if(op==1) return 2;
                    else      continue;
                }return 2;
            }
        }
    }
    return 0;
}

void CheckHurtAll(int i,int j){
    if(Pig[j].Type==M_MP){
        Pig[i].Show=F_SP;
    }
}

void CheckKill(int i,int j){
    if(Pig[j].Type==F_FP){
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        SumFP--;
    }else if(Pig[j].Type==Z_ZP and Pig[i].Type==M_MP){
        Pig[i].IsAgain=false;
        Pig[i].SumCards=0;
    }
    Pig[j].Type=Died;
    if(Pig[1].Type==Died or SumFP==0){
        if(Pig[1].Type!=Died) puts("MP");
        else                  puts("FP");
        FOR(i,1,n){
            if(Pig[i].Type==Died){
                puts("DEAD");
            }else{
                Clear(i);
                FOR(j,1,Pig[i].SumCards){
                    printf("%c ",ToChar(Pig[i].Cards[j]));
                }puts("");
            }
        }
        exit(0);
    }
}

void Action(int i){
    bool IsAction=true,Iskill=false;
    while(IsAction){
        IsAction=false;
        FOR(c,1,Pig[i].SumCards){
            int card=Pig[i].Cards[c];
            if(card==P_Peach and Pig[i].Blood!=4){
                Pig[i].Cards[c]=0;
                Pig[i].Blood++;
                IsAction=true;break;
            }else if(card==K_Kills and (!Iskill or Pig[i].IsAgain)){
                int j;
                if(Pig[i].Type==F_FP and TryHate(i,1)){
                    j=1;
                }else{
                    j=Find_Next(i);
                    while(!TryHate(i,j) and i!=j){
                        j=Find_Next(j);
                    }
                }
                if(i!=j){
                    Pig[i].Cards[c]=0;
                    if(TryDodge(j)==false){
                        Pig[j].Blood--;
                        if(Pig[j].Blood<=0 and TryHealth(j)==false){
                            CheckKill(i,j);
                        }
                        Iskill=true;
                    }
                    Clear(i);
                    Clear(j);
                    IsAction=true;break;
                }
            }else if(card==F_Fight){
                int j;
                if(Pig[i].Type==F_FP and TryHate(i,1)){
                    j=1;
                }else{
                    j=Find_Next(i);
                    while(!TryHate(i,j) and i!=j){
                        j=Find_Next(j);
                    }
                }
                if(i!=j){
                    Pig[i].Cards[c]=0;
                    int Out=1;
                    while(TryFight((Out==0)?i:j,(Out==0)?j:i)){
                        Out=1-Out;
                    }
                    j=((Out==0)?i:j);
                    Pig[j].Blood--;
                    if(Pig[j].Blood<=0 and TryHealth(j)==false){
                        CheckKill(i,j);
                    }
                    Clear(i);
                    Clear(j);
                    IsAction=true;break;
                }
            }else if(card==N_North){
                int j=Find_Next(i);
                while(j!=i){
                    Pig[i].Cards[c]=0;
                    if(!TryKills(j)){
                        if(TrySafer(j,i,true)!=2){
                            Pig[j].Blood--;
                            CheckHurtAll(i,j);
                            if(Pig[j].Blood<=0 and TryHealth(j)==false){
                                CheckKill(i,j);
                            }
                            Iskill=true;
                        }
                    }
                    j=Find_Next(j);
                }
                Clear(i);
                IsAction=true;break;
            }else if(card==W_Arrow){
                int j=Find_Next(i);
                while(j!=i){
                    Pig[i].Cards[c]=0;
                    if(!TryDodge(j)){
                        if(TrySafer(j,i,true)!=2){
                            Pig[j].Blood--;
                            CheckHurtAll(i,j);
                            if(Pig[j].Blood<=0 and TryHealth(j)==false){
                                CheckKill(i,j);
                            }
                            Iskill=true;
                        }
                    }
                    j=Find_Next(j);
                }
                Clear(i);
                IsAction=true;break;
            }
        }
    }
}


signed main()
{
    Input();
    int now=1;
    while(true){
        Pig[now].Cards[++Pig[now].SumCards]=GetCard();
        Pig[now].Cards[++Pig[now].SumCards]=GetCard();
        Action(now);
        now=Find_Next(now);
    }
    return 0;
}

Day2: 2025/04/29

  1. 吃桃时没有消除此牌;
  2. 南猪入侵/万箭齐发不算杀;
  3. 南猪入侵/万箭齐发卡片重复删除导致误删;
  4. 使用无懈可击挡下南猪入侵/万箭齐发,其实是在对自己献殷勤;
  5. 未处理猪哥连弩的装备;
  6. 猪哥连弩忘记标记已出牌;
  7. 被南猪入侵/万箭齐发时应该先出无懈可击再出杀/闪;
  8. 决斗前未检查无懈可击情况;
  9. 检查无懈可击是否成功的函数忘记跳到下一个人导致死循环;
  10. 无懈可击时检查是否出过牌的函数返回值错误;
  11. 无懈可击判断是否继续检查时 continue 导致没有找到下一只猪;
  12. 禁 止 对 着 死 猪 表 敌 意;

成就:1.5h,5pts。

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

#define pb push_back

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)

namespace io{
    char getdigit(){char c=getchar();while(!isdigit(c))c=getchar();return c;}
    char getupper(){char c=getchar();while(!isupper(c))c=getchar();return c;}
    char getlower(){char c=getchar();while(!islower(c))c=getchar();return c;}
    char getalpha(){char c=getchar();while(!isalpha(c))c=getchar();return c;}
    char getachar(){char c=getchar();while(c=='\n'||c==' ')c=getchar();return c;}
    void read(){}template<typename T,typename...T2>inline void read(T &x,T2 &... oth){x=0;int c=getchar(),f=0;while(!isdigit(c)){if(c=='-')f=1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}if(f)x=-x;read(oth...);}
    void write(int x){if(x<0)x=-x;if(x>9)write(x/10);putchar(x%10+'0');}
    void print(int x,char end='\n'){write(x),putchar(end);}
}
namespace math{
    int gcd(int a,int b){return __gcd(a,b);}
    int lcm(int a,int b){return a/__gcd(a,b)*b;}
    int pow(int a,int b,int mod){int res=1%mod;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
    int inv(int a,int mod){return pow(a,mod-2,mod);}
    void Min(int &a,int b){a=min(a,b);}
    void Max(int &a,int b){a=max(a,b);}
}
using namespace io;
using namespace math;

struct Pigs{
    int Type,Show,SumCards;
    int Blood,IsAgain;
    int Cards[2005];
}Pig[15];

int n,m,SumFP;

namespace Defines{
    #define M_MP 0
    #define Z_ZP 1
    #define F_FP 2
    #define F_SP 3
    #define Died 4
    #define P_Peach 11
    #define K_Kills 12
    #define D_Dodge 13
    #define F_Fight 21
    #define N_North 22
    #define W_Arrow 23
    #define J_Safer 24
    #define Z_Again 31
    #define ERROR_RETURN 114514
    int TypePig(char c){
        if(c=='M') return M_MP;
        if(c=='Z') return Z_ZP;
        if(c=='F') return F_FP;
    }
    int TypeCard(char c){
        if(c=='P') return P_Peach;
        if(c=='K') return K_Kills;
        if(c=='D') return D_Dodge;
        if(c=='F') return F_Fight;
        if(c=='N') return N_North;
        if(c=='W') return W_Arrow;
        if(c=='J') return J_Safer;
        if(c=='Z') return Z_Again;
    }
    char ToChar(int c){
        if(c==P_Peach) return 'P';
        if(c==K_Kills) return 'K';
        if(c==D_Dodge) return 'D';
        if(c==F_Fight) return 'F';
        if(c==N_North) return 'N';
        if(c==W_Arrow) return 'W';
        if(c==J_Safer) return 'J';
        if(c==Z_Again) return 'Z';
    }
}
using namespace Defines;

namespace Card_Stack{
    int CardStack[2005],top;
    int GetCard(){
        top=min(top+1,m);
        return CardStack[top];
    }
}
using namespace Card_Stack;

void Input(){
    read(n,m);
    FOR(i,1,n){
        Pig[i].Type=TypePig(getalpha());
        if(Pig[i].Type==F_FP) SumFP++;
        getalpha();
        FOR(j,1,4){
            Pig[i].Cards[j]=TypeCard(getalpha());
        }Pig[i].SumCards=Pig[i].Blood=4;
    }
    Pig[1].Show=Z_ZP;
    FOR(i,1,m){
        CardStack[i]=TypeCard(getalpha());
    }
}

void Delete(int i,int j){
    FOR(c,j,Pig[i].SumCards){
        Pig[i].Cards[c]=Pig[i].Cards[c+1];
    }Pig[i].SumCards--;
}

int Find_Next(int i){
    for(int j=i%n+1;;j=j%n+1){
        if(Pig[j].Type!=Died) return j;
    }
}

bool TryHate(int i,int j){
    switch(Pig[i].Type){
        case M_MP:
            if(Pig[j].Show==F_FP or Pig[j].Show==F_SP){
                return true;
            }return false;
        case Z_ZP:
            if(Pig[j].Show==F_FP){
                Pig[i].Show=Z_ZP;
                return true;
            }return false;
        case F_FP:
            if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                Pig[i].Show=F_FP;
                return true;
            }return false;
        case Died:
            return false;
    }
}

bool TryLove(int i,int j){
    if(Pig[j].Show==0 or Pig[j].Show==F_SP){
        return false;
    }else{
        switch(Pig[i].Type){
            case M_MP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    return true;
                }return false;
            case Z_ZP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    Pig[i].Show=Z_ZP;
                    return true;
                }return false;
            case F_FP:
                if(Pig[j].Show==F_FP){
                    Pig[i].Show=F_FP;
                    return true;
                }return false;
            case Died:
                return false;
        }
    }
}

bool TryKills(int i){
    FOR(c,1,Pig[i].SumCards){
        if(Pig[i].Cards[c]==K_Kills){
            Delete(i,c);
            return true;
        }
    }return false;
}

bool TryFight(int i,int j){
    if(Pig[i].Type==Z_ZP and Pig[j].Type==M_MP){
        return false;
    }else{
        FOR(c,1,Pig[i].SumCards){
            if(Pig[i].Cards[c]==K_Kills){
                Delete(i,c);
                return true;
            }
        }return false;
    }
}

bool TryDodge(int i){
    FOR(c,1,Pig[i].SumCards){
        if(Pig[i].Cards[c]==D_Dodge){
            Delete(i,c);
            return true;
        }
    }return false;
}

bool TryHealth(int i){
    FOR(c,1,Pig[i].SumCards){
        if(Pig[i].Cards[c]==P_Peach){
            Pig[i].Blood++;
            Delete(i,c);
            return true;
        }
    }
    return false;
}

int TrySafer(int i,int j,bool s){
    if((s==true and TryLove(i,j)) or (s==false and TryHate(i,j))){
        FOR(c,1,Pig[i].SumCards){
            if(Pig[i].Cards[c]==J_Safer){
                Delete(i,c);
                int k=Find_Next(i);
                while(k!=i){
                    int op=TrySafer(k,i,1-s);
                    if(op==2) return 1;
                    if(op==1) return 2;
                    k=Find_Next(k);
                }return 2;
            }
        }
    }
    return 0;
}

void CheckHurtAll(int i,int j){
    if(Pig[j].Type==M_MP){
        Pig[i].Show=F_SP;
    }
}

void CheckKill(int i,int j){
    if(Pig[j].Type==F_FP){
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        SumFP--;
    }else if(Pig[j].Type==Z_ZP and Pig[i].Type==M_MP){
        Pig[i].IsAgain=false;
        Pig[i].SumCards=0;
    }
    Pig[j].Type=Died;
    if(Pig[1].Type==Died or SumFP==0){
        if(Pig[1].Type!=Died) puts("MP");
        else                  puts("FP");
        FOR(i,1,n){
            if(Pig[i].Type==Died){
                puts("DEAD");
            }else{
                FOR(c,1,Pig[i].SumCards){
                    printf("%c ",ToChar(Pig[i].Cards[c]));
                }puts("");
            }
        }
        exit(0);
    }
}

void Action(int i){
    bool IsAction=true,Iskill=false;
    while(IsAction){
        IsAction=false;
        FOR(c,1,Pig[i].SumCards){
            int card=Pig[i].Cards[c];
            if(card==P_Peach and Pig[i].Blood!=4){
                Delete(i,c);
                Pig[i].Blood++;
                IsAction=true;break;
            }else if(card==K_Kills and (!Iskill or Pig[i].IsAgain)){
                int j;
                if(Pig[i].Type==F_FP and TryHate(i,1)){
                    j=1;
                }else{
                    j=Find_Next(i);
                    while(!TryHate(i,j) and i!=j){
                        j=Find_Next(j);
                    }
                }
                if(i!=j){
                    Delete(i,c);
                    Iskill=true;
                    if(TryDodge(j)==false){
                        Pig[j].Blood--;
                        if(Pig[j].Blood<=0 and TryHealth(j)==false){
                            CheckKill(i,j);
                        }
                    }
                    IsAction=true;break;
                }
            }else if(card==F_Fight){
                int j;
                if(Pig[i].Type==F_FP and TryHate(i,1)){
                    j=1;
                }else{
                    j=Find_Next(i);
                    while(!TryHate(i,j) and i!=j){
                        j=Find_Next(j);
                    }
                }
                if(i!=j){
                    Delete(i,c);
                    if(!TrySafer(j,j,true)){
                        int Out=1;
                        while(TryFight((Out==0)?i:j,(Out==0)?j:i)){
                            Out=1-Out;
                        }
                        j=((Out==0)?i:j);
                        Pig[j].Blood--;
                        if(Pig[j].Blood<=0 and TryHealth(j)==false){
                            CheckKill(i,j);
                        }
                        IsAction=true;break;
                    }
                }
            }else if(card==N_North){
                Delete(i,c);
                int j=Find_Next(i);
                while(j!=i){
                    if(TrySafer(j,j,true)!=2){
                        if(!TryKills(j)){
                            Pig[j].Blood--;
                            CheckHurtAll(i,j);
                            if(Pig[j].Blood<=0 and TryHealth(j)==false){
                                CheckKill(i,j);
                            }
                        }
                    }
                    j=Find_Next(j);
                }
                IsAction=true;break;
            }else if(card==W_Arrow){
                Delete(i,c);
                int j=Find_Next(i);
                while(j!=i){
                    if(TrySafer(j,j,true)!=2){
                        if(!TryDodge(j)){
                            Pig[j].Blood--;
                            CheckHurtAll(i,j);
                            if(Pig[j].Blood<=0 and TryHealth(j)==false){
                                CheckKill(i,j);
                            }
                        }
                    }
                    j=Find_Next(j);
                }
                IsAction=true;break;
            }else if(card==Z_Again){
                Pig[i].IsAgain=true;
                Delete(i,c);
                IsAction=true;break;
            }
        }
    }
}


signed main()
{
    Input();
    int now=1;
    while(true){
        Pig[now].Cards[++Pig[now].SumCards]=GetCard();
        Pig[now].Cards[++Pig[now].SumCards]=GetCard();
        Action(now);
        now=Find_Next(now);
    }
    return 0;
}

Day3: 2025/04/30

  1. 类反猪需要未表明身份;
  2. 一个角色受到南猪入侵/万箭齐发时,其他猪可以帮他挡住;
  3. 在判断是否可以献殷勤/表敌意时直接修改了;
  4. 一方赢了不用摸奖励/惩罚直接输出;
  5. 为什么我的代码桃的部分突然消失了?!

成就:3h,20pts。

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

#define pb push_back

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)

namespace io{
    char getdigit(){char c=getchar();while(!isdigit(c))c=getchar();return c;}
    char getupper(){char c=getchar();while(!isupper(c))c=getchar();return c;}
    char getlower(){char c=getchar();while(!islower(c))c=getchar();return c;}
    char getalpha(){char c=getchar();while(!isalpha(c))c=getchar();return c;}
    char getachar(){char c=getchar();while(c=='\n'||c==' ')c=getchar();return c;}
    void read(){}template<typename T,typename...T2>inline void read(T &x,T2 &... oth){x=0;int c=getchar(),f=0;while(!isdigit(c)){if(c=='-')f=1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}if(f)x=-x;read(oth...);}
    void write(int x){if(x<0)x=-x;if(x>9)write(x/10);putchar(x%10+'0');}
    void print(int x,char end='\n'){write(x),putchar(end);}
}
namespace math{
    int gcd(int a,int b){return __gcd(a,b);}
    int lcm(int a,int b){return a/__gcd(a,b)*b;}
    int pow(int a,int b,int mod){int res=1%mod;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
    int inv(int a,int mod){return pow(a,mod-2,mod);}
    void Min(int &a,int b){a=min(a,b);}
    void Max(int &a,int b){a=max(a,b);}
}
using namespace io;
using namespace math;

struct Pigs{
    int Type,Show,SumCards;
    int Blood,IsAgain;
    int Cards[2005];
}Pig[15];

int n,m,SumFP;

namespace Defines{
    #define M_MP 0
    #define Z_ZP 1
    #define F_FP 2
    #define F_SP 3
    #define Died 4
    #define P_Peach 11
    #define K_Kills 12
    #define D_Dodge 13
    #define F_Fight 21
    #define N_North 22
    #define W_Arrow 23
    #define J_Safer 24
    #define Z_Again 31
    #define ERROR_RETURN 114514
    int TypePig(char c){
        if(c=='M') return M_MP;
        if(c=='Z') return Z_ZP;
        if(c=='F') return F_FP;
    }
    int TypeCard(char c){
        if(c=='P') return P_Peach;
        if(c=='K') return K_Kills;
        if(c=='D') return D_Dodge;
        if(c=='F') return F_Fight;
        if(c=='N') return N_North;
        if(c=='W') return W_Arrow;
        if(c=='J') return J_Safer;
        if(c=='Z') return Z_Again;
    }
    char ToChar(int c){
        if(c==P_Peach) return 'P';
        if(c==K_Kills) return 'K';
        if(c==D_Dodge) return 'D';
        if(c==F_Fight) return 'F';
        if(c==N_North) return 'N';
        if(c==W_Arrow) return 'W';
        if(c==J_Safer) return 'J';
        if(c==Z_Again) return 'Z';
    }
}
using namespace Defines;

namespace Card_Stack{
    int CardStack[2005],top;
    int GetCard(){
        top=min(top+1,m);
        return CardStack[top];
    }
}
using namespace Card_Stack;

void Input(){
    read(n,m);
    FOR(i,1,n){
        Pig[i].Type=TypePig(getalpha());
        if(Pig[i].Type==F_FP) SumFP++;
        getalpha();
        FOR(j,1,4){
            Pig[i].Cards[j]=TypeCard(getalpha());
        }Pig[i].SumCards=Pig[i].Blood=4;
    }
    Pig[1].Show=Z_ZP;
    FOR(i,1,m){
        CardStack[i]=TypeCard(getalpha());
    }
}

void Delete(int i,int j){
    FOR(c,j,Pig[i].SumCards){
        Pig[i].Cards[c]=Pig[i].Cards[c+1];
    }Pig[i].SumCards--;
}

int Find_Next(int i){
    for(int j=i%n+1;;j=j%n+1){
        if(Pig[j].Type!=Died) return j;
    }
}

bool CanHate(int i,int j){
    switch(Pig[i].Type){
        case M_MP:
            if(Pig[j].Show==F_FP or Pig[j].Show==F_SP){
                return true;
            }return false;
        case Z_ZP:
            if(Pig[j].Show==F_FP){
                return true;
            }return false;
        case F_FP:
            if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                return true;
            }return false;
        case Died:
            return false;
    }
}

bool TryHate(int i,int j){
    switch(Pig[i].Type){
        case M_MP:
            if(Pig[j].Show==F_FP or Pig[j].Show==F_SP){
                return true;
            }return false;
        case Z_ZP:
            if(Pig[j].Show==F_FP){
                Pig[i].Show=Z_ZP;
                return true;
            }return false;
        case F_FP:
            if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                Pig[i].Show=F_FP;
                return true;
            }return false;
        case Died:
            return false;
    }
}

bool CanLove(int i,int j){
    if(Pig[j].Show==0 or Pig[j].Show==F_SP){
        return false;
    }else{
        switch(Pig[i].Type){
            case M_MP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    return true;
                }return false;
            case Z_ZP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    return true;
                }return false;
            case F_FP:
                if(Pig[j].Show==F_FP){
                    return true;
                }return false;
            case Died:
                return false;
        }
    }
}

bool TryLove(int i,int j){
    if(Pig[j].Show==0 or Pig[j].Show==F_SP){
        return false;
    }else{
        switch(Pig[i].Type){
            case M_MP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    return true;
                }return false;
            case Z_ZP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    Pig[i].Show=Z_ZP;
                    return true;
                }return false;
            case F_FP:
                if(Pig[j].Show==F_FP){
                    Pig[i].Show=F_FP;
                    return true;
                }return false;
            case Died:
                return false;
        }
    }
}

bool TryKills(int i){
    FOR(c,1,Pig[i].SumCards){
        if(Pig[i].Cards[c]==K_Kills){
            Delete(i,c);
            return true;
        }
    }return false;
}

bool TryFight(int i,int j){
    if(Pig[i].Type==Z_ZP and Pig[j].Type==M_MP){
        return false;
    }else{
        FOR(c,1,Pig[i].SumCards){
            if(Pig[i].Cards[c]==K_Kills){
                Delete(i,c);
                return true;
            }
        }return false;
    }
}

bool TryDodge(int i){
    FOR(c,1,Pig[i].SumCards){
        if(Pig[i].Cards[c]==D_Dodge){
            Delete(i,c);
            return true;
        }
    }return false;
}

bool TryHealth(int i){
    FOR(c,1,Pig[i].SumCards){
        if(Pig[i].Cards[c]==P_Peach){
            Pig[i].Blood++;
            Delete(i,c);
            return true;
        }
    }
    return false;
}

bool TrySafer(int i,int j,bool s){
    if((s==true and CanLove(i,j)) or (s==false and CanHate(i,j))){
        FOR(c,1,Pig[i].SumCards){
            if(Pig[i].Cards[c]==J_Safer){
                if(s==true) TryLove(i,j);
                else        TryHate(i,j);
                Delete(i,c);
                int k=Find_Next(i);
                while(k!=i){
                    if(TrySafer(k,i,1-s)==true) return false;
                    k=Find_Next(k);
                }return true;
            }
        }
    }
    return false;
}

bool TryBreak(int i,int j){
    int k=i;
    do{ if(TrySafer(k,j,true)==true){
            return true;
        }
        k=Find_Next(k);
    }while(k!=i);
    return false;
}

void CheckHurtAll(int i,int j){
    if(Pig[j].Type==M_MP and Pig[i].Show==0){
        Pig[i].Show=F_SP;
    }
}

void CheckKill(int i,int j){
    if(Pig[j].Type==M_MP or (Pig[j].Type==F_FP and SumFP==1)){
        Pig[j].Type=Died;
        if(Pig[1].Type!=Died) puts("MP");
        else                  puts("FP");
        FOR(i,1,n){
            if(Pig[i].Type==Died){
                puts("DEAD");
            }else{
                FOR(c,1,Pig[i].SumCards){
                    printf("%c ",ToChar(Pig[i].Cards[c]));
                }puts("");
            }
        }
        exit(0);
    }
    if(Pig[j].Type==F_FP){
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        SumFP--;
    }else if(Pig[j].Type==Z_ZP and Pig[i].Type==M_MP){
        Pig[i].IsAgain=false;
        Pig[i].SumCards=0;
    }
    Pig[j].Type=Died;
}

void Action(int i){
    bool IsAction=true,Iskill=false;
    while(IsAction){
        IsAction=false;
        FOR(c,1,Pig[i].SumCards){
            int card=Pig[i].Cards[c];
            if(card==P_Peach and Pig[i].Blood!=4){
                Delete(i,c);
                Pig[i].Blood++;
                IsAction=true;break;
            }if(card==K_Kills and (!Iskill or Pig[i].IsAgain)){
                int j;
                if(Pig[i].Type==F_FP and TryHate(i,1)){
                    j=1;
                }else{
                    j=Find_Next(i);
                    while(!CanHate(i,j) and i!=j){
                        j=Find_Next(j);
                    }
                }
                if(i!=j){
                    Delete(i,c);
                    TryHate(i,j);
                    Iskill=true;
                    if(TryDodge(j)==false){
                        Pig[j].Blood--;
                        if(Pig[j].Blood<=0 and TryHealth(j)==false){
                            CheckKill(i,j);
                        }
                    }
                    IsAction=true;break;
                }
            }else if(card==F_Fight){
                int j;
                if(Pig[i].Type==F_FP and TryHate(i,1)){
                    j=1;
                }else{
                    j=Find_Next(i);
                    while(!CanHate(i,j) and i!=j){
                        j=Find_Next(j);
                    }
                }
                if(i!=j){
                    Delete(i,c);
                    TryHate(i,j);
                    if(!TryBreak(i,j)){
                        int Out=1;
                        while(TryFight((Out==0)?i:j,(Out==0)?j:i)){
                            Out=1-Out;
                        }
                        j=((Out==0)?i:j);
                        Pig[j].Blood--;
                        if(Pig[j].Blood<=0 and TryHealth(j)==false){
                            CheckKill(i,j);
                        }
                        IsAction=true;break;
                    }
                }
            }else if(card==N_North){
                Delete(i,c);
                int j=Find_Next(i);
                while(j!=i){
                    if(!TryBreak(i,j)){
                        if(!TryKills(j)){
                            Pig[j].Blood--;
                            CheckHurtAll(i,j);
                            if(Pig[j].Blood<=0 and TryHealth(j)==false){
                                CheckKill(i,j);
                            }
                        }
                    }
                    j=Find_Next(j);
                }
                IsAction=true;break;
            }else if(card==W_Arrow){
                Delete(i,c);
                int j=Find_Next(i);
                while(j!=i){
                    if(!TryBreak(i,j)){
                        if(!TryDodge(j)){
                            Pig[j].Blood--;
                            CheckHurtAll(i,j);
                            if(Pig[j].Blood<=0 and TryHealth(j)==false){
                                CheckKill(i,j);
                            }
                        }
                    }
                    j=Find_Next(j);
                }
                IsAction=true;break;
            }else if(card==Z_Again){
                Pig[i].IsAgain=true;
                Delete(i,c);
                IsAction=true;break;
            }
        }
    }
}


signed main()
{
    Input();
    int now=1;
    while(true){
        Pig[now].Cards[++Pig[now].SumCards]=GetCard();
        Pig[now].Cards[++Pig[now].SumCards]=GetCard();
        Action(now);
        now=Find_Next(now);
    }
    return 0;
}

Day4: 2025/05/01

  1. 表敌意/献殷勤时对象错误;
  2. 杀的攻击范围是 1;
  3. 不 要 让 死 猪 继 续 出 牌;
  4. 角斗时重新选择牌的时间错误;
  5. 决斗时伤害来源弄错;

成就:7.5h,100pts。

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

#define pb push_back

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)

namespace io{
    char getdigit(){char c=getchar();while(!isdigit(c))c=getchar();return c;}
    char getupper(){char c=getchar();while(!isupper(c))c=getchar();return c;}
    char getlower(){char c=getchar();while(!islower(c))c=getchar();return c;}
    char getalpha(){char c=getchar();while(!isalpha(c))c=getchar();return c;}
    char getachar(){char c=getchar();while(c=='\n'||c==' ')c=getchar();return c;}
    void read(){}template<typename T,typename...T2>inline void read(T &x,T2 &... oth){x=0;int c=getchar(),f=0;while(!isdigit(c)){if(c=='-')f=1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}if(f)x=-x;read(oth...);}
    void write(int x){if(x<0)x=-x;if(x>9)write(x/10);putchar(x%10+'0');}
    void print(int x,char end='\n'){write(x),putchar(end);}
}
namespace math{
    int gcd(int a,int b){return __gcd(a,b);}
    int lcm(int a,int b){return a/__gcd(a,b)*b;}
    int pow(int a,int b,int mod){int res=1%mod;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
    int inv(int a,int mod){return pow(a,mod-2,mod);}
    void Min(int &a,int b){a=min(a,b);}
    void Max(int &a,int b){a=max(a,b);}
}
using namespace io;
using namespace math;

struct Pigs{
    int Type,Show,SumCards;
    int Blood,IsAgain;
    int Cards[2005];
}Pig[15];

int n,m,SumFP;

namespace Defines{
    #define M_MP 0
    #define Z_ZP 1
    #define F_FP 2
    #define F_SP 3
    #define Died 4
    #define P_Peach 11
    #define K_Kills 12
    #define D_Dodge 13
    #define F_Fight 21
    #define N_North 22
    #define W_Arrow 23
    #define J_Safer 24
    #define Z_Again 31
    #define ERROR_RETURN 114514
    int TypePig(char c){
        if(c=='M') return M_MP;
        if(c=='Z') return Z_ZP;
        if(c=='F') return F_FP;
    }
    int TypeCard(char c){
        if(c=='P') return P_Peach;
        if(c=='K') return K_Kills;
        if(c=='D') return D_Dodge;
        if(c=='F') return F_Fight;
        if(c=='N') return N_North;
        if(c=='W') return W_Arrow;
        if(c=='J') return J_Safer;
        if(c=='Z') return Z_Again;
    }
    char ToChar(int c){
        if(c==P_Peach) return 'P';
        if(c==K_Kills) return 'K';
        if(c==D_Dodge) return 'D';
        if(c==F_Fight) return 'F';
        if(c==N_North) return 'N';
        if(c==W_Arrow) return 'W';
        if(c==J_Safer) return 'J';
        if(c==Z_Again) return 'Z';
    }
}
using namespace Defines;

namespace Card_Stack{
    int CardStack[2005],top;
    int GetCard(){
        top=min(top+1,m);
        return CardStack[top];
    }
}
using namespace Card_Stack;

void Input(){
    read(n,m);
    FOR(i,1,n){
        Pig[i].Type=TypePig(getalpha());
        if(Pig[i].Type==F_FP) SumFP++;
        getalpha();
        FOR(j,1,4){
            Pig[i].Cards[j]=TypeCard(getalpha());
        }Pig[i].SumCards=Pig[i].Blood=4;
    }
    Pig[1].Show=Z_ZP;
    FOR(i,1,m){
        CardStack[i]=TypeCard(getalpha());
    }
}

void Delete(int i,int j){
    FOR(c,j,Pig[i].SumCards){
        Pig[i].Cards[c]=Pig[i].Cards[c+1];
    }Pig[i].SumCards--;
}

int Find_Next(int i){
    for(int j=i%n+1;;j=j%n+1){
        if(Pig[j].Type!=Died) return j;
    }
}

bool CanHate(int i,int j){
    switch(Pig[i].Type){
        case M_MP:
            if(Pig[j].Show==F_FP or Pig[j].Show==F_SP){
                return true;
            }return false;
        case Z_ZP:
            if(Pig[j].Show==F_FP){
                return true;
            }return false;
        case F_FP:
            if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                return true;
            }return false;
        case Died:
            return false;
    }
}

bool TryHate(int i,int j){
    switch(Pig[i].Type){
        case M_MP:
            if(Pig[j].Show==F_FP or Pig[j].Show==F_SP){
                return true;
            }return false;
        case Z_ZP:
            if(Pig[j].Show==F_FP){
                Pig[i].Show=Z_ZP;
                return true;
            }return false;
        case F_FP:
            if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                Pig[i].Show=F_FP;
                return true;
            }return false;
        case Died:
            return false;
    }
}

bool CanLove(int i,int j){
    if(Pig[j].Show==0 or Pig[j].Show==F_SP){
        return false;
    }else{
        switch(Pig[i].Type){
            case M_MP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    return true;
                }return false;
            case Z_ZP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    return true;
                }return false;
            case F_FP:
                if(Pig[j].Show==F_FP){
                    return true;
                }return false;
            case Died:
                return false;
        }
    }
}

bool TryLove(int i,int j){
    if(Pig[j].Show==0 or Pig[j].Show==F_SP){
        return false;
    }else{
        switch(Pig[i].Type){
            case M_MP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    return true;
                }return false;
            case Z_ZP:
                if(Pig[j].Type==M_MP or Pig[j].Show==Z_ZP){
                    Pig[i].Show=Z_ZP;
                    return true;
                }return false;
            case F_FP:
                if(Pig[j].Show==F_FP){
                    Pig[i].Show=F_FP;
                    return true;
                }return false;
            case Died:
                return false;
        }
    }
}

bool TryKills(int i){
    FOR(c,1,Pig[i].SumCards){
        if(Pig[i].Cards[c]==K_Kills){
            Delete(i,c);
            return true;
        }
    }return false;
}

bool TryFight(int i,int j){
    if(Pig[i].Type==Z_ZP and Pig[j].Type==M_MP){
        return false;
    }else{
        FOR(c,1,Pig[i].SumCards){
            if(Pig[i].Cards[c]==K_Kills){
                Delete(i,c);
                return true;
            }
        }return false;
    }
}

bool TryDodge(int i){
    FOR(c,1,Pig[i].SumCards){
        if(Pig[i].Cards[c]==D_Dodge){
            Delete(i,c);
            return true;
        }
    }return false;
}

bool TryHealth(int i){
    FOR(c,1,Pig[i].SumCards){
        if(Pig[i].Cards[c]==P_Peach){
            Pig[i].Blood++;
            Delete(i,c);
            return true;
        }
    }
    return false;
}

bool TrySafer(int i,int j,bool s){
    if((s==true and CanLove(i,j)) or (s==false and CanHate(i,j))){
        FOR(c,1,Pig[i].SumCards){
            if(Pig[i].Cards[c]==J_Safer){
                if(s==true) TryLove(i,j);
                else        TryHate(i,j);
                Delete(i,c);
                int k=Find_Next(i);
                while(k!=i){
                    if(TrySafer(k,j,1-s)==true) return false;
                    k=Find_Next(k);
                }return true;
            }
        }
    }
    return false;
}

bool TryBreak(int i,int j){
    int k=i;
    do{ if(TrySafer(k,j,true)==true){
            return true;
        }k=Find_Next(k);
    }while(k!=i);
    return false;
}

void CheckHurtAll(int i,int j){
    if(Pig[j].Type==M_MP and Pig[i].Show==0){
        Pig[i].Show=F_SP;
    }
}

void CheckKill(int i,int j){
    if(Pig[j].Type==M_MP or (Pig[j].Type==F_FP and SumFP==1)){
        Pig[j].Type=Died;
        if(Pig[1].Type!=Died) puts("MP");
        else                  puts("FP");
        FOR(i,1,n){
            if(Pig[i].Type==Died){
                puts("DEAD");
            }else{
                FOR(c,1,Pig[i].SumCards){
                    printf("%c ",ToChar(Pig[i].Cards[c]));
                }puts("");
            }
        }
        exit(0);
    }
    if(Pig[j].Type==F_FP){
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        Pig[i].Cards[++Pig[i].SumCards]=GetCard();
        SumFP--;
    }else if(Pig[j].Type==Z_ZP and Pig[i].Type==M_MP){
        Pig[i].IsAgain=false;
        Pig[i].SumCards=0;
    }
    Pig[j].Type=Died;
}

void Action(int i){
    bool IsAction=true,Iskill=false;
    while(IsAction){
        IsAction=false;
        FOR(c,1,Pig[i].SumCards){
            int card=Pig[i].Cards[c];
            if(card==P_Peach and Pig[i].Blood!=4){
                Delete(i,c);
                Pig[i].Blood++;
                IsAction=true;break;
            }if(card==K_Kills and (!Iskill or Pig[i].IsAgain)){
                int j=Find_Next(i);
                if(CanHate(i,j)){
                    Delete(i,c);
                    TryHate(i,j);
                    Iskill=true;
                    if(TryDodge(j)==false){
                        Pig[j].Blood--;
                        if(Pig[j].Blood<=0 and TryHealth(j)==false){
                            CheckKill(i,j);
                        }
                    }
                    IsAction=true;break;
                }
            }else if(card==F_Fight){
                int j;
                if(Pig[i].Type==F_FP and TryHate(i,1)){
                    j=1;
                }else{
                    j=Find_Next(i);
                    while(!CanHate(i,j) and i!=j){
                        j=Find_Next(j);
                    }
                }
                if(i!=j){
                    Delete(i,c);
                    TryHate(i,j);
                    if(!TryBreak(i,j)){
                        int Out=1;
                        while(TryFight((Out==0)?i:j,(Out==0)?j:i)){
                            Out=1-Out;
                        }
                        int from=(((Out==0)?j:i));
                        j=((Out==0)?i:j);
                        Pig[j].Blood--;
                        if(Pig[j].Blood<=0 and TryHealth(j)==false){
                            CheckKill(from,j);
                        }
                    }
                    IsAction=true;break;
                }
            }else if(card==N_North){
                Delete(i,c);
                int j=Find_Next(i);
                while(j!=i){
                    if(!TryBreak(i,j)){
                        if(!TryKills(j)){
                            Pig[j].Blood--;
                            CheckHurtAll(i,j);
                            if(Pig[j].Blood<=0 and TryHealth(j)==false){
                                CheckKill(i,j);
                            }
                        }
                    }
                    j=Find_Next(j);
                }
                IsAction=true;break;
            }else if(card==W_Arrow){
                Delete(i,c);
                int j=Find_Next(i);
                while(j!=i){
                    if(!TryBreak(i,j)){
                        if(!TryDodge(j)){
                            Pig[j].Blood--;
                            CheckHurtAll(i,j);
                            if(Pig[j].Blood<=0 and TryHealth(j)==false){
                                CheckKill(i,j);
                            }
                        }
                    }
                    j=Find_Next(j);
                }
                IsAction=true;break;
            }else if(card==Z_Again){
                Pig[i].IsAgain=true;
                Delete(i,c);
                IsAction=true;break;
            }
        }
        if(Pig[i].Type==Died) break;
    }
}


signed main()
{
    Input();
    int now=1;
    while(true){
        Pig[now].Cards[++Pig[now].SumCards]=GetCard();
        Pig[now].Cards[++Pig[now].SumCards]=GetCard();
        Action(now);
        now=Find_Next(now);
    }
    return 0;
}

The End.

第一个紫大模拟交了 31 发。

我怎么这么菜 /kk