社区讨论
求调
P2482[SDOI2010] 猪国杀参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lygxcdq3
- 此快照首次捕获于
- 2024/07/11 15:05 2 年前
- 此快照最后确认于
- 2025/01/14 17:29 去年
调了 年了,样例一直过不去,但是60分,求大佬看看。
CPP/*****************************************
备注:
******************************************/
#include<queue>
#include<math.h>
#include<stack>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<iomanip>
#include<map>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 2e5 + 10;
const int MR = 20 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int debug = false;//debug(肯定会崩溃的)
struct card//卡牌
{
bool flag;//是否出过
char card;//卡牌类型
};
#define itr vector<card>::iterator//容器
class PIG_GAME//记录每一头猪能干嘛~哎哟(
{
public:
void init(char id);//初始化猪
void start();//游戏开始
void getcard();//抽牌
void outcard();//出牌
void use(itr t, char ch);
bool findc(char ch);//找牌&出牌
int minusheal();
int plusheal();
void jump();//跳过
void make_rebel();//进入类反
void stop_rebel();//取消类反
void noequip();//卸下诸葛连弩
void hurt(PIG_GAME &that);//对that造成伤害
bool death();//濒临死亡
void killing(PIG_GAME &that);//杀that
void killed();//被杀了
bool usecard(char ch);//出卡牌
int try_kill();//寻找对象
void nowkill(PIG_GAME &that);//开始杀人
bool killres();//相应->杀
int findfight();//找人撅斗
void fight(PIG_GAME &that);//撅斗
void invasion();//南蛮入侵
bool invasionres();//相应->南蛮入侵
void shoot();//万箭齐发
bool shootres();//相应->万箭齐发
void bow();//诸葛连弩
bool nohurt(PIG_GAME &that);//无懈可击
bool starthurt();//无懈可击->对抗
int num;//编号
vector<card> hand;//牌
char identity;//这个猪的身份
int health;//生命值
bool equipped;//诸葛连弩
bool die;//死亡?
bool kill;//用杀
bool jumped;//跳过
bool rebel;//造反?
}pig[MR];
int n, m;
int mpig;//主 猪
int apig;//反猪
int htop = 1;//堆
bool over;//游戏结束了吗?
char win;//谁赢了
char cheap[MAXN];//π
void print()//输出答案
{
if(win == 'M')cout << "MP\n";
else cout << "FP\n";
for(int i = 1;i <= n; i++)
{
if(pig[i].die)cout << "DEAD\n";
else{
for(itr j = pig[i].hand.begin(); j < pig[i].hand.end(); j++)
{
if(j->flag)
{
cout << j->card << ' ';
}
}
cout << endl;
}
}
}
signed main()
{
cin >> n >> m;
char tmp;
for(int i = 1;i <= n; i++)
{
string s;
cin >> s;
if(s[0] == 'M')mpig = i;
else if(s[0] == 'F')apig++;
pig[i].init(s[0]);
while((tmp = getchar()) != '\n')
{
if(tmp >= 'A' && tmp <= 'Z')
{
pig[i].hand.push_back({true, tmp});
}
}
}
for(int i = 1;i <= m; i++)
{
while((tmp = getchar()) < 'A' || tmp > 'Z')
{
continue;
}
cheap[i] = tmp;
}
for(int i = 1;i <= n; i++)
{
pig[i].health = 4;
pig[i].equipped = pig[i].die = pig[i].kill = false;
pig[i].jumped = pig[i].rebel = false;
pig[i].num = i;
}
for(int i = m + 1; i <= 5000; i++)
{
cheap[i] = cheap[m];
}
pig[mpig].jump();
if(apig == 0)
{
win = 'M';//主猪赢力(喜
print();
exit(0);
}
int i = 0;
while(true)
{
i = i % n + 1;
if(pig[i].die)continue;
if(debug)cout << i << "pig start his turn\n";
pig[i].start();
if(over)
{
print();
break;
}
}
return 0;
}
/////正片 开 始!
void PIG_GAME::init(char id){identity = id;}
void PIG_GAME::getcard(){hand.push_back({true,cheap[htop++]});}
int PIG_GAME::findfight()
{
if(identity == 'M')
{
for(int i = num % n + 1; i != num; i = i % n + 1)
{
if(pig[i].die)continue;
if(pig[i].rebel)return i;
if(pig[i].identity == 'F' && pig[i].jumped)return i;
}
}
else if(identity == 'Z')
{
for(int i = num % n + 1; i != num; i = i % n + 1)
{
if(pig[i].die)continue;
if(pig[i].identity == 'F' && pig[i].jumped)return i;
}
}
else
{
return mpig;
}
return 0;
}
int PIG_GAME::try_kill()
{
if(kill && !equipped)return 0;
if(identity == 'M')//主猪杀猪
{
for(int i = num % n + 1; i != num; i = i % n + 1)
{
if(pig[i].die)continue;
if(pig[i].rebel)return i;
if(pig[i].identity == 'F' && pig[i].jumped)return i;
else return 0;
}
}
else if(identity == 'Z')//忠猪杀猪
{
for(int i = num % n + 1; i != num; i = i % n + 1)
{
if(pig[i].die)continue;
if(pig[i].identity == 'F' && pig[i].jumped)return i;
else return 0;
}
}
else //反猪杀猪
{
for(int i = num % n + 1; i != num; i = i % n + 1)
{
if(pig[i].die)continue;
if(pig[i].identity == 'F' && pig[i].jumped)return i;
else return 0;
}
}
}
bool PIG_GAME::usecard(char ch)
{
if(ch == 'P' && health < 4)return true;
else if((ch == 'K' && try_kill()) || (ch == 'F' && findfight()) || ch == 'N' || ch == 'W' || ch == 'Z')return true;
return false;
}
void PIG_GAME::jump(){jumped = true;}
void PIG_GAME::make_rebel(){rebel = true;}
void PIG_GAME::stop_rebel(){rebel = false;}
bool PIG_GAME::findc(char ch)
{
for(itr i = hand.begin();i < hand.end();i++)
{
if(i->card == ch && i->flag)
{
i->flag = false;
if(debug) cout<<num<<" used a "<<ch<<endl;
return true;
}
}
return false;
}
bool PIG_GAME::killres()
{
return findc('D');
}
int PIG_GAME::minusheal()
{
return --health;
}
int PIG_GAME::plusheal()
{
return ++health;
}
bool PIG_GAME::death()
{
for(itr i = hand.begin(); i <hand.end(); i++)
{
if(i->card == 'P' && i->flag)
{
i->flag = false;
plusheal();
return false;
}
}
return true;
}
void PIG_GAME::noequip(){equipped = false;}
void PIG_GAME::killed(){die = true;}
void PIG_GAME::killing(PIG_GAME &that)
{
that.killed();
if(that.identity == 'M')
{
win = 'F';
over = true;
}
else if(that.identity == 'F')
{
apig--;
if(apig == 0)
{
win = 'M';
over = true;
return ;
}
getcard();
getcard();
getcard();
}
else if(identity == 'M' && that.identity == 'Z')
{
for(itr i = hand.begin();i < hand.end(); i++)
{
i->flag = false;
}
noequip();
}
}
void PIG_GAME::hurt(PIG_GAME &that)
{
that.minusheal();
if(that.health == 0 && that.death())
{
this->killing(that);
}
}
void PIG_GAME::nowkill(PIG_GAME &that)
{
jump();
stop_rebel();
kill = true;
if(!that.killres())hurt(that);
}
bool PIG_GAME::starthurt()
{
for(int i = num % n + 1;i != num;i = i % n + 1)
{
if(pig[i].die) continue;
if(identity == 'M' && pig[i].identity == 'Z') continue;
if(identity == 'Z' && pig[i].identity == 'Z') continue;
if(identity == 'F' && pig[i].identity == 'F') continue;
if(identity == 'Z' && pig[i].identity == 'M') continue;
if(pig[i].findc('J'))
{
pig[i].jump();
return !pig[i].starthurt();
}
}
return false;
}
bool PIG_GAME::nohurt(PIG_GAME &that)
{
if(!that.jumped) return false;
bool flag = true;
for(int i = num;i != num || flag;i = i % n + 1)
{
flag = false;
if(pig[i].die) continue;
if(that.identity == 'M' && pig[i].identity == 'F') continue;
if(that.identity == 'Z' && pig[i].identity == 'F') continue;
if(that.identity == 'F' && pig[i].identity == 'Z') continue;
if(that.identity == 'F' && pig[i].identity == 'M') continue;//寻找同势力
if(pig[i].findc('J'))
{
pig[i].jump();
return !pig[i].starthurt();
}
}
return false;
}
void PIG_GAME::fight(PIG_GAME &that)
{
jump();
stop_rebel();
if(nohurt(that))return ;
if(identity == 'M' && that.identity == 'Z')
{
hurt(that);
return ;
}
int whohurt;
while(1919810)
{
if(!that.findc('K')){whohurt = 2;break;}
if(!findc('K')){whohurt = 1;break;}
}
if(whohurt == 1){that.hurt(*this);}
else {hurt(that);}
}
bool PIG_GAME::invasionres(){return findc('K');}
void PIG_GAME::invasion()
{
for(int i = num % n + 1;i != num;i = i % n + 1)
{
if(pig[i].die)continue;
if(debug) cout<<"invasion->"<<i<<endl;
if(nohurt(pig[i]))continue;
if(!pig[i].invasionres())
{
hurt(pig[i]);
if(over)return ;
if(pig[i].identity == 'M' && !jumped)make_rebel();
}
}
}
bool PIG_GAME::shootres(){return findc('D');}
void PIG_GAME::shoot()
{
for(int i = num % n + 1;i != num;i = i % n + 1)
{
if(pig[i].die)continue;
if(debug) cout<<"shoot->"<<i<<endl;
if(nohurt(pig[i]))continue;
if(!pig[i].shootres())
{
hurt(pig[i]);
if(over)return ;
if(pig[i].identity == 'M' && !jumped)make_rebel();
}
}
}
void PIG_GAME::bow(){equipped = true;}
void PIG_GAME::use(itr i, char ch)
{
int tmp;
switch(ch)
{
case 'K':
if(tmp = try_kill())
{
i->flag = false;
if(debug) printf("%d used a kill to %d\n",num,tmp);
nowkill(pig[tmp]);
}
break;
case 'P':
i->flag = false;
if(debug) printf("%d used a peach\n",num);
plusheal();
break;
case 'F':
if(tmp = findfight())
{
i->flag = false;
if(debug) printf("%d used a fight to %d\n",num,tmp);
fight(pig[tmp]);
}
break;
case 'N':
i->flag = false;
if(debug) printf("%d used a invasion\n",num);
invasion();
break;
case 'W':
i->flag = false;
if(debug) printf("%d used a shoot\n",num);
shoot();
break;
case 'Z':
i->flag = false;
if(debug) printf("%d used a bow \n",num);
bow();
}
}
void PIG_GAME::outcard()
{
bool flag = true;
while(flag)
{
flag = false;
for(itr i = hand.begin(); i != hand.end(); i++)
{
if(i -> flag && usecard(i->card))
{
use(i, i->card);
if(die || over)return ;
i = hand.begin() - 1;
flag = true;
}
}
}
}
void PIG_GAME::start()
{
getcard();
getcard();
outcard();
if(debug)
{
for(int i = 1;i<=n;i++)
{
if(pig[i].die)continue;
printf("%d %c %d:",pig[i].num,pig[i].identity,pig[i].health);
PIG_GAME s = pig[i];
for(itr i = s.hand.begin();i < s.hand.end();i++) if(i->flag) printf("%c ",i->card);
printf("\n");
}
}
kill = false;
if(debug)cout<<endl;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...