编程介的小学生 2017-05-05 01:30 采纳率: 20.5%
浏览 784
已采纳

Game of Pawns

On the chess board, the poor little pawns are put out in front right in harms way while the other guys are hiding back behind.But according the chess rules, if a pawn can make it to the other side, it will be rewarded with a promotion - to a queen! Noting this, EZ invents a new kind of single-player game.

At the beginning of the game, EZ puts 8 black pawns on the first rank(see the figure below), and then places some enemy on the board. He wonder how many of them can become queens at most.

Here are some rules in this game about the move of the pawn. You can see more detail in Rules of Chess

A pawn can move forward one square, if that square is unoccupied. If it has not yet moved, the pawn has the option of moving two squares forward provided both squares in front of the pawn are unoccupied. A pawn cannot move backward.
Pawns are the only pieces that capture differently from how they move. They can capture an enemy piece on either of the two spaces adjacent to the space in front of them (i.e., the two squares diagonally in front of them) but cannot move to these spaces if they are vacant.
If a pawn advances to its eighth rank,it is then promoted to a queen. In this very game, once a pawn has been promoted to a queen, it would stay there for the rest of the game.
Since this is a single-player game, the enemy would stay where they are during the whole game(unless they had been captured).
Input

There are multiple cases (no more than 30). The first line of each test case contains an integer N, indicating the number of enemys on the board. (0 <= N <= 16) Then N lines followed, each line contains two character cr ('a' <= c <= 'h', '1' < r <= '8'), which is the loction of the ith enemy.

Output

For each case, output the maximum number of pawns that can be promoted to queens in a single line.

Sample Input

2
a2
b2
3
a2
b2
e5
3
a2
b2
b3
Sample Output

8
7
8

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP