# bzoj1972: [Sdoi2010]猪国杀

www.lydsy.com/JudgeOnline/problem.php?id=1972

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXM 2001

#define Tao     ('P')
#define Sha     ('K')
#define Shan    ('D')
#define JueDou  ('F')
#define NanZhu  ('N')
#define WanJian ('W')
#define WuXie   ('J')
#define ZhuGe   ('Z')
#define DiYi    (-1)
#define None     0
#define YinQin   1

int LeftFan;
typedef struct PigBase *PtrPig;
void MoPai(PtrPig, int);
void Win();
struct PigBase
{
vector<char> ShouPai;
int blood;
PigBase(bool _tiao, char c1, char c2, char c3, char c4)
{
ShouPai.push_back(c1);
ShouPai.push_back(c2);
ShouPai.push_back(c3);
ShouPai.push_back(c4);
}
virtual bool IsZhu()const
{
return false;
}
virtual bool IsZhong()const
{
return false;
}
virtual bool IsFan()const
{
return false;
}
void PrintInfo()
{
else
{
if (ShouPai.size() == 0)
{
putchar('\n');
return;
}
for (vector<char>::iterator i = ShouPai.begin(); i + 1 != ShouPai.end(); ++i)
printf("%c ", *i);
printf("%c\n", ShouPai.back());
}
}
virtual void ChuPai() = 0;
void BinSi(PtrPig sender)
{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), Tao);
if (p == ShouPai.end())
{
if (IsFan())
--LeftFan;
Win();
if (IsFan())
MoPai(sender, 3);
if (IsZhong() && sender->IsZhu())
{
sender->ShouPai.clear();
sender->HaveZhuGe = false;
}
}
else
{
ShouPai.erase(p);
++blood;
}
}
void GotSha(PtrPig sender)
{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), Shan);
if (p == ShouPai.end())
{
--blood;
if (blood == 0)
BinSi(sender);
}
else
ShouPai.erase(p);
}
virtual bool QuaryWuXie(PtrPig, PtrPig, PigLinker, int) = 0;
virtual void GotJueDou(PtrPig) = 0;
virtual void GotNanZhu(PtrPig sender)
{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), Sha);
if (p == ShouPai.end())
{
--blood;
if (blood == 0)
BinSi(sender);
}
else
ShouPai.erase(p);
}
virtual void GotWanJian(PtrPig sender)
{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), Shan);
if (p == ShouPai.end())
{
--blood;
if (blood == 0)
BinSi(sender);
}
else
ShouPai.erase(p);
}
void Tiao();
};
struct PigZhu: public PigBase
{
vector<PtrPig> LeiFan;
PigZhu(char c1, char c2, char c3, char c4)
: PigBase(true, c1, c2, c3, c4) {}
bool IsZhu()const
{
return true;
}
void ChuPai();
void GotJueDou(PtrPig sender)
{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), Sha);
if (p == ShouPai.end())
{
--blood;
if (blood == 0)
BinSi(sender);
}
else
{
ShouPai.erase(p);
sender->GotJueDou(this);
}
}
void GotNanZhu(PtrPig sender)
{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), Sha);
if (p == ShouPai.end())
{
--blood;
if (blood == 0)
BinSi(sender);
if (!sender->tiao && find(LeiFan.begin(), LeiFan.end(), sender) == LeiFan.end())
LeiFan.push_back(sender);
}
else
ShouPai.erase(p);
}
void GotWanJian(PtrPig sender)
{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), Shan);
if (p == ShouPai.end())
{
--blood;
if (blood == 0)
BinSi(sender);
if (!sender->tiao && find(LeiFan.begin(), LeiFan.end(), sender) == LeiFan.end())
LeiFan.push_back(sender);
}
else
ShouPai.erase(p);
}
};
struct PigZhong: public PigBase
{
PigZhong(char c1, char c2, char c3, char c4)
: PigBase(false, c1, c2, c3, c4) {}
bool IsZhong()const
{
return true;
}
void ChuPai();
void GotJueDou(PtrPig sender)
{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), Sha);
if (sender->IsZhu() || p == ShouPai.end())
{
--blood;
if (blood == 0)
BinSi(sender);
}
else
{
ShouPai.erase(p);
sender->GotJueDou(this);
}
}
};
struct PigFan: public PigBase
{
PigFan(char c1, char c2, char c3, char c4)
: PigBase(false, c1, c2, c3, c4) {}
bool IsFan()const
{
return true;
}
void ChuPai();
void GotJueDou(PtrPig sender)
{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), Sha);
if (p == ShouPai.end())
{
--blood;
if (blood == 0)
BinSi(sender);
}
else
{
ShouPai.erase(p);
sender->GotJueDou(this);
}
}
};

