QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619299 | #4170. 猪国杀 | McIron233 | 100 ✓ | 17ms | 4172kb | C++14 | 7.8kb | 2024-10-07 13:48:28 | 2024-10-07 13:48:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct Player{
// player info
list<char>Cards;
int HP,withZ,Dead,AbleToPlayK;
int GuessID[15];
// The Value of GuessID:
// 0: Cannot Determine
// 1: ZP
// 2: FP
// 3: (for MP only) Similar to FP
string Identity;
void PlayerInit(){
withZ=0; Cards.clear();
HP=4; Dead=0;
memset(GuessID,0,sizeof(GuessID));
}
}player[15];
list<char>CardPile,Tmp;
int PlayerCount,CardPileCount,TT,CurrentPlayer;
int CurrentInjurySource,FPCount,ClearMP;
string Result="I don't know";
void Debug(){
// to do: J(wu xie ke ji)
// to debug: NextPlayer
// to debug: JudgeDead
// to debug: Fight(WIP)
// to debug: Duel
for(int i=1;i<=PlayerCount;++i){
cout<<player[i].Identity<<" "<<player[i].HP<<" "<<player[i].withZ<<'\n';
for(int j=1;j<=PlayerCount;++j)
cout<<player[i].GuessID[j]<<" ";
cout<<'\n';
for(char x:player[i].Cards)cout<<x<<" ";
cout<<'\n'; if(i!=PlayerCount)cout<<'\n';
}
int j=0; for(char ch:CardPile){
cout<<ch<<" "; ++j;
if(j==10)break;
} cout<<"\n";
}
int CalcDist(int u,int v){
int res=-1;
for(int i=u;;i=(i+1>PlayerCount?1:i+1)){
res+=(1-player[i].Dead); if(i==v)return res;
} return 114514;
}
int NextPlayer(int I){
for(int i=1;i<=PlayerCount;++i){
if(player[i].Dead || i==I)continue;
if(CalcDist(I,i)==1)return i;
} return I+1;
}
bool Revi(int i){
if(player[i].Dead){
Tmp.clear();
player[i].Cards.clear();
player[i].withZ=0;
}
while(!Tmp.empty()){
player[i].Cards.push_front(Tmp.front());
Tmp.pop_front();
} return 1;
}
void Output(){
cout<<Result<<'\n';
for(int i=1;i<=PlayerCount;++i){
if(player[i].Dead){ cout<<"DEAD\n"; continue; }
while(!player[i].Cards.empty()){
cout<<player[i].Cards.front()<<" ";
player[i].Cards.pop_front();
} cout<<'\n';
} exit(0);
}
void Input(){
cin>>PlayerCount>>CardPileCount;
for(int i=1;i<=PlayerCount;++i){
player[i].PlayerInit();
cin>>player[i].Identity;
if(player[i].Identity=="FP")++FPCount;
for(int j=1;j<=4;++j){
char Cd; cin>>Cd;
player[i].Cards.push_back(Cd);
}
} for(int i=1;i<=CardPileCount;++i){
char Cd; cin>>Cd;
CardPile.push_back(Cd);
} for(int i=1;i<=10000;++i)
CardPile.push_back(CardPile.back());
}
int JudgeAndPlayTheCard(int i,char Card){
int T=player[i].Cards.size(),flg=1; list<char>tmp;
while(T--){
char Cur=player[i].Cards.front(); player[i].Cards.pop_front();
if(Cur==Card){
flg=0; break;
} tmp.push_front(Cur);
} while(!tmp.empty()){
player[i].Cards.push_front(tmp.front());
tmp.pop_front();
} if(Card=='J')return (flg xor 1);
player[i].HP-=flg; return flg;
}
void JudgeDead(int i){
int T=player[i].Cards.size(); list<char>tmp;
while(T--){
char Cur=player[i].Cards.front(); player[i].Cards.pop_front();
if(Cur=='P'){
++player[i].HP;
while(!tmp.empty()){
player[i].Cards.push_front(tmp.front());
tmp.pop_front();
} return;
} tmp.push_front(Cur);
} player[i].Dead=1; player[i].withZ=0;
if(i==1){
Result="FP";
Revi(CurrentPlayer);
Output();
}
if(player[i].Identity=="FP"){
--FPCount; if(FPCount==0){ Result="MP"; Revi(CurrentPlayer); Output(); } TT+=3;
player[CurrentInjurySource].Cards.push_back(CardPile.front()); CardPile.pop_front();
player[CurrentInjurySource].Cards.push_back(CardPile.front()); CardPile.pop_front();
player[CurrentInjurySource].Cards.push_back(CardPile.front()); CardPile.pop_front();
}
if(player[i].Identity=="ZP" && CurrentInjurySource==1){
player[1].withZ=0; player[1].Cards.clear(); Tmp.clear();
}
}
bool CheckToPlayJ(int i,int op,int target){
if(i==1){
if(op==1 && (target==1 || player[i].GuessID[target]==1))return 1;
if(op==2 && (player[i].GuessID[target]==3 || player[i].GuessID[target]==2))return 1;
} else if(player[i].Identity=="ZP"){
if(op==1 && (target==1 || player[i].GuessID[target]==1))return 1;
if(op==2 && player[i].GuessID[target]==2)return 1;
} else if(player[i].Identity=="FP"){
if(op==1 && player[i].GuessID[target]==2)return 1;
if(op==2 && (target==1 || player[i].GuessID[target]==1))return 1;
} return 0;
// Result==1: To Play The Card J
// Result==0: Not To Play The Card J
}
int PlayWuXieKeJi(int u,int op,int target){
// op==1: Show Love
// op==2: Show Aggresive
for(int i=u,j=0;j<PlayerCount;i=(i+1>PlayerCount?1:i+1),++j){
if(player[i].Dead)continue;
if(CheckToPlayJ(i,op,target)){
int res=JudgeAndPlayTheCard(i,'J');
if(res==1){
if(i-1){
for(int j=1;j<=PlayerCount;++j)
player[j].GuessID[i]=(player[i].Identity=="ZP"?1:2);
}
return (1+PlayWuXieKeJi(i,op==1?2:1,target))&1;
}
}
}
return 0;
// Result==1: The Card Is Not Valid
// Result==0: The Card Is Valid
}
void AllPeopleHurt(int I,char op){
for(int i=(I+1>PlayerCount?1:I+1);i!=I;i=(i+1>PlayerCount?1:i+1)){
if(player[i].Dead)continue;
if(PlayWuXieKeJi(I,1,i))continue;
bool res=JudgeAndPlayTheCard(i,op);
if(player[i].HP==0)JudgeDead(i);
if(i==1 && res && player[1].GuessID[I]==0)player[1].GuessID[I]=3;
}
}
void Duel(int u,int v){
if(u-1){
for(int j=1;j<=PlayerCount;++j)player[j].GuessID[u]=(player[u].Identity=="ZP"?1:2);
} if(PlayWuXieKeJi(u,1,v))return;
CurrentInjurySource=u; while(1){
int oppo=(CurrentInjurySource==u?v:u);
if(u==1 && player[v].Identity=="ZP"){ --player[v].HP; if(player[v].HP==0)JudgeDead(v); break; }
bool res=JudgeAndPlayTheCard(oppo,'K');
if(player[oppo].HP==0)JudgeDead(oppo);
if(res)break; CurrentInjurySource=oppo;
}
}
bool PlayACard(int i){
TT=player[i].Cards.size();
Tmp.clear(); while(TT--){
//Debug();
char Cur=player[i].Cards.front();
player[i].Cards.pop_front();
Tmp.push_front(Cur); switch(Cur){
case 'P':{
if(player[i].HP<4){
++player[i].HP;
Tmp.pop_front();
return Revi(i);
} break;
}
case 'N':{
CurrentInjurySource=i;
Tmp.pop_front(); Revi(i);
AllPeopleHurt(i,'K'); return 1;
}
case 'W':{
CurrentInjurySource=i;
Tmp.pop_front(); Revi(i);
AllPeopleHurt(i,'D'); return 1;
}
case 'Z':{
player[i].withZ=1;
player[i].AbleToPlayK=1;
Tmp.pop_front();
return Revi(i);
}
case 'K':{
int p=NextPlayer(i);
if(player[i].AbleToPlayK && ((player[i].Identity=="MP" && (player[i].GuessID[p]==3 || player[i].GuessID[p]==2)) || (player[i].Identity=="ZP" && player[i].GuessID[p]==2) || (player[i].Identity=="FP" && (p==1 || player[i].GuessID[p]==1)))){
CurrentInjurySource=i; Tmp.pop_front(); Revi(i); JudgeAndPlayTheCard(p,'D');
if(player[i].Identity!="MP"){
for(int j=1;j<=PlayerCount;++j)player[j].GuessID[i]=(player[i].Identity=="ZP"?1:2);
}
if(player[p].HP==0)JudgeDead(p);
if(!player[i].withZ)player[i].AbleToPlayK=0; return 1;
} break;
}
case 'F':{
for(int p=(i+1>PlayerCount?1:i+1),tmp=0,Cnt=-1;;p=(p+1>PlayerCount?1:p+1)){
if(player[p].Dead)continue;
if(tmp==0)tmp=p; if(tmp==p)++Cnt; if(Cnt==1)break;
if((player[i].Identity=="MP" && (player[i].GuessID[p]==3 || player[i].GuessID[p]==2)) || (player[i].Identity=="ZP" && player[i].GuessID[p]==2) || (player[i].Identity=="FP" && p==1)){
Tmp.pop_front(); Revi(i); Duel(i,p); return 1;
}
} break;
}
}
} return !Revi(i);
}
void Fight(){
for(int i=1;;i=(i+1>PlayerCount?1:i+1)){
//cout<<"player "<<i<<"'s turn\n";
CurrentPlayer=i; player[i].AbleToPlayK=1;
if(player[i].Dead)continue;
player[i].Cards.push_back(CardPile.front()); CardPile.pop_front();
player[i].Cards.push_back(CardPile.front()); CardPile.pop_front();
while(PlayACard(i));
}
}
signed main(){
//freopen("IO.in","r",stdin);
//freopen("IO.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
Input();
Fight();
//Debug();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 16ms
memory: 3928kb
input:
5 2000 MP K K P P FP D K D K ZP P P D K FP D K P D FP P K P P D D D P D K P P D D P D D K P P D P D P P K K P D P K D P P D Z P P P K P P D P K K Z K K P D K K P D Z K D P D P K P P K K D P P K P P P P K P K P D K K D P D K D P K Z K K K K D D K K Z P K D D P K P D K Z K P P P K D P K P K K P K Z D ...
output:
FP DEAD D K D K D P D K K P P P K K D D P K P P K K K P K D P D D K D P K D D K D P K D P K K P P D K D P P K K P D K P P K K P D P D K D D P K K D P K D P D D D K P K D K D D P P D K P K K P P D P K K P P K D D K D K D P K P K P P D K D D D P P K K K K P K P K K K D D K K P D D P D D K D K D K D K ...
result:
ok 6 lines
Test #2:
score: 5
Accepted
time: 17ms
memory: 3912kb
input:
2 2000 MP P P K K FP D Z K D D D Z P K D P P Z D K D P P P D P K D P K Z K K K D D K D D D D D D Z D P D K P P P K P P Z K P P P P P Z D D K P D P Z D D P K Z P P K D K K Z K K P K D K P P D D D K D D D P K K D Z K P D P D P P P D D D K P D D K P K D D K K K D D P D D D K D K P P K Z K D D D D K D D...
output:
MP DEAD
result:
ok 3 lines
Test #3:
score: 5
Accepted
time: 0ms
memory: 3984kb
input:
5 2000 MP D F W D FP W N P N ZP P F P K FP D K P P FP F D K K D P F P K D P K D D F K F P P D K K N Z K D W D F D K K P K W N F N F W W N K F K W D N P P K P F F W P F N K F K D D K N N N F K N K N D D P K P K K W N F N W W K F N P D W F K K W D N W K D N K F F W N W P N K Z N P K P W N N W K K N P ...
output:
FP DEAD P K D P K D D
result:
ok 6 lines
Test #4:
score: 5
Accepted
time: 1ms
memory: 3916kb
input:
5 2000 MP P K K K FP N W K P FP F K K F FP Z F P W ZP W F D P P F P D K K F F P W N D P P W F W P N P D N D F N K D F F P F D K N F W F F P W W K D N P K D N F K F D W N K W K D N P P F P N K K D D N K P F F P N N D D D D D D W F Z D K W K W P N D K P W P W D W P W W W P F P D W P W P D F N W W K D ...
output:
FP DEAD K P P K F W F P
result:
ok 6 lines
Test #5:
score: 5
Accepted
time: 1ms
memory: 3912kb
input:
5 2000 MP N F F P FP F K F N ZP P F K F ZP F W W W ZP F D D F K K D N N F P P F P P N F N W F F N F W N D N N N K P K D N P K P N N F W D D W W K P N F D W K K K N N N W F D W N K N F P D P K N P N D Z K F P K D W N P F K W N N F D P K K F D P N N N N P F D W F N W K D N N W N N F P W P N P K D K P ...
output:
MP F F P DEAD N F F W W W F D D F
result:
ok 6 lines
Test #6:
score: 5
Accepted
time: 1ms
memory: 3992kb
input:
5 2000 MP F F K K ZP P F W D FP F D K W FP K P F N ZP Z F N K F W W W F F W N N W D W W F P K K N K N K N D P K K W K P W P W W N P N D D W F W N N N N Z D D W N P F K N N K Z K P N W K F K F D D K W K W P W P P W W D N D N W P D N D N K F W N K N K F K N W D F K K K K K F D P W Z F D K D F N D F K ...
output:
FP DEAD P F DEAD F N W D DEAD
result:
ok 6 lines
Test #7:
score: 5
Accepted
time: 1ms
memory: 3868kb
input:
7 2000 MP J P W F ZP F D D D ZP F D J J FP K W P P FP F K F W ZP W N J N FP N W N K K F J D J P N F J F W J P N D D D J K P N P F N W K W J W K J D D N K P D W K K J Z W K Z W F F D J K J F N W J J K P J P K J P N F P J K F F N K K F J K N F D D D K K P P P F P P J K K J W J N W D P N K D J D D K K ...
output:
FP DEAD F DEAD P DEAD P N D D D DEAD
result:
ok 8 lines
Test #8:
score: 5
Accepted
time: 1ms
memory: 3912kb
input:
7 2000 MP W K D F FP F J D N FP J K F D ZP F N W K FP W N P N FP P D P K FP J K Z N P W W F F K F K K N D F P F J P J J N N N W Z K J W D J D N D D D J N N J P D W J K K F P P D D F J P F D P K W W D K N K P P N D N D K J D N P N D K K P D J N P P K K N N K P W J F K D D D F F J P D D D P K F P N W ...
output:
FP DEAD J K W F K K N D DEAD P P Z N
result:
ok 8 lines
Test #9:
score: 5
Accepted
time: 0ms
memory: 4140kb
input:
7 2000 MP K W P J FP J K W J FP F F W D ZP D K Z F ZP J P K D ZP K J J F FP K K J K D N F J K F J W J D D K N N W N N J W K D N P F K W W D K W F J F D P D F D W P D P N P N N W Z D W N F D W N W P P W W Z K P P K K D K P N K W Z D F D W P Z F F W K P N J K N P W J K J P N N K J F K W F K W D D D J ...
output:
FP DEAD DEAD K D D K N P DEAD DEAD
result:
ok 8 lines
Test #10:
score: 5
Accepted
time: 1ms
memory: 4136kb
input:
7 2000 MP J K K D ZP F K F N FP F D J W FP N D J W ZP J F P P FP D F N Z ZP F N K Z P F J J J W F N P J W P K D D P N F N W D D D W F K N J J N N F N F W D N N W P F N P J P W F F K P D W D K K P F D N P K J D K K F F K F W W F F J J P W W F K J K J F W W J D P J J W K D F F P K K D W P W F D F D P ...
output:
MP P P N F N W DEAD DEAD DEAD DEAD DEAD
result:
ok 8 lines
Test #11:
score: 5
Accepted
time: 1ms
memory: 3920kb
input:
7 2000 MP F D F W ZP W W J F FP P F P K ZP P F P K FP F F K F ZP F N J D ZP W W D F W P F P D F K J J D F N J J K J K D W N P W W W F N K D K N P D N N J D J N J Z W K K N F F W P P P D P W P P D D K N F N F J W J D W N K F J P K P J D J P J D F P J N J D J N W W N K P F D D P N F N N F D F W W K K ...
output:
MP F F P F F F K DEAD K DEAD DEAD F K
result:
ok 8 lines
Test #12:
score: 5
Accepted
time: 1ms
memory: 4004kb
input:
7 2000 MP F K F J FP N K K P FP W J K W FP N P D W FP K F N K FP J W F D ZP J D F J F W K J J W W F F J W D N F D Z D D W W W Z D K W F P F P W K N N W F F D K D P J N F J J K K J K D J J W J K P N P J D W W N N F P J N K K F K P P N J F P J P N J N F W N D N P J W N W K J J D F D D F F D D D D F N ...
output:
FP DEAD K K K F F W D DEAD DEAD W F DEAD
result:
ok 8 lines
Test #13:
score: 5
Accepted
time: 1ms
memory: 4172kb
input:
7 2000 MP D K K D ZP F P N F FP D D J K FP D D F F ZP W F P N ZP D Z P D ZP J J D P J P N J K W N F N D D N P K N N P F P P W D W D W D P J P P W N K W D J F F K W J D D P D J P F W W P J K F W J J N W F J K F W P F F W N F D K D F K W N K D P D P D N N D K W J P F N F J D K K W F P P P W F N D F K ...
output:
MP P N D D P DEAD DEAD N P Z P P
result:
ok 8 lines
Test #14:
score: 5
Accepted
time: 1ms
memory: 4000kb
input:
10 2000 MP J J P P ZP D J J P ZP J K K N FP J D N K ZP J N K P FP K N D J ZP J W W N FP P F W J ZP K W D N ZP W Z N K N P K D K P K W J N W W F K D D J W D P W J P D D N F N F F J W P K P K W D Z J J P D D J N W K N K K K D P D N N J N D K K W P K W N D D P F F J W P P K P K W D W J K P J P K F W J ...
output:
MP P P DEAD W F K D D DEAD DEAD DEAD DEAD DEAD
result:
ok 11 lines
Test #15:
score: 5
Accepted
time: 1ms
memory: 4136kb
input:
10 2000 MP K N W W FP W J K N ZP D J D W ZP N P J J FP F N J F ZP K P J P FP P P K J FP W N P F ZP W W J P ZP F K N N N W D W N N N J F K N N K D N W F N D W D P K W N D K K J F F D W P P D D D K D F W N P D F F D P N J F P D P D D N F J F K K F F N K J W P P F F F W D J W J N J D P F D K W N J D F ...
output:
MP DEAD K DEAD DEAD DEAD DEAD DEAD DEAD DEAD
result:
ok 11 lines
Test #16:
score: 5
Accepted
time: 1ms
memory: 4108kb
input:
3 24 MP K K K K ZP Z Z Z Z FP J J J J K K Z Z J J K K W Z W W K Z J J K K J J K K W W
output:
FP DEAD DEAD J J J J J J J J J J W
result:
ok 4 lines
Test #17:
score: 5
Accepted
time: 1ms
memory: 3916kb
input:
10 2000 MP J P J Z ZP J J N J ZP F N N P ZP F W J Z ZP P D D P ZP F W J W ZP K Z P W FP J J J J FP J J K J FP J J Z J Z N J K Z W N J N J N J J K Z F P K K J D Z W W N W Z Z J J J J J J J K N D J N Z J D D J N Z J Z J N J J P J P K N J N N J D J K Z K K K Z F F N J P P N N F Z J J P W Z J K W K D W ...
output:
MP P N N J N J DEAD D P DEAD Z W DEAD DEAD DEAD
result:
ok 11 lines
Test #18:
score: 5
Accepted
time: 1ms
memory: 3920kb
input:
10 2000 MP K W Z Z FP N K K K ZP N P N J FP J Z J K ZP J W K D ZP N P K P ZP J P F J ZP J N N W ZP J K J W ZP J Z K J Z P D J D K W F F Z N J F F J K J J J J J K W D Z K N Z W K D P Z F J F P K J J W J F P F J J N F J D D P J Z J W F W J J J P W J J W J F D W J W W J D Z N F J F N W Z J D F J J J F ...
output:
MP P DEAD D DEAD Z N N DEAD DEAD DEAD DEAD
result:
ok 11 lines
Test #19:
score: 5
Accepted
time: 1ms
memory: 3928kb
input:
3 2000 MP F F F F ZP N K K K FP J J D F F D K K K J P D J P W N J Z J J W J D W J J P K Z K N J P N F N W D J J W F J W W N P J K J N P J K J W D D Z F J P F P K P J J W D J J F N J J F K J F D D J J F W J J W Z D D F P Z J W P D D F J P W F J J W J Z N N J J F Z N D Z F J N K J J Z Z K N J P P P N ...
output:
FP DEAD DEAD D
result:
ok 4 lines
Test #20:
score: 5
Accepted
time: 0ms
memory: 3876kb
input:
10 2000 MP N K K K FP F F F F ZP Z J J J FP N J J J ZP D J Z F FP D J K J FP J W J W FP J D N J FP J D P W ZP D F K J F Z N J D J J F J Z J Z N K K J Z J D K N Z P W Z K P N Z J D D N N Z P W J K F F K K W J F J J J J N W P P F J K P Z N J J D D W D J K J D J W K D Z K Z Z W N Z F F J Z W D W J P J ...
output:
FP DEAD DEAD DEAD DEAD K K D K N Z P W Z DEAD DEAD
result:
ok 11 lines