We have a square board with 64 places, numbered from 0 to 63, see Figure 1.
    There are two pieces: A king and a queen. The pair of king’s place and queen’s place is called the state. A state is legal if the pieces are not at the same place. The king and queen move alternatingly. The king can move one step in a horizontal or vertical direction, as long as it does not arrive at the place of the queen. The queen can move one ore more steps in a horizontal or vertical direction, as long as it does not encounter the king. All these moves are called legal. Please note that the pieces may not move diagonally.

    For example, suppose we have a state with a king at place 17 and a queen at place 49, as in Figure 2. The legal moves of the king are to places 9, 16, 18, and 25 and the queen can legally move to place 25, 33, 41, 48, 50, 51, 52, 53, 54, 55, or 57. We impose, however, an extra restriction: A piece may not move to a place where the other one can also move to. Legal moves satisfying this restriction are called allowed. In Figure 2, all possible places the king and the queen can move to by an allowed move, are denoted with a circle (◦) and a dot (•), respectively. In Figure 3, the king cannot move, it is locked in.

This problem requires you to write a program that does some checking related to the movement of the queen.
Input
The input for your program resides in a textfile that ends with the standard end-of-file marker. Each line ends with the standard end-of-line marker and contains a sequence of three integers in the range O…63, separated by one space. The first two integers denote the place of the king and the queen, respectively. Together they form a state. The third integer denotes a new place for the queen. You
may think of it as computed by some function movequeen. Your program determines whether:
• the given state is legal
• the queen’s move is legal
• the queen’s move is allowed.
    Furthermore, if these requirements are met, your program determines whether the move of the queen results in a state where the king is locked in.
Output
The output is also a textflle. For each input line, your program produces one output line with one of the following messages:
• Illegal state
• Illegal move
• Move not allowed
• Continue
• Stop
‘Illegal state’ indicates that the given state is not legal, i.e. the pieces are at the same place.
‘Illegal move’ means that the given state is legal, but the queen’s move is illegal.
‘Move not allowed’ applies if both the given state and the queen’s move are legal, but the queen’s
move is not allowed.
Both ‘Continue’ and ‘Stop’ mean that the given state is legal and the queen’s move is allowed. If
the king can do an allowed move in the resulting state, the message is ‘Continue’, otherwise the king
is locked in and you reply ‘Stop’.
Sample Input
17 17 49
17 49 56
17 49 9
17 49 17
17 49 25
17 49 33
17 49 41
17 49 49
56 48 49
Sample Output
Illegal state
Illegal move
Illegal move
Illegal move
Move not allowed
Continue
Continue
Illegal move
Stop