{
PtrPig data;
: data(_data), next(_next) {}
};

char PaiDui[MAXM];
int m;

void Init()
{
LeftFan = 0;
int n;
scanf("%d%d", &n, &m);
char c1, c2, c3, c4, s[4];
for (int i = 0; i < n; ++i)
{
scanf("%s %c %c %c %c", s, &c1, &c2, &c3, &c4);
if (i == 0)
Zhu = PigList = new PigLink(new PigZhu(c1, c2, c3, c4));
else if (strcmp(s, "ZP") == 0)
{
PigList->next = new PigLink(new PigZhong(c1, c2, c3, c4));
PigList = PigList->next;
}
else
{
PigList->next = new PigLink(new PigFan(c1, c2, c3, c4));
PigList = PigList->next;
++LeftFan;
}
}
PigList->next = Zhu;
PigList = Zhu;
for (int i = 0; i < m; ++i)
scanf(" %c", &PaiDui[i]);
}

void MoPai(PtrPig x, int t)
{
for (int i = 0; i < t; ++i)
{
}
}

void Win()
{
{
printf(LeftFan ? "FP\n" : "MP\n");
Zhu->data->PrintInfo();
for (PigLinker i = Zhu->next; i != Zhu; i = i->next)
i->data->PrintInfo();
exit(0);
}
}

int main()
{
long ct = 1;
for (Init();; PigList = PigList->next, ++ct)
{
continue;
MoPai(PigList->data, 2);
PigList->data->ChuPai();
}
return 0;
}

{
return true;
for (PigLinker i = sender->next; i != sender; i = i->next)
return true;
return false;
}

{
for (PigLinker i = sender->next; i != sender; i = i->next)
i->data->GotNanZhu(sender->data);
}

{
for (PigLinker i = sender->next; i != sender; i = i->next)
i->data->GotWanJian(sender->data);
}

void PigZhu::ChuPai()
{
bool UsedSha = false;
for (vector<char>::iterator i = ShouPai.begin(); i != ShouPai.end();)
if (*i == Tao)
{
if (blood != 4)
{
i = ShouPai.erase(i);
++blood;
}
else
++i;
}
else if (*i == Sha)
{
if (!UsedSha || HaveZhuGe)
{
for (j = PigList->next; j != PigList; j = j->next)
{
continue;
if (j->data->IsFan() && j->data->tiao)
break;
if (find(LeiFan.begin(), LeiFan.end(), j->data) != LeiFan.end())
break;
j = PigList;
break;
}
if (j != PigList)
{
ShouPai.erase(i);
UsedSha = true;
j->data->GotSha(this);
i = ShouPai.begin();
}
else
++i;
}
else
++i;
}
else if (*i == Shan)
{
++i;
continue;
}
else if (*i == JueDou)
{
for (j = PigList->next; j != PigList; j = j->next)
{
continue;
if (j->data->IsFan() && j->data->tiao)
break;
if (find(LeiFan.begin(), LeiFan.end(), j->data) != LeiFan.end())
break;
}
if (j != PigList)
{
ShouPai.erase(i);
if (!AllQuaryWuXie(PigList, j->data, DiYi))
j->data->GotJueDou(this);
i = ShouPai.begin();
}
else
++i;
}
else if (*i == NanZhu)
{
ShouPai.erase(i);
AllGotNanZhu(PigList);
i = ShouPai.begin();
}
else if (*i == WanJian)
{
ShouPai.erase(i);
AllGotWanJian(PigList);
i = ShouPai.begin();
}
else if (*i == WuXie)
{
++i;
continue;
}
else if (*i == ZhuGe)
{
ShouPai.erase(i);
HaveZhuGe = true;
i = ShouPai.begin();
}
}

void PigZhong::ChuPai()
{
bool UsedSha = false;
for (vector<char>::iterator i = ShouPai.begin(); i != ShouPai.end();)
if (*i == Tao)
{
if (blood != 4)
{
i = ShouPai.erase(i);
++blood;
}
else
++i;
}
else if (*i == Sha)
{
if (!UsedSha || HaveZhuGe)
{
for (j = PigList->next; j != PigList; j = j->next)
{
continue;
if (j->data->IsFan() && j->data->tiao)
break;
j = PigList;
break;
}
if (j != PigList)
{
PigList->data->Tiao();
ShouPai.erase(i);
UsedSha = true;
j->data->GotSha(this);
i = ShouPai.begin();
}
else
++i;
}
else
++i;
}
else if (*i == Shan)
{
++i;
continue;
}
else if (*i == JueDou)
{
for (j = PigList->next; j != PigList; j = j->next)
{

continue;
if (j->data->IsFan() && j->data->tiao)
break;
}
if (j != PigList)
{
ShouPai.erase(i);
PigList->data->Tiao();
if (!AllQuaryWuXie(PigList, j->data, DiYi))
{
j->data->GotJueDou(this);
return;
}
i = ShouPai.begin();
}
else
++i;
}
else if (*i == NanZhu)
{
ShouPai.erase(i);
AllGotNanZhu(PigList);
i = ShouPai.begin();
}
else if (*i == WanJian)
{
ShouPai.erase(i);
AllGotWanJian(PigList);
i = ShouPai.begin();
}
else if (*i == WuXie)
{
++i;
continue;
}
else if (*i == ZhuGe)
{
ShouPai.erase(i);
HaveZhuGe = true;
i = ShouPai.begin();
}
}

