开始之前获得 LJC00101 同志的提示,题面是假的(悲),牌要是用完了需要一直抽最后一张
好,那么整一个 struct ,大致整个框架,先写构造/折构函数。
using std::string;
const string FP = "FP", MP = "MP" , ZP = "ZP" ,P = "P", K = "K",D = "D",Z = "Z" , J = "J",F = "F",N = "N",W = "W" ;
struct Game{
static const int maxn = 15 , maxm = 2e3 + 5,Maxlife = 4;
int n,m;
string card[maxm];int cur = 1;int cnt = 0;bool win;//card/cur 维护牌堆,cnt 存活反猪数量,win 存谁赢
string Top(){return cur>m?card[m]:card[cur++];}
std::map<string,int> counter[maxn];string type[maxn];
std::vector<string> hand[maxn];int arrow[maxn];bool tf[maxn],tz[maxn],lfz[maxn];
int life[maxn];bool death[maxn];
//counter 表示各种牌的数量,hand 表示手牌,type 存角色身份,arrow 存是否有连弩,tf/tz/lfz 跳反/跳忠(为了方便,认为主公初始跳忠)/是否伤害过主公
//life 血量,death 是否死亡
void get_card(const int &id,string s);//抽卡
void eat(const int &id,string s);//用卡
inline int nxt(const int &id){return id==n?1:id+1;}//下一个人
int dist(int x,int y);//计算距离
void flow(const int &id,const int &Killer);//濒死/死亡
inline void hurt(int alpha,int beta);//造成伤害
void Sha(int alpha,int beta);//杀
int relation(int alpha,int beta);//alpha 认为 beta 是盟友/敌人/不明
bool call(int alpha,int beta,int Type);//alpha->beta ,type 表示是否有害/有利于 beta 返回是否生效
void battle(int alpha,int beta);//决斗
void Nan(const int &id);//南蛮
void Wan(const int &id);//万箭
void Move(const int &id);//行动
Game(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
std::cin>>type[i];
if(type[i]==FP) cnt++;if(type[i]==MP) tz[i] = 1;
for(int j=0;j<4;j++){
string s;std::cin>>s;
get_card(i,s);
}
life[i] = Maxlife;
}
for(int i=1;i<=m;i++) std::cin>>card[i];
for(int i=1;;i=nxt(i)){
if(death[i]) continue ;
get_card(i,Top()),get_card(i,Top());
Move(i);
}
}
~Game(){
if(win) puts("MP");else puts("FP");
for(int i=1;i<=n;i++){
if(death[i]) puts("DEAD");
else{
for(string s:hand[i]) std::cout<<s<<' ';
std::cout<<'\n';
}
}
exit(0);
}
}Steins_Gate;get_card/eat 很好实现,
void get_card(const int &id,string s){
hand[id].push_back(s);counter[id][s]++;
}
void eat(const int &id,string s){
counter[id][s]--;
for(auto it=hand[id].begin();it!=hand[id].end();it++)
if(*it==s) return hand[id].erase(it),void() ;
}dist 也还行,
int dist(int x,int y){
if(death[x]||death[y]) throw ;if(x==y) return 0 ;
int result = 0;
for(int i=x;i!=y;i=nxt(i)){
result += !death[i];
}
return result ;
}接下来开始写 flow ,名字是顺手打了个 Everything will flow 之后嫌太长,就改成了 flow
void flow(const int &id,const int &Killer){
// printf("flowing!! id:%d Killer:%d\n",id,Killer);
if(counter[id][P]) return eat(id,P),life[id]++,void() ;//自救;闲话,在当时,我忘记自救完要回血了,然后就看到一帮血量为负的妖魔鬼怪在那诸神之战,那打的是相当惨烈,在当时
death[id] = 1;
if(type[id]==MP){win = false;this->~Game();}
if(type[id]==FP){
if(--cnt == 0){win=true;this->~Game();}
for(int T=1;T<=3;T++) get_card(Killer,Top());
}
else{
if(type[Killer]==MP){
hand[Killer].clear(),counter[Killer].clear();
arrow[Killer] = 0;
}
}
}那么 hurt 也就好写了,造成伤害这个行为与跳忠/反无关,但是可能会让主公把你标反
inline void hurt(int alpha,int beta){
if(type[beta]==MP ) lfz[alpha] = 1;//把类反猪在判定关系的时候放在最后,这里就不用管 alpha 是否跳忠/反
if(--life[beta]==0) flow(beta,alpha);
}接着尝试先去完成没有锦囊牌的世界,就先写了杀
void Sha(int alpha,int beta){//杀
if(tz[beta]) tf[alpha]=1;
if(tf[beta]) tz[alpha]=1;
if(counter[beta][D]) return eat(beta,D),void() ;
hurt(alpha,beta);
}以及 relation :
int relation(int alpha,int beta){
//unsure -> 0 , enemy -> -1 , friend -> 1
if(type[alpha]!=FP && tf[beta]) return -1 ;
if(type[alpha]==FP && tz[beta]) return -1 ;
if(type[alpha]!=FP && tz[beta]) return 1 ;
if(type[alpha]==FP && tf[beta]) return 1 ;
if(type[alpha]==MP && lfz[beta]) return -1 ;
return 0 ;
}到这里去整一个阉割版的 Move 函数,就能获得 10 分的好成绩了!!
然后开始处理锦囊牌,,感觉还行
bool call(int alpha,int beta,int Type){//alpha->beta ,type 表示是否有害/有利于 beta 返回是否生效
bool tpo = 1;
for(int i=alpha;i!=alpha||tpo;i=nxt(i),tpo=0){
if(death[i]) continue ;
if((relation(i,beta)==1&&Type==1)||(relation(i,beta)==-1&&Type==0)){
if(counter[i][J]==0) continue ;
eat(i,J);
if(type[i]==FP) tf[i] = 1;
if(type[i]!=FP) tz[i] = 1;
return !call(i,beta,!Type) ;
}
}
return true ;
}
void battle(int alpha,int beta){
if(tz[beta]) tf[alpha] = 1;
if(tf[beta]) tz[alpha] = 1;
if(call(alpha,beta,1)){
int tp[2]={alpha,beta};
for(int cur=1;;cur^=1){
if(type[tp[cur]]==ZP && type[tp[!cur]]==MP) return hurt(tp[!cur],tp[cur]) ;
if(counter[tp[cur]][K]) eat(tp[cur],K);else return hurt(tp[!cur],tp[cur]) ;
}
}
}
void Nan(const int &id){
for(int i=nxt(id);i!=id;i=nxt(i)){
if(death[i]) continue ;
if(call(id,i,1)){
if(counter[i][K]) eat(i,K);
else hurt(id,i);
}
}
}
void Wan(const int &id){
for(int i=nxt(id);i!=id;i=nxt(i)){
if(death[i]) continue ;
if(call(id,i,1)){
if(counter[i][D]) eat(i,D);
else hurt(id,i);
}
}
}然后去把 Move 函数写好就行了,注意反贼优先冲主公
void Move(const int &id){
bool flag = false ;if(death[id]) throw ;
#define use counter[id][hand[id][i]]--,hand[id].erase(hand[id].begin()+i);
//你问我这里为什么不直接调用 eat ,而是要写 use 这个宏?……我也不知道
#define done i=-1;goto Next;
//为什么要 i=-1 ?因为一张牌打出去后有可能会使之前某张不能使用的牌可以使用
for(int i=0;i<(int)hand[id].size() && !death[id];i++){
//在当时,这里没有 && !death[id]
//然后就看到一个反贼决斗把自己决死了,但是却身残志坚,用他那强大的意志力,再硬生生拍下一张万箭带走队友
//真是太TM感人了
if(hand[id][i]==P){
if(life[id]==Maxlife) continue ;
use ;life[id] ++ ;done ;
}
if(hand[id][i]==K){
if(flag && !arrow[id]) continue ;
if(type[id]==FP && dist(id,1)<=1){
use ;Sha(id,1);
flag = 1;done ;
}
for(int j=nxt(id);j!=id;j=nxt(j)){
if(death[j]) continue ;
if(dist(id,j) <= 1 && relation(id,j)==-1){
use ;Sha(id,j) ;
flag = 1 ;done ;
}
}
}
if(hand[id][i]==Z){use ;arrow[id] = 1;done ;}
if(hand[id][i]==F){
if(type[id]==FP){
use ;battle(id,1);
done ;
}
for(int j=nxt(id);j!=id;j=nxt(j)){
if(death[j]) continue ;
if(relation(id,j)==-1){
use ;battle(id,j);
done ;
}
}
}
if(hand[id][i]==N){use ;Nan(id);done ;}
if(hand[id][i]==W){use ;Wan(id);done ;}
Next:;
}
}写了一个晚上,感觉还行;
调试的时候对着数据看猪猪们的神仙操作,就像看小梦写文一样,还挺欢乐的。