Description

You all are familiar with the famous 8-queens problem which asks you to place 8 queens on a chess board so no two attack each other. In this problem, you will be given locations of queens and knights and pawns and asked to find how many of the unoccupied squares on the board are not under attack from either a queen or a knight (or both). We'll call such squares "safe" squares. Here, pawns will only serve as blockers and have no capturing ability. The board below has 6 safe squares. (The shaded squares are safe.)

Recall that a knight moves to any unoccupied square that is on the opposite corner of a 2x3 rectangle from its current position; a queen moves to any square that is visible in any of the eight horizontal, vertical, and diagonal directions from the current position. Note that the movement of a queen can be blocked by another piece, while a knight's movement can not.

Input

There will be multiple test cases. Each test case will consist of 4 lines. The first line will contain two integers n and m, indicating the dimensions of the board, giving rows and columns, respectively. Neither integer will exceed 1000. The next three lines will each be of the form 
k r1 c1 r2 c2 ... rk ck 
indicating the location of the queens, knights and pawns, respectively. The numbering of the rows and columns will start at one. There will be no more than 100 of any one piece. Values of n = m = 0 indicate end of input.

Output

Each test case should generate one line of the form 
Board b has s safe squares. 
where b is the number of the board (starting at one) and you supply the correct value for s.

Sample Input
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAARABIDASIAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAAAAMFBwT/xAAlEAACAQQCAQMFAAAAAAAAAAABAgMABAURBiESIjFBMjZxdbP/xAAYAQACAwAAAAAAAAAAAAAAAAAAAwEEBf/EABsRAQEAAgMBAAAAAAAAAAAAAAEAAgMEEyFh/9oADAMBAAIRAxEAPwDQeRW+SyVnctBIkiiScOk87qm0ciP0aZWA8dkEDZA2fcGPCWPI+PXkUt3GIcQjkyQxTGdtMrAhUVQO5CraVd/UB1pa7cnHmbaW5hjxEktoZJJGulnjChWYsT4lvLoHvr3B1vommvuQYaSe/jGSxrW9yXEiCWIiTe9eWohvs/LH8n5ocDh9jlnsER+zt+9wDE9G0uKWO4hSaGRJIpFDI6MCrKewQR7ilVfFPs7B/r4P5rStB8ZJW9KUqIlKUoi//9k=" alt="" /> Copy sample input to clipboard 
4 4
2 1 4 2 4
1 1 2
1 2 3
2 3
1 1 2
1 1 1
0
1000 1000
1 3 3
0
0
0 0
Sample Output
Board 1 has 6 safe squares.
Board 2 has 0 safe squares.
Board 3 has 996998 safe squares.
这题可能有理解错误的地方就是对queen,它在八个方向的移动是不限的,除非遇到一个其他对象。
#include <iostream>
#include <vector> using namespace std; char location[][]; int king[] = {-, -, -, , -, , , , , , , -, , -, -, -};
int queueL[] = {-, -, -, , -, , , -, , , , -, , , , }; int main(int argc, char const *argv[])
{
int m, n, num, x, y;
int testCase = ;
while (cin >> m >> n && m != && n != ) {
++testCase;
memset(location, '', sizeof(location));
vector<int> queue; // queen
cin >> num;
queue.resize(num * + );
int i = , j = ;
while (i++ < num) {
cin >> x >> y;
location[x - ][y - ] = '';
queue[j] = x - ;
queue[j + ] = y - ;
j += ;
} // knight
i = ;
cin >> num;
while (i++ < num) {
cin >> x >> y;
location[x - ][y - ] = '';
for (int k = ; k < ; k += ) { // 处理8个方向,也即八个“日”字形路线
int xT = x - + king[k];
int yT = y - + king[k + ];
if (xT >= && xT < m && yT >= && yT < n && location[xT][yT] == '')
location[xT][yT] = '';
}
} // pawn
i = ;
cin >> num;
while (i++ < num) {
cin >> x >> y;
location[x - ][y - ] = '';
} // Queen 的处理
for (i = ; i < j; i += ) {
for (int p = ; p < ; p += ) {
int xT = queue[i];
int yT = queue[i + ];
for (int q = ; ; ++q) {
xT += queueL[p];
yT += queueL[p + ];
if (xT >= && xT < m && yT >= && yT < n && location[xT][yT] == '') {
location[xT][yT] = '';
} else if (xT >= && xT < m && yT >= && yT < n && location[xT][yT] == '') { // 在该直线上遇到了其他对象,所以不需要再走了
break;
} else if(xT < || xT >= m || yT < || yT >= n) { // 跑出了棋盘,那么说明在这条直线上已经不需要再走了
break;
}
}
}
} int result = ;
for (i = ; i != m; ++i) {
for (j = ; j != n; ++j)
if (location[i][j] == '')
++result;
} cout << "Board " << testCase << " has " << result << " safe squares." << endl;
}
return ;
}

sicily 1172. Queens, Knights and Pawns的更多相关文章

  1. Codeforces Gym 100650D Queens, Knights and Pawns 暴力

    Problem D: Queens, Knights and PawnsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu ...

  2. HOJ题目分类

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

  3. POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 12439   Acce ...

  4. sicily 中缀表达式转后缀表达式

    题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...

  5. POJ 2942 Knights of the Round Table

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 10911   Acce ...

  6. LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)

    题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...

  7. 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS

    [Usaco2005 Dec]Knights of Ni 骑士 Description  贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...

  8. sicily 1934. 移动小球

    Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...

  9. Knights of the Round Table-POJ2942(双连通分量+交叉染色)

    Knights of the Round Table Description Being a knight is a very attractive career: searching for the ...

随机推荐

  1. poj 1469 COURSES (二分匹配)

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16877   Accepted: 6627 Descript ...

  2. Python单例模式的四种方法

    在这之前,先了解super()和__new__()方法 super()方法: 返回一个父类或兄弟类类型的代理对象,让你能够调用一些从继承过来的方法. 它有两个典型作用: a. 在单继承的类层次结构中, ...

  3. 关于Python的 a, b = b, a+b

    Python中有一种写法:多个值同时赋给多个变量,如:a, b = b, a+b 1. A写法 a = 0, b = 1 a, b = b, a+b print a, b #结果为:1 1 这种写法, ...

  4. BZOJ5338:[TJOI2018]异或——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5338 现在有一颗以1为根节点的由n个节点组成的树,树上每个节点上都有一个权值vi. 现在有Q 次操 ...

  5. CF633C:Spy Syndrome 2——题解

    https://vjudge.net/problem/CodeForces-633C http://codeforces.com/problemset/problem/633/C 点击这里看巨佬题解 ...

  6. Hydra—密码爆破神器

    公司邮箱系统密码复杂度规则:字母大小写.数字.特殊字符,四选三,长度8位以上.这种复杂度的密码看着是比较安全的,但因历史原因,邮箱系统开放了外网登陆权限,加之公司人数众多,必然会有少量员工把自己的密码 ...

  7. C++语言中数组指针和指针数组彻底分析

    #################################                              ##       基本知识               ##        ...

  8. ubuntu下安装golang

    1.安装 sudo apt-get install golang 2.查看go的安装路径 go env 查看 GOROOT="/usr/lib/go-1.6" 3.修改环境变量 e ...

  9. [mysql]数据库引擎查看

    1.查看数据库引擎 全局下,show engines; 2.察看数据库引擎 show variables like '%engine%'; 或者show create table xxx\G 会显示默 ...

  10. bzoj 1564 [NOI2009]二叉查找树 区间DP

    [NOI2009]二叉查找树 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 906  Solved: 630[Submit][Status][Discu ...