In the FEN (Forsyth-Edwards Notation), a chessboard is described as follows:
• The Board-Content is specified starting with the top row and ending with the bottom row.
• Character ‘/’ is used to separate data of adjacent rows.
• Each row is specified from left to right.
• White pieces are identified by uppercase piece letters: PNBRQK.
• Black pieces are identified by lowercase piece letters: pnbrqk.
• Empty squares are represented by the numbers one through eight.
• A number used represents the count of contiguous empty squares along a row.
• Each row’s sum of numbers and characters must equal 8.
    As for example:
5k1r/2q3p1/p3p2p/1B3p1Q/n4P2/6P1/bbP2N1P/1K1RR3, is the FEN notation description of the following chessboard:

    The chessboard of the beginning of a chess game is described in FEN as:
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR
    Your task is simple: given a chessboard description in a FEN notation you are asked to compute the number of unoccupied squares on the board which are not attacked by any piece.
Input
Input is a sequence of lines, each line containing a FEN description of a chessboard. Note that the description does not necessarily give a legal chess position. Input lines do not contain white space.
Output
For each line of input, output one line containing an integer which gives the number of unoccupied squares which are not attacked.
Sample Input
5k1r/2q3p1/p3p2p/1B3p1Q/n4P2/6P1/bbP2N1P/1K1RR3
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR
Sample Output
3
16

问题链接:UVA10284 POJ2512 Chessboard in FEN
问题简述:(略)
问题分析
    国际象棋问题。
    与参考链接原理相同,不解释。代码是网友帮忙写的。
程序说明:(略)
参考链接
UVA10196 Check The Check【模拟+回溯】
POJ4001 HDU4121 UVA1589 UVALive5829 Xiangqi【模拟+回溯】
题记:(略)

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

/* UVA10284 POJ2512 Chessboard in FEN */#include <iostream>
#include <cstdio>using namespace std;const int N=8;
const int drow[]={1,1,-1,-1,1,0,-1,0,1,1,-1,-1,2,2,-2,-2};
const int dcol[]={1,-1,1,-1,0,1,0,-1,2,-2,2,-2,1,-1,1,-1};char board[N][N];void getboard(string& s)
{int r=0,c=0;for(int i=0;s[i];i++){if(isdigit(s[i]))for(int j=0;j<s[i]-'0';j++)board[r][c++]='.';else if(isalpha(s[i]))board[r][c++]=s[i];else if(s[i]=='/')r++,c=0;}
}void judge(int row,int col,char k,int start,int end,char flag)
{for (int i=start;i<=end;i++){int nextrow=row+drow[i];int nextcol=col+dcol[i];int tem=0;while(nextrow>=0&&nextrow<N&&nextcol>=0&&nextcol<N){if((flag=='p'||flag=='k'||flag=='n')&&tem==1)break;if(board[nextrow][nextcol]==k)board[nextrow][nextcol]='1';if(isalpha(board[nextrow][nextcol]))break;nextrow+=drow[i];nextcol+=dcol[i];tem++;}}
}void pawn(int x, int y, char k, char flag)
{if(flag == 'p')return judge(x, y, k, 0, 1, 'p');elsereturn judge(x, y, k, 2, 3, 'p');
}void knight(int row,int col,char k)
{return judge(row, col, k, 8, 15, 'n');
}void bishop(int row, int col, char k)
{return judge(row, col, k, 0, 3, 'b');
}void rook(int row, int col, char k)
{return judge(row, col, k, 4, 7, 'r');
}void queen(int row, int col, char k)
{return judge(row, col, k, 0, 7, 'q');
}void king(int row, int col, char k)
{return judge(row, col, k, 0, 7, 'k');
}void deal()
{for(int i = 0; i < N; i++)for(int j = 0; j < N; j++){switch (board[i][j]){case 'p':pawn(i,j,'.','p');break;case 'P':pawn(i,j,'.','P');break;case 'n':knight(i,j,'.');break;case 'N':knight(i,j,'.');break;case 'b':bishop(i,j,'.');break;case 'B':bishop(i,j,'.');break;case 'r':rook(i,j,'.');break;case 'R':rook(i,j,'.');break;case 'q':queen(i,j,'.');break;case 'Q':queen(i,j,'.');break;case 'K':king(i,j,'.');break;case 'k':king(i,j,'.');break;default:break;}}
}int main()
{string s;while(getline(cin,s)){getboard(s);deal();int cnt=0;for(int i=0;i<N;i++)for(int j=0;j<N;j++)cnt+= board[i][j]=='.'? 1:0;printf("%d\n",cnt);}return 0;
}

