HDOJ 4414 Finding crosses search

Source: Internet
Author: User

[Cpp]
// HDOJ 4414 Finding crosses search
 
/*

Question: How many cross numbers are shown in a figure?
The definition of a cross is composed of '#' and the size of the cross is greater than or equal to 3, and '#' cannot appear in its adjacent position (horizontal or vertical)
For details, refer to the question
 
Idea: enumerate the midpoint and find the number of '#' that can be extended in the four directions. time complexity O (n ^ 3)
 
*/
 
 
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
 
# Define INF 100000000
# Define N 55
 
Int n; www.2cto.com
Char map [N] [N];
 
Bool check (int x, int y ){
If (x> = 0 & x <n & y> = 0 & y <n)
Return true;
Return false;
}
 
Int Min (int x, int y ){
Return x <y? X: y;
}
 
Bool bx (int x, int y ){
Int I, j, xx, yy;
Int a = 1, B = 1, c = 1, d = 1;
Bool aa = false, bb = false, cc = false, dd = false;
For (I = 1; a = I; ++ I ){
Yy = y-I;
If (check (x, yy) & map [x] [yy] = '#')
If (! Check (x + 1, yy) | (check (x + 1, yy) & map [x + 1] [yy]! = '#'))
If (! Check (x-1, yy) | (check (x-1, yy) & map [x-1] [yy]! = '#'))
+ A; aa = true;
}

For (I = 1; B = I; ++ I ){
Yy = y + I;
If (check (x, yy) & map [x] [yy] = '#')
If (! Check (x + 1, yy) | (check (x + 1, yy) & map [x + 1] [yy]! = '#'))
If (! Check (x-1, yy) | (check (x-1, yy) & map [x-1] [yy]! = '#'))
+ + B, bb = true;
}

For (I = 1; c = I; ++ I ){
Xx = x-I;
If (check (xx, y) & map [xx] [y] = '#')
If (! Check (xx, y + 1) | (check (xx, y + 1) & map [xx] [y + 1]! = '#'))
If (! Check (xx, Y-1) | (check (xx, Y-1) & map [xx] [Y-1]! = '#'))
++ C, cc = true;
}

For (I = 1; d = I; ++ I ){
Xx = x + I;
If (check (xx, y) & map [xx] [y] = '#')
If (! Check (xx, y + 1) | (check (xx, y + 1) & map [xx] [y + 1]! = '#'))
If (! Check (xx, Y-1) | (check (xx, Y-1) & map [xx] [Y-1]! = '#'))
++ D, dd = true;
}
 
Return a = B & B = c & c = d & aa & bb & cc & dd;
}
 
Int cal (){
Int I, j, ans = 0;
For (I = 0; I <n; ++ I ){
For (j = 0; j <n; ++ j)
If (map [I] [j] = '#' & bx (I, j ))
++ Ans;
}
Return ans;
}
 
Int main (){
Int I;
While (scanf ("% d", & n), n ){
For (I = 0; I <n; ++ I)
Scanf ("% s", map [I]);
Printf ("% d \ n", cal ());
}
Return 0;
}

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.