从今天下午开始看题 于2022.10.4 19:26:23在 \(loj\) \(ac\)
没有大改,没有重构,框架一遍过
下面是原版代码
code
#include<bits/stdc++.h>
using namespace std;
#define MP 3
#define ZP 1
#define FP 2
char in[100];
int n, m;
char muopai(){if(m){cin >> in;--m;}return in[0];
}
int cntfp;
struct PIG{int sf;//身份 1 忠 2 反 3 主bool jump_zhong, jump_fan, lei_fan, have_zhuangbei;int hp;int nxt, id, from;vector<char>sp;//手牌void mp(int x){//摸牌,张数for(int i = 1; i <= x; ++i)sp.push_back(muopai());// cout << " I mp :: ";// for(char c : sp)cout << c << " " ;// cout << endl;}
}p[15];
bool game_over;void MAKE_DR(int from, int to){// cout << from << "bdy to " << to << endl;if(p[from].sf == MP)return;if(p[to].sf == MP || p[to].jump_zhong){p[from].jump_fan = 1;return;}if(p[to].jump_fan){p[from].jump_zhong = 1;return;}
}
void MAKE_FRIEND(int from, int to){// cout << from << " xyq to " << to << endl;if(p[to].sf == MP)p[from].jump_zhong = 1, p[from].lei_fan = 0;p[from].jump_fan |= p[to].jump_fan;p[from].jump_zhong |= p[to].jump_zhong;
}
void NEED_TAO(int x, int from){auto y = p[x].sp.begin();for(; y != p[x].sp.end(); ++y)if((*y) == 'P'){p[x].sp.erase(y); ++p[x].hp; return;}p[p[x].from].nxt = p[x].nxt;p[p[x].nxt].from = p[x].from;if(p[x].sf == MP){game_over = 1; return;}if(p[x].sf == ZP && p[from].sf == MP){p[from].sp.clear(); p[from].have_zhuangbei = 0; return;}if(p[x].sf == FP){--cntfp; if(cntfp == 0){game_over = 1; return;} p[from].mp(3);}
}
bool NEED_SHAN(int x){auto y = p[x].sp.begin();for(; y != p[x].sp.end(); ++y)if((*y) == 'D'){p[x].sp.erase(y);return true;}return false;
}
bool NEED_SHA(int x){auto y = p[x].sp.begin();for(; y != p[x].sp.end(); ++y)if((*y) == 'K'){p[x].sp.erase(y);return true;}return false;
}
bool NEED_WXKJ(int x){auto y = p[x].sp.begin();for(; y != p[x].sp.end(); ++y)if((*y) == 'J'){p[x].sp.erase(y);return true;}return false;
}
void USE_KILL(int from, int to){// cout << from << "use KILL to" << to << endl;if(p[from].sf != MP || p[to].sf != ZP)MAKE_DR(from, to);if(!NEED_SHAN(to)){--p[to].hp; if(p[to].hp < 1)NEED_TAO(to, from);}
}bool check_make_friend(int now, int x){if(p[x].sf == MP && (p[now].sf == ZP || p[now].sf == MP))return true;if(p[x].jump_zhong && (p[now].sf == MP || p[now].sf == ZP))return true;if(p[x].jump_fan && p[now].sf == FP)return true;return false;
}
bool check_make_dr(int now, int x){if(now == x)return false;if(p[x].sf == MP && p[now].sf == FP)return true;if(p[x].jump_fan && (p[now].sf == MP || p[now].sf == ZP))return true;if(p[x].jump_zhong && p[now].sf == FP)return true;if(p[x].lei_fan && p[now].sf == MP)return true;return false;
}
bool get_WXKJ_dr(int x){int now = p[x].nxt;while(now != x){if(check_make_dr(now, x) && NEED_WXKJ(now)){MAKE_DR(now, x);if(get_WXKJ_dr(now) == false)return true;else return false;}now = p[now].nxt;}return false;
}
bool get_WXKJ_friend(int x, int used){int now = used;do{// if(now == 5 && x == 4)cout << check_make_friend(now, x) << " " << p[x].jump_fan << endl;if(check_make_friend(now, x) && NEED_WXKJ(now)){MAKE_FRIEND(now, x);if(get_WXKJ_dr(now) == false)return true;else return false;}now = p[now].nxt;}while(now != used);return false;
}void USE_FIGHT(int from, int to){if(p[from].sf == MP && p[to].sf == ZP){if(get_WXKJ_friend(to, from))return;--p[to].hp;if(p[to].hp < 1)NEED_TAO(to, from);return;}MAKE_DR(from, to);if(get_WXKJ_friend(to, from))return;for(int round = 1; true; ++round){if(round & 1){if(NEED_SHA(to))continue;--p[to].hp;if(p[to].hp < 1)NEED_TAO(to, from);}else {if(NEED_SHA(from))continue;--p[from].hp;if(p[from].hp < 1)NEED_TAO(from, to);}break;}
}
void USE_NZRQ(int from){// cout << from << " used NZRQ" << endl;int now = p[from].nxt;while(now != from){int nxt = p[now].nxt;if(!get_WXKJ_friend(now, from))if(!NEED_SHA(now)){--p[now].hp;if(p[now].sf == MP)p[from].lei_fan = 1;if(p[now].hp < 1)NEED_TAO(now, from);}if(game_over)return;now = nxt;}// cout << p[now].hp << " " << p[now].jump_fan << " " << p[now].jump_zhong << " " << p[now].lei_fan << endl;}
void USE_WJQF(int from){// cout << from << " used WJQF" << endl;int now = p[from].nxt;while(now != from){int nxt = p[now].nxt;if(!get_WXKJ_friend(now, from))if(!NEED_SHAN(now)){--p[now].hp;if(p[now].sf == MP)p[from].lei_fan = 1;if(p[now].hp < 1)NEED_TAO(now, from);}if(game_over)return;now = nxt;}
}
void print(){// for(int i = 1; i <= n; ++i){// cout << i << " " << p[i].hp << " ";// if(p[i].hp > 0){// for(char c : p[i].sp)cout << c << " ";// cout << endl;// }else cout << "DEAD\n";// }// cout << endl;// for(int i = 1; i <= n; ++i)cout << p[i].from << " " << p[i].nxt << " ";// cout << endl;
}
int find_DR(int now){int l = p[now].nxt;while(l != now){if(p[l].hp < 1){l = p[l].nxt;continue;}if(p[now].sf == FP){if(p[l].sf == MP)return l;if(p[l].jump_zhong)return l;}if(p[now].sf == ZP){if(p[l].jump_fan)return l;}if(p[now].sf == MP){if(p[l].jump_fan ||(!p[l].jump_zhong && p[l].lei_fan))return l;}l = p[l].nxt;}return 0;
}
void play(int now){bool out = 1, CAN_KILL = 1;while(out && !game_over && p[now].hp > 0){out = 0;auto x = p[now].sp.begin();for(; x != p[now].sp.end(); ++x){if((*x) == 'P' && p[now].hp < 4){++p[now].hp; out = 1; p[now].sp.erase(x); break;}if((*x) == 'K' && (CAN_KILL || p[now].have_zhuangbei)){int dr = find_DR(now);if(dr == p[now].nxt){out = 1; CAN_KILL = 0;p[now].sp.erase(x);USE_KILL(now, dr);break;}}if((*x) == 'F'){int dr = find_DR(now);if(p[now].sf == FP)dr = 1;if(dr){out = 1;p[now].sp.erase(x);USE_FIGHT(now, dr);break;}}if((*x) == 'N'){p[now].sp.erase(x);out = 1;USE_NZRQ(now);break;}if((*x) == 'W'){p[now].sp.erase(x);out = 1;USE_WJQF(now);break;}if((*x) == 'Z'){p[now].have_zhuangbei = 1;p[now].sp.erase(x);out = 1;break;}}if(out)print();}
}void start_game(){int now = 1;do{if(p[now].hp < 1){now = p[now].nxt;continue;}// cout << now << " ";p[now].mp(2);play(now);now = p[now].nxt;}while(!game_over);
}int main(){cin >> n >> m;m += n * 4;for(int i = 1; i <= n; ++i){cin >> in;if(in[0] == 'M')p[i].sf = MP;if(in[0] == 'Z')p[i].sf = ZP;if(in[0] == 'F')p[i].sf = FP, ++cntfp;p[i].mp(4); p[i].hp = 4; p[i].nxt = i + 1; p[i].id = i; p[i].from = i - 1;}p[1].from = n;p[n].nxt = 1;start_game();if(cntfp)cout << "FP\n";else cout << "MP\n";for(int i = 1; i <= n; ++i)if(p[i].hp > 0){for(char c : p[i].sp)cout << c << " ";cout << endl;}else cout << "DEAD\n";return 0;
}