问题链接:UVA255 Correct Move
问题简述:(略)
问题分析
    国际象棋局面判定问题。
    棋盘上只有2个棋子,一方是王,一方是王后。先统计王和王后可以走到的点,再行局面判定。王可以走到的点记为1,王后可以走到的点标记为2,王和王后均可以走到的点标记为3,其他
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA255 Correct Move */#include <bits/stdc++.h>using namespace std;const int M = 4;
int drow[] = {0, 0, -1, 1};
int dcol[] = {1, -1, 0, 0};
const int N = 8;
int board[N][N];int main()
{int a, b, c;while(scanf("%d%d%d", &a, &b, &c) != EOF)if(a == b) printf("Illegal state\n");else {memset(board, 0, sizeof(board));for(int i = 0; i < M; i++) {int row = a / N + drow[i];int col = a % N + dcol[i];if(row >= 0 && row < N && col >= 0 && col < N)board[row][col]++;row = b / N + drow[i];col = b % N + dcol[i];int t = row * N + col;while(row >= 0 && row < N && col >= 0 && col < N && t != a) {board[row][col] += 2;row += drow[i];col += dcol[i];t = row * N + col;}}if(board[c / N][c % N] < 2)printf("Illegal move\n");else if(board[c / N][c % N] == 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");elseprintf("Continue\n");}return 0;
}

UVA255 Correct Move【国际象棋】相关推荐

  1. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  2. 【UGV】Mec 麦轮版小车结合角度传感器实现直线行走示例

    文章目录 所用硬件 程序代码 所用硬件 原理图请参考:[UGV]小车一些图片 麦轮版小车 控制原理请参考:[控制]麦轮小车动力学模型分析 程序代码 // Motor Controller Use Me ...

  3. python汉诺塔算法_基于Python的汉诺塔求解中途算法

    能不能把河内塔半路解决?我做了大量的研究来寻找能够解决用户配置问题的代码,但是我还没有找到一个.这是一个任务,我需要代码接管从用户已经停止求解的地方,并继续为用户解决它,而不重置为方块一.在 我知道有 ...

  4. 为什么和平精英无响应_什么和为什么

    为什么和平精英无响应 重点 (Top highlight) 什么和为什么 (The What and Why) Amazon has long been striving to fix the iss ...

  5. linux usb gadget 日志

    1,USB 协议入门 几种USB控制器类型:OHCI,UHCI,EHCI,XHCI 遇到过一些关于USB的东西(如下),一直没搞明白什么USB1.0/1.1/2.0/3.0之类的,当然我知道它们的各自 ...

  6. Linux内核网络结构,和收发数据基本流程

    不管是大型虚拟化云网络,还是嵌入式物联网系统,Linux网络都扮演着重要的角色.借用一句话说,如果说网络是信息系统的基石,那么Linux网络系统就是基石中的钢筋.它经过几十年的发展,它千锤百炼,几乎包 ...

  7. UVA10849 Move the bishop【国际象棋】

    Consider you have a chess board with N × N squares, 1 ≤ N ≤ 100.000.000. There is only a piece on th ...

  8. 深度学习机器72小时自学国际象棋达到大师水平

    chess Photo by Maarten van den Heuvel on Unsplash 本文在腾讯云+社区人工智能专栏首发, 为原创翻译文章. 文章正文部分以注释格式给出正文 导读 英文原 ...

  9. 国际象棋ai下载_国际象棋AI的解剖

    国际象棋ai下载 Chess-playing programs made their grand debut in the 50's. They were unsurprisingly fairly ...

最新文章

  1. linux下mysql定时备份数据库
  2. 零基础学python-3.2 变量赋值
  3. 消费金融首推即时沟通工具“马上”探索科技金融发展新方向
  4. js 获取vue组件html_vue.js中怎么引入组件?
  5. C#学习笔记——通用对话框
  6. 用matlab算24点小游戏,24点游戏的Matlab程序
  7. java怎么设置404界面_如何使用Spring MVC显示自定义的404 Not Found页面
  8. 获取和保存当前屏幕的截图 实现的C++代码如下
  9. 微信小程序中rpx与rem单位使用
  10. bzoj 3383: [Usaco2004 Open]Cave Cows 4 洞穴里的牛之四(set+BFS)
  11. django缓存优化(一)
  12. flink 自定义 窗口_Flink源码分析: 窗口机制的执行流程
  13. 智能卡检测控制系统检测m1这么操作_多联机制冷剂灌注操作方法
  14. 使用GDAL读取SRTM格式高程数据
  15. 黑客穷追不舍攻击“谷姐” [转]
  16. 对RS232接口的详细攻破
  17. [你好,2022] 月落乌啼霜满天,江枫渔火对愁眠
  18. java调用腾讯企业邮箱给谷歌(gmail)邮箱发送邮件丢失或进入垃圾邮箱
  19. TI—CC3200【6】通过功放芯片的使能引脚消去POPO声
  20. 选手的名次 C语言实现

热门文章

  1. 树莓派禁用SD卡上的swap交换空间
  2. html——windows.onload()与$(document).ready()区别
  3. 使用CSS 媒体查询功能满足不同屏幕分辨率要求
  4. .net socket与完成端口、异步发送相关研究
  5. mysql中datetime有带时区_当服务器时区不是UTC时,从Java中检索来自MySQL的UTC DATETIME字段...
  6. 报错:Ticket expired while renewing credentials 原因:Hue 集成Kerberos 导致Kerberos Ticket Renewer 起不来
  7. Root cause be too many concurrent connections error could not open clinet transport with jdbc uri
  8. clock函数的时间单位_【CUDA 基础】2.2 核函数计时
  9. LeetCode 22. 括号生成(回溯+剪枝)
  10. CUDA ---- Hello World From GPU