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
- UVa 255 - Correct Move
- UVa 10849 - Move the bishop
- Move
- Move
- Move
- Move..
- Move!Move!!Move!!!
- CORRECT 边界条件
- Correct Solution?
- Make Correct Code Look Correct
- Move Move Look
- Move.c && Move.h
- Move.h && Move.c
- Right-BICEP和CORRECT
- a correct Divide function
- 12B Correct Solution?
- B. Error Correct System
- gamma correct blurring
- 面试题2 编程实现单链表删除节点
- 1102. Invert a Binary Tree (pat) / 226. Invert Binary Tree(leetcode)
- fpga设计思想(二):有限状态机
- 数据预处理(方法介绍)
- 开发中常用的功能
- UVa 255 - Correct Move
- 第四周项目3-单链表应用(1)
- 数据结构实践——建设单链表算法库
- 反调试主要方法简述
- 第3周SHH数据结构—【项目4-顺序表应用问题(2)】
- View Controller 流(纯代码版)
- 第4周项目1-建立单链表
- 项目经验分享
- Go语法简略 - 依赖注入