Sicily 1172. Queens, knights and pawns

Source: Internet
Author: User
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 much 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 ctions 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 be 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 e will be no more than 100 of any one piece. values of N = m = 0 indicate end of input.

Output

Each test case shoshould 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 copy sample input to clipboard
4 42 1 4 2 41 1 21 2 32 31 1 21 1 101000 10001 3 3000 0
Sample output
Board 1 has 6 safe squares.Board 2 has 0 safe squares.Board 3 has 996998 safe squares.
This question may be misunderstood by Queen, which is not limited to moving in eight directions unless another object is encountered.
# Include <iostream> # include <vector> using namespace STD; char location [1001] [1001]; int King [16] = {-2,-1,-2, 1,-1, 2, 1, 2, 2, 1, 2,-1, 1,-2,-1,-2 }; int queuel [16] = {-1,-1,-1, 0,-1, 1, 0,-1, 0, 1,-1, 1, 0, 1, 1}; int main (INT argc, char const * argv []) {int m, n, num, X, Y; int testcase = 0; while (CIN> m> N & M! = 0 & n! = 0) {++ testcase; memset (location, '0', sizeof (location); vector <int> queue; // Queen CIN> num; queue. resize (Num * 2 + 1); int I = 0, j = 0; while (I ++ <num) {CIN> x> Y; location [X-1] [Y-1] = '2'; queue [J] = x-1; queue [J + 1] = Y-1; J + = 2;} // knight I = 0; CIN> num; while (I ++ <num) {CIN> x> Y; location [X-1] [Y-1] = '2'; For (int K = 0; k <16; k + = 2) {// PROCESS 8 directions, that is, 8 "Day" line int XT = x-1 + King [k]; int yt = Y-1 + King [k + 1]; if (XT> = 0 & XT <M & yt> = 0 & yt <n & location [XT] [yt] = '0 ') location [XT] [yt] = '1' ;}// pawn I = 0; CIN> num; while (I ++ <num) {CIN> x> Y; Location [X-1] [Y-1] = '2';} // processing of Queen for (I = 0; I <j; I + = 2) {for (INT p = 0; P <16; P + = 2) {int XT = queue [I]; int yt = queue [I + 1]; for (INT q = 0; ++ q ){ XT + = queuel [p]; yt + = queuel [p + 1]; if (XT> = 0 & XT <M & yt> = 0 & yt <n & location [XT] [yt] = '0 ') {location [XT] [yt] = '1 ';} else if (XT> = 0 & XT <M & yt> = 0 & yt <n & location [XT] [yt] = '2 ') {// other objects are encountered on this line, so you do not need to go through break again ;} else if (XT <0 | XT> = M | yt <0 | yt> = N) {// ran out of the board, it means that you no longer need to go through break on this line; }}} int result = 0; for (I = 0; I! = M; ++ I) {for (j = 0; J! = N; ++ J) if (location [I] [J] = '0') ++ result ;} cout <"board" <testcase <"has" <result <"Safe squares. "<Endl;} return 0 ;}

 

Sicily 1172. Queens, knights and pawns

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.