(Water question NUPT 1593) 8. Queen's question (judge whether any element is in the same row, column, or diagonal line), nupt1593

Source: Internet
Author: User

(Water question NUPT 1593) 8. Queen's question (judge whether any element is in the same row, column, or diagonal line), nupt1593

Question:

8. Queen's questionTime limit (Common/Java):2000 MS/6000 MS running memory limit: 65536 KByte
Total submissions: 1116 pass the test: 137

Description

Put eight queens on 8x8 garbled chess. Please judge whether they attack each other, that is, whether both queens are in the same row, column, or diagonal line.



Input

The input contains multiple test cases (up to 104 ). The number of test cases is given first. Then there is each test case. Each test case contains eight lines, each line uses eight characters to indicate the placement of the Queen on the board, "Q" indicates the queen, and "#" indicates null.

Output

For each test case, the output line contains:

L "Case #:", # indicates the serial number

L if the eight queens in the test case attack each other, the output is Yes; otherwise, the output is No.

Sample Input

2
Q #######
### Q ####
##### Q ##
# Q #####
####### Q
#### Q ###
###### Q #
# Q #####
####### Q
### Q ####
Q #######
# Q #####
##### Q ##
# Q ######
###### Q #
#### Q ###

Sample output

Case 1: Yes
Case 2: No

Prompt

 

Question Source

NUPT



Question Analysis:

Simple question. Because the same diagonal line was missing at the beginning, it was later added to determine whether the line was the same. So it seems a little messy. However, the AC is okay.


The Code is as follows:

/** Aa2.cpp ** Created on: March 24, 2015 * Author: Administrator */# include <iostream> # include <cstdio> # include <cmath> using namespace std; const int maxn = 8; struct Point {int x; int y;} points [maxn]; char map [maxn + 1] [maxn + 1]; bool visited [maxn]; int main () {int t; scanf ("% d", & t); int kk; for (kk = 1; kk <= t; ++ kk) {// printf ("Case % d:", kk); memset (visited, false, sizeof (visited); int I; for (I = 0; I <maxn; ++ I) {scanf ("% s", & map [I]);} bool flag = true; // checks whether a specific element is in the same column of int j; for (I = 0; I <maxn; ++ I) {for (j = 0; j <maxn; ++ j) {if (map [I] [j] = 'q') {points [I]. x = I; points [I]. y = j; if (visited [j] = false) {visited [j] = true;} else {flag = false;} break ;}} if (flag = false) {break ;}// you can determine whether a specific element is on the same diagonal line. otherwise, WA) if (flag = true) {for (I = 0; I <maxn; ++ I) {for (j = I + 1; j <maxn; ++ j) {if (fabs (points [I]. x-points [j]. x) = fabs (points [I]. y-points [j]. y) {flag = false ;}}} if (flag = true) {printf ("Case % d: No \ n", kk );} else {printf ("Case % d: Yes \ n", kk) ;}} return 0 ;}




Related Article

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.