void PigFan::ChuPai()
{
bool UsedSha = false;
for (vector<char>::iterator i = ShouPai.begin(); i != ShouPai.end();)
if (*i == Tao)
{
if (blood != 4)
{
i = ShouPai.erase(i);
++blood;
}
else
++i;
}
else if (*i == Sha)
{
if (!UsedSha || HaveZhuGe)
{
for (j = PigList->next; j != PigList; j = j->next)
{

continue;
if (j->data->IsZhu() || (j->data->IsZhong() && j->data->tiao))
break;
j = PigList;
break;
}
if (j != PigList)
{
PigList->data->Tiao();
ShouPai.erase(i);
UsedSha = true;
j->data->GotSha(this);
i = ShouPai.begin();
}
else
++i;
}
else
++i;
}
else if (*i == Shan)
{
++i;
continue;
}
else if (*i == JueDou)
{
PigList->data->Tiao();
ShouPai.erase(i);
if (!AllQuaryWuXie(PigList, Zhu->data, DiYi))
{
Zhu->data->GotJueDou(this);
return;
}
i = ShouPai.begin();
}
else if (*i == NanZhu)
{
ShouPai.erase(i);
AllGotNanZhu(PigList);
i = ShouPai.begin();
}
else if (*i == WanJian)
{
ShouPai.erase(i);
AllGotWanJian(PigList);
i = ShouPai.begin();
}
else if (*i == WuXie)
{
++i;
continue;
}
else if (*i == ZhuGe)
{
ShouPai.erase(i);
HaveZhuGe = true;
i = ShouPai.begin();
}
}

{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), WuXie);
if (p == ShouPai.end())
return false;
if (k == DiYi)
{
return false;
|| (sender->IsFan() && sender->tiao))
{
ShouPai.erase(p);
return !AllQuaryWuXie(me, sender, DiYi) && !AllQuaryWuXie(me, receiver, YinQin);
}
}
else if (k == None)
{
return false;
{
ShouPai.erase(p);
}
}
else if (k == YinQin)
{
{
ShouPai.erase(p);
return !AllQuaryWuXie(me, sender, DiYi) && !AllQuaryWuXie(me, receiver, DiYi);
}
}
return false;
}
{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), WuXie);
if (p == ShouPai.end())
return false;
if (k == DiYi)
{
return false;
|| (sender->IsFan() && sender->tiao))
{
Tiao();
ShouPai.erase(p);
return !AllQuaryWuXie(me, sender, DiYi) && !AllQuaryWuXie(me, receiver, YinQin);
}
}
else if (k == None)
{
return false;
{
Tiao();
ShouPai.erase(p);
}
}
else if (k == YinQin)
{
{
Tiao();
ShouPai.erase(p);
return !AllQuaryWuXie(me, sender, DiYi) && !AllQuaryWuXie(me, receiver, DiYi);
}
}
return false;
}
{
vector<char>::iterator p = find(ShouPai.begin(), ShouPai.end(), WuXie);
if (p == ShouPai.end())
return false;
if (k == DiYi)
{
return false;
|| (sender->IsZhong() && sender->tiao))
{
Tiao();
ShouPai.erase(p);
return !AllQuaryWuXie(me, sender, DiYi) && !AllQuaryWuXie(me, receiver, YinQin);
}
}
else if (k == None)
{
return false;
{
Tiao();
ShouPai.erase(p);
}
}
else if (k == YinQin)
{
if (sender->IsZhu() || (sender->IsZhong() && receiver->tiao)
{
Tiao();
ShouPai.erase(p);
return !AllQuaryWuXie(me, sender, DiYi) && !AllQuaryWuXie(me, receiver, DiYi);
}
}
return false;
}

void PigBase::Tiao()
{
tiao = true;
vector<PtrPig>::iterator p = find(((PigZhu *)(Zhu->data))->LeiFan.begin(), ((PigZhu *)(Zhu->data))->LeiFan.end(), this);
if (p != ((PigZhu *)(Zhu->data))->LeiFan.end())
((PigZhu *)(Zhu->data))->LeiFan.erase(p);
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120