QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#76095#4170. 猪国杀zombie462100 ✓6ms3720kbC++1411.1kb2023-02-07 16:47:112023-02-07 16:47:13

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-07 16:47:13]
  • 评测
  • 测评结果:100
  • 用时:6ms
  • 内存:3720kb
  • [2023-02-07 16:47:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define N 11
#define M 2222
struct player {
    int id;
    int hp;
    int cnt;
    char card[M];
    int pre;
    int nxt;
    int pigid;
    bool special;
    bool weapon;
} pig[N];
int n, m;
int top;
char cards[M];
bool gameover;
int FPcnt;
void printcard(int i) {
    bool first = true;

    for (int j = 1; j <= pig[i].cnt; ++j) {
        if (pig[i].card[j] == 'X')
            continue;

        if (!first) {
            printf(" ");
        } else
            first = false;

        printf("%c", pig[i].card[j]);
    }

    printf("\n");
}
void getcard(int i) {
    if (top > m)
        top = m;

    pig[i].cnt++;
    pig[i].card[pig[i].cnt] = cards[top];
    top++;
    //  printf("%d:card=",i);printcard(i);
}
int findcard(int x, char card) {
    for (int i = 1; i <= pig[x].cnt; ++i) {
        if (pig[x].card[i] == card) {
            pig[x].card[i] = 'X';
            //          printf("%d lose card:%c\n",x,card);
            //          printf("%d:card=",x);printcard(x);
            return true;
        }
    }

    return false;
}
void getfriend(int x, int y) {
    if (pig[y].pigid == 0)
        return;

    if (pig[y].pigid != 3)
        pig[x].special = false, pig[x].pigid = 1;

    if (pig[y].pigid == 3)
        pig[x].special = true, pig[x].pigid = 3;

    //  printf("%d show its id:%d\n",x,pig[x].pigid);
}
void getenemy(int x, int y) {
    if (pig[y].pigid == 0)
        return;

    if (pig[y].pigid != 3)
        pig[x].pigid = 3, pig[x].special = true;

    if (pig[y].pigid == 3)
        pig[x].pigid = 1, pig[x].special = false;

    //  printf("%d show its id:%d\n",x,pig[x].pigid);
}
void dechp(int x, int i) {
    pig[i].hp--;

    //  printf("%d lose 1 HP by %d; Now HP=%d \n",i,x,pig[i].hp);
    while (pig[i].hp <= 0 && findcard(i, 'P')) {
        pig[i].hp++;
        //      printf("%d add 1 HP\n",i);
    }

    if (pig[i].hp <= 0) {
        //      printf("%d is killed by %d\n",i,x);
        pig[i].cnt = 0;
        pig[i].weapon = false;

        if (pig[i].id == 1) {
            gameover = true;
            //          printf("Game over\n");
            return;
        } else if (pig[i].id == 2) {
            if (pig[x].id == 1) {
                //              printf("MP lose his all card\n");
                pig[x].cnt = 0;
                pig[x].weapon = false;
            }
        } else if (pig[i].id == 3) {
            FPcnt--;

            if (FPcnt == 0) {
                gameover = true;
                //              printf("Game over\n");
                return;
            }

            //          printf("%d got 3 new card\n",x);
            getcard(x);
            getcard(x);
            getcard(x);
        }

        pig[pig[i].pre].nxt = pig[i].nxt;
        pig[pig[i].nxt].pre = pig[i].pre;
    }
}
bool enemy(int x, int y) {
    if (pig[x].id == 1 && pig[y].special == true)
        return true;

    if (pig[y].pigid == 0)
        return false;

    if (pig[x].id != 3 && pig[y].pigid == 3)
        return true;

    if (pig[x].id == 3 && pig[y].pigid != 3)
        return true;

    return false;
}
bool friendly(int x, int y) {
    if (pig[y].pigid == 0)
        return false;

    if (pig[x].id != 3 && pig[y].pigid != 3)
        return true;

    if (pig[x].id == 3 && pig[y].pigid == 3)
        return true;

    return false;
}

bool usecard_j(int from, int to, int last) {
    int now = from;

    while (true) {
        if ((last == 0 && friendly(now, to)) || (last != 0 && enemy(now, last))) {
            if (findcard(now, 'J')) {
                if (last == 0 && friendly(now, to))
                    getfriend(now, to);

                if (last != 0 && enemy(now, last))
                    getenemy(now, last);

                if (!usecard_j(pig[now].nxt, to, now)) {
                    return true;
                }
            }
        }

        now = pig[now].nxt;

        if (now == from)
            return false;
    }
}
void usecard_k(int from, int to) {
    getenemy(from, to);
    bool p = findcard(to, 'D');

    if (p == false) {
        dechp(from, to);
    }
}
void usecard_f(int from, int to) {
    if (pig[from].id == 1 && pig[to].id == 2) {
        dechp(from, to);
        return;
    }

    while (true) {
        bool flag1 = findcard(to, 'K');

        if (!flag1) {
            dechp(from, to);
            return;
        }

        bool flag2 = findcard(from, 'K');

        if (!flag2) {
            dechp(to, from);
            return;
        }
    }
}
void usecard_n(int from, int to) {
    while (true) {
        if (gameover)
            return;

        if (!usecard_j(from, to, 0)) {
            bool flag = findcard(to, 'K');

            if (!flag) {
                if (pig[to].id == 1 && pig[from].pigid == 0) {
                    pig[from].special = true;
                    //                  printf("%d is not good with MP\n",from);
                }

                dechp(from, to);
            }
        }

        to = pig[to].nxt;

        if (to == from)
            return;
    }
}
void usecard_w(int from, int to) {
    while (true) {
        if (gameover)
            return;

        if (!usecard_j(from, to, 0)) {
            bool flag = findcard(to, 'D');

            if (!flag) {
                if (pig[to].id == 1 && pig[from].pigid == 0) {
                    pig[from].special = true;
                    //                  printf("%d is not good with MP\n",from);
                }

                dechp(from, to);
            }
        }

        to = pig[to].nxt;

        if (to == from)
            return;
    }
}
void rungame() {
    while (true) {
        for (int i = 1; i <= n; ++i) {
            //          printf("--------Turn:%d--------\n",i);
            if (gameover)
                return;

            if (pig[i].hp <= 0)
                continue;

            getcard(i);
            getcard(i);
            bool use_k = true;

            for (int j = 1; j <= pig[i].cnt; ++j) {
                if (pig[i].card[j] == 'X')
                    continue;

                if (gameover)
                    return;

                switch (pig[i].card[j]) {
                case 'P': {
                    if (pig[i].hp < 4) {
                        //                          printf("%d try to use card P; Now HP=%d\n",i,pig[i].hp);
                        pig[i].card[j] = 'X';
                        //                          printf("%d:card=",i);printcard(i);
                        pig[i].hp++;
                    }

                    break;
                }

                case 'K': {
                    if (use_k && enemy(i, pig[i].nxt)) {
                        //                          printf("%d try to use card K\n",i);
                        pig[i].card[j] = 'X';
                        //                          printf("%d:card=",i);printcard(i);
                        usecard_k(i, pig[i].nxt);

                        if (!pig[i].weapon) {
                            use_k = false;
                        }

                        j = 0;
                    }

                    break;
                }

                case 'F': {
                    if (pig[i].id == 3) {
                        //                          printf("%d try to use card F to 1\n",i);
                        pig[i].card[j] = 'X';
                        //                          printf("%d:card=",i);printcard(i);
                        getenemy(i, 1);

                        if (usecard_j(i, 1, 0))
                            break;

                        usecard_f(i, 1);
                        j = 0;
                    } else {
                        int to = pig[i].nxt;

                        while (true) {
                            if (enemy(i, to)) {
                                //                                  printf("%d try to use card F to %d\n",i,to);
                                pig[i].card[j] = 'X';
                                //                                  printf("%d:card=",i);printcard(i);
                                getenemy(i, to);

                                if (usecard_j(i, to, 0))
                                    break;

                                usecard_f(i, to);
                                j = 0;
                                break;
                            }

                            to = pig[to].nxt;

                            if (to == i)
                                break;
                        }
                    }

                    break;
                }

                case 'N': {
                    //                      printf("%d try to use card N\n",i);
                    pig[i].card[j] = 'X';
                    //                      printf("%d:card=",i);printcard(i);
                    usecard_n(i, pig[i].nxt);
                    j = 0;
                    break;
                }

                case 'W': {
                    //                      printf("%d try to use card W\n",i);
                    pig[i].card[j] = 'X';
                    //                      printf("%d:card=",i);printcard(i);
                    usecard_w(i, pig[i].nxt);
                    j = 0;
                    break;
                }

                case 'Z': {
                    //                      printf("%d try to use card Z\n",i);
                    pig[i].card[j] = 'X';
                    //                      printf("%d:card=",i);printcard(i);
                    pig[i].weapon = true;
                    use_k = true;
                    j = 0;
                    break;
                }
                }

                while (pig[i].card[pig[i].cnt] == 'X')
                    pig[i].cnt--;
            }
        }
    }
}
int main() {
    scanf("%d%d", &n, &m);

    for (int i = 1; i < N; ++i) {
        for (int j = 1; j < M; ++j) {
            pig[i].card[j] = 'X';
        }

        pig[i].hp = 4;
    }

    for (int i = 1; i <= n; ++i) {
        char names[5], s[5];
        scanf("%s", names);

        for (int j = 1; j <= 4; ++j) {
            scanf("%s", s);
            pig[i].card[j] = s[0];
        }

        pig[i].cnt = 4;

        if (names[0] == 'M')
            pig[i].id = 1, pig[i].pigid = 1;
        else if (names[0] == 'Z')
            pig[i].id = 2;
        else
            pig[i].id = 3, FPcnt++;

        pig[i].nxt = i + 1;
        pig[i].pre = i - 1;
    }

    pig[n].nxt = 1;
    pig[1].pre = n;

    for (int i = 1; i <= m; ++i) {
        char s[5];
        scanf("%s", s);
        cards[i] = s[0];
    }

    top = 1;
    rungame();

    if (pig[1].hp <= 0)
        printf("FP\n");
    else
        printf("MP\n");

    for (int i = 1; i <= n; ++i) {
        if (pig[i].hp <= 0)
            printf("DEAD\n");
        else {
            printcard(i);
        }
    }

    return 0;
}

详细

Test #1:

score: 5
Accepted
time: 1ms
memory: 3580kb

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: 6ms
memory: 3456kb

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: 2ms
memory: 3448kb

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: 2ms
memory: 3508kb

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: 2ms
memory: 3484kb

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: 0ms
memory: 3568kb

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: 2ms
memory: 3628kb

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: 2ms
memory: 3692kb

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: 2ms
memory: 3684kb

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: 2ms
memory: 3716kb

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: 2ms
memory: 3544kb

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: 2ms
memory: 3584kb

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: 2ms
memory: 3720kb

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: 2ms
memory: 3716kb

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: 0ms
memory: 3544kb

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: 2ms
memory: 3544kb

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: 3ms
memory: 3564kb

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: 2ms
memory: 3556kb

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: 2ms
memory: 3516kb

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: 2ms
memory: 3508kb

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