正文
增加 367 行删除 43 行
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556```cpp#include <bits/stdc++.h>using namespace std ;const int N = 4e2 + 55 ;struct node {int x ;int y ;} ;int ans[N][N] ;int walk[8][2] = {{2, 1}, {1, 2}, {-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}} ;queue<node> q ;int main() {int n, m, x, y ;cin >> n >> m >> x >> y ; // Read once onlymemset(ans, -1, sizeof(ans)) ;node tmp = {x, y} ;q.push(tmp) ;ans[x][y] = 0 ;while (!q.empty()) {node u = q.front() ;int ux = u.x ;int uy = u.y ;q.pop() ;for (int k = 0 ; k < 8 ; k++) {int nx = ux + walk[k][0] ;int ny = uy + walk[k][1] ;if (nx < 1 || nx > n || ny < 1 || ny > m || ans[nx][ny] != -1) {continue ;}ans[nx][ny] = ans[ux][uy] + 1 ;node newPos = {nx, ny} ;q.push(newPos) ;}}// Print the final result after BFS is completefor (int i = 1 ; i <= n ; i++) {for (int j = 1 ; j <= m ; j++) {printf("%-5d", ans[i][j]) ;}cout << endl ;}return 0 ;}```123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380```cpp# include <bits/stdc++.h># define N 111# define M 2222using namespace std;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 ifCnt;int main () {return 0;}#include <bits/stdc++.h>using namespace std;#define N 11#define M 2222struct 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++;}bool 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';return true;}}return false;}void setFriend(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;}}void setEnemy(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;}}void decreaseHp(int from, int to) {pig[to].hp--;while (pig[to].hp <= 0 && findCard(to, 'P')) {pig[to].hp++;}if (pig[to].hp <= 0) {pig[to].cnt = 0;pig[to].weapon = false;if (pig[to].id == 1) {gameover = true;return;} else if (pig[to].id == 2) {if (pig[from].id == 1) {pig[from].cnt = 0;pig[from].weapon = false;}} else if (pig[to].id == 3) {fpCnt--;if (fpCnt == 0) {gameover = true;return;}getCard(from);getCard(from);getCard(from);}pig[pig[to].pre].nxt = pig[to].nxt;pig[pig[to].nxt].pre = pig[to].pre;}}bool isEnemy(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 isFriend(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 useCardJ(int from, int to, int last) {int now = from;while (true) {if ((last == 0 && isFriend(now, to)) || (last != 0 && isEnemy(now, last))) {if (findCard(now, 'J')) {if (last == 0 && isFriend(now, to)) setFriend(now, to);if (last != 0 && isEnemy(now, last)) setEnemy(now, last);if (!useCardJ(pig[now].nxt, to, now)) {return true;}}}now = pig[now].nxt;if (now == from) return false;}}void useCardK(int from, int to) {setEnemy(from, to);bool hasDodge = findCard(to, 'D');if (!hasDodge) {decreaseHp(from, to);}}void useCardF(int from, int to) {if (pig[from].id == 1 && pig[to].id == 2) {decreaseHp(from, to);return;}while (true) {bool hasKill = findCard(to, 'K');if (!hasKill) {decreaseHp(from, to);return;}bool hasKill2 = findCard(from, 'K');if (!hasKill2) {decreaseHp(to, from);return;}}}void useCardN(int from, int to) {while (true) {if (gameover) return;if (!useCardJ(from, to, 0)) {bool hasKill = findCard(to, 'K');if (!hasKill) {if (pig[to].id == 1 && pig[from].pigid == 0) {pig[from].special = true;}decreaseHp(from, to);}}to = pig[to].nxt;if (to == from) return;}}void useCardW(int from, int to) {while (true) {if (gameover) return;if (!useCardJ(from, to, 0)) {bool hasDodge = findCard(to, 'D');if (!hasDodge) {if (pig[to].id == 1 && pig[from].pigid == 0) {pig[from].special = true;}decreaseHp(from, to);}}to = pig[to].nxt;if (to == from) return;}}void runGame() {while (true) {for (int i = 1; i <= n; ++i) {if (gameover) return;if (pig[i].hp <= 0) continue;getCard(i);getCard(i);bool canUseK = 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) {pig[i].card[j] = 'X';pig[i].hp++;}break;}case 'K': {if (canUseK && isEnemy(i, pig[i].nxt)) {pig[i].card[j] = 'X';useCardK(i, pig[i].nxt);if (!pig[i].weapon) {canUseK = false;}j = 0;}break;}case 'F': {if (pig[i].id == 3) {pig[i].card[j] = 'X';setEnemy(i, 1);if (useCardJ(i, 1, 0)) break;useCardF(i, 1);j = 0;} else {int to = pig[i].nxt;while (true) {if (isEnemy(i, to)) {pig[i].card[j] = 'X';setEnemy(i, to);if (useCardJ(i, to, 0)) break;useCardF(i, to);j = 0;break;}to = pig[to].nxt;if (to == i) break;}}break;}case 'N': {pig[i].card[j] = 'X';useCardN(i, pig[i].nxt);j = 0;break;}case 'W': {pig[i].card[j] = 'X';useCardW(i, pig[i].nxt);j = 0;break;}case 'Z': {pig[i].card[j] = 'X';pig[i].weapon = true;canUseK = 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 name[5], s[5];scanf("%s", name);for (int j = 1; j <= 4; ++j) {scanf("%s", s);pig[i].card[j] = s[0];}pig[i].cnt = 4;if (name[0] == 'M') {pig[i].id = 1;pig[i].pigid = 1;} else if (name[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;}```