UVA10284 POJ2512 Chessboard in FEN【国际象棋】相关推荐

  1. Competitive Programming 3题解

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

  2. 国际象棋走棋步数(Distance on Chessboard)计算程序

    国际象棋走棋步数(Distance on Chessboard)计算程序 国际象棋的棋盘是黑白相间的8 * 8的方格,棋子放在格子中间.如下图所示: 王.后.车.象的走子规则如下:  王:横.直.斜都 ...

  3. UVa Online Judge 工具網站

    UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...

  4. HOJ题目分类//放这儿没事刷刷学算法!嘻嘻!

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  5. 哈工大软件构造lab2实验报告

    1 实验目标概述 2 实验环境配置 3 实验过程 3.1 Poetic Walks 3.1.1 Get the code and prepare Git repository 3.1.2 Proble ...

  6. 使用 Python 在 2 秒内评估国际象棋位置

    如何在两秒钟内评估国际象棋位置的指南 经常在 https://lichess.org/ 上观看大师们玩的国际象棋比赛.这些棋局和棋手的水平超出了我们的想象,如果想知道谁有优势.与其事后分析游戏,不如实 ...

  7. node seneca_使用Node.js和Seneca编写国际象棋微服务,第1部分

    node seneca (This is Part 1 of a three-part series [Part 2, Part 3]) (这是一个由三部分组成的系列文章的第1部分[ 第2 部分 , ...

  8. java模拟国际象棋游戏_java国际象棋小游戏

    [实例简介] 用java编写的国际象棋游戏 在eclipse环境下可以运行 界面美观 适合初学者 [实例截图] [核心代码] https___download.csdn.net_download_mo ...

  9. node seneca_使用Node.js和Seneca编写国际象棋微服务,第2部分

    node seneca 处理新需求而无需重构 (Handling new requirements without refactoring) Part 1 of this series talked ...

最新文章

  1. 什么是OpenMAX技术分析OpenMAX
  2. JDK+TOMCAT在LINUX下简单的配置
  3. 解决静态方法调用注入的service
  4. mysql数据库设计与应用答案智慧树_智慧树_MySQL数据库设计与应用_完整免费答案...
  5. 运行bat批处理文件不出现黑框
  6. 电脑屏保海底世界_水下栖息地:人类能否在海洋中居住?真的有人住在海底吗?...
  7. 计算机视觉目标检测算法总结5——RCNN系列算法
  8. java中字符串和数组如何比较_[Java教程]javascript中数组和字符串的方法比较
  9. adoption/adaption
  10. (日常搬砖)voc(xml)格式的标注转换为coco(json)格式
  11. 栈和队列的常见面试题-栈实现队列-队列实现栈
  12. java 判断文章的重复率_如何统计文件重复率
  13. 如何将手机中的Word文档转换成PDF文件?
  14. 手持式水质监测仪在污水处理中的应用
  15. DW-概率统计打卡task01
  16. 〔首届CSDN.南京区程序员聚会〕正式报名情况[每日更新7月19日 17:30]
  17. 手机壁纸网站源码 带全自动采集 响应式手机电脑端模板
  18. selenium爬取中国经济与社会发展统计数据库
  19. 前端定期小复盘, 每期都有小收获(一)
  20. C语言学习1——第一、二、三章学习记录

热门文章

  1. GDAL中MEM格式的简单使用示例
  2. shared_ptr四宗罪
  3. 小芭比linux怎么装win7_小户型再怎么装也是小?看完我闭嘴了
  4. mysql批量修改http为https,搜索和将数据库中的“ http”替换为“ https”
  5. Python的算数运算符
  6. IntelliJ IDEA激活破解有效方法
  7. uview组件得到回调的参数
  8. Yarn和SparkAlone对比
  9. chm 转 html 带索引,chm 的项目文件中包含创建 chm 文件所需的HTML文件信息、目录表文件信息、索引文件信息、窗口属 - 试题答案网问答...
  10. linux mysql emoji_Linux宝塔面板MySQL存储emoji,非服务器命令方法