UVa 255 - Correct Move

来源:互联网 发布:数据库应用系统实例 编辑:程序博客网 时间:2024/04/29 19:57

題目:已知國際象棋的王和后的位置和后的下一步移動,判斷狀態和移動的合法性。

分析:簡單題,枚舉,模擬。本題只處理水平數值移動。直接枚舉判斷即可。

            可以利用一個狀態圖標記,王能走記1,后能走記2,都能走記3,方便判斷。

說明:單詞打錯╮(╯▽╰)╭。

#include <cstring>#include <cstdio>int maps[8][8];int dxy[4][2] = {0,1,0,-1,-1,0,1,0};int main(){int n, m, a, b, c, x, y;while (~scanf("%d%d%d",&a,&b,&c)) {if (a == b)printf("Illegal state\n");else {for (int i = 0; i < 8; ++ i)for (int j = 0; j < 8; ++ j)maps[i][j] = 0;for (int i = 0; i < 4; ++ i) {x = a/8+dxy[i][0];y = a%8+dxy[i][1];if (x >= 0 && x < 8 && y >= 0 && y < 8)maps[x][y] += 1;x = b/8+dxy[i][0];y = b%8+dxy[i][1]; while (x >= 0 && x < 8 && y >= 0 && y < 8 && x*8+y != a) {maps[x][y] += 2;x = x+dxy[i][0];y = y+dxy[i][1]; }}if (maps[c/8][c%8] < 2)printf("Illegal move\n");else if (maps[c/8][c%8] == 3)printf("Move not allowed\n");else if (a == 0 && c == 9 || a == 7 && c == 14 || a == 56 && c == 49 || a == 63 && c == 54)printf("Stop\n");else printf("Continue\n");}}    return 0;}


0 0