Topic Description: The title is very long, it posted about topics connected to it = _ =. . https://vjudge.net/problem/UVA-1103
H input to the effect that a character row W column matrix (H <= 200, W <= 50). Each character is four pixels adjacent hex (ie 10,011,100 corresponds 9c), so you can get a picture, then find six kinds of pictograms contained in the title picture given what.
Thinking: This is an example on the purple book, the author gives an important reminder that find these characteristics in different hieroglyphs the number of blank inside each symbol, as long as we find within each block has a black Unicom several blank, China Unicom will be able to know the black block corresponds to which sign, to find Unicom block with dfs. According to this idea, my approach is to link each black blocks extracted from the original image, the background is white, so the number of how many white block Unicom, will be able to determine which symbols. Finally took a long time and only then debug it, there are a few details not pay attention to, such as the need to add a blank for each original picture up and down, avoid multi-blank judged Unicom internal black block occurs when the border.
code show as below:
. 1 #IN clud E <the iostream> 2 #include <memory.h> . 3 #include < String > . 4 #include <algorithm> . 5 the using namespace STD; . 6 const int MAXN = 206 ; . 7 int PIX [MAXN] [MAXN]; . 8 int IDX [MAXN] [MAXN]; . 9 int mcopy [MAXN] [MAXN] [MAXN]; // mcopy [i] [] [] indicates the i-th resultant pictograph extracted image 10 int H, W is; . 11 const char code [ . 6 ] = { 'W is ' , ' A ' , ' K ' , ' J ' , ' S ' , ' D ' }; 12 is 13 is void dfs ( int R & lt, int C, int ID, int Symbol) // This is the original picture dfs function, used to find Unicom black block, and to extract each block mcopy the black Unicom 14 { 15 IF (R & lt < 0 || R & lt> H + . 1 || C < 0 || C> W is * . 4 + . 1 )return; 16 if(idx[r][c] > 0 || pix[r][c] != symbol) return; 17 18 19 // cout << "r: " << r << " c: " << c << "\n"; 20 idx[r][c] = id; 21 mcopy[id-1][r][c] = 1; 22 dfs(r-1, c, id, symbol); 23 dfs(r+1, c, id, symbol); 24 dfs(r, c-1, id, symbol); 25 dfs(r, c+1, id, symbol); 26 } 27 28 void DFS ( int R & lt, int C, int ID, int Symbol, int I) // This function is mcopy process, wherein the white Unicom find the number of blocks 29 { 30 // COUT << "R & lt:" < <R & lt << "C:" C << << "\ n-"; 31 is static int n-= . 1 ; 32 // COUT n-++ << << "\ n-"; 33 is IF (R & lt < 0 || R & lt> H + . 1 || C < 0 || C> W is * . 4 + . 1 ) return ; 34 if(idx[r][c] > 0 || mcopy[i][r][c] != 0) return; 35 idx[r][c] = id; 36 dfs(r-1, c, id, symbol, i); 37 dfs(r+1, c, id, symbol, i); 38 dfs(r, c-1, id, symbol, i); 39 dfs(r, c+1, id, symbol, i); 40 } 41 42 int chartonum(char c) 43 { 44 if(isalpha(c)) return c-'a'+10; 45 else return c-'0'; 46 } 47 48 int main() 49 { 50 //freopen("uva1103_in.txt", "r", stdin); 51 //freopen("uva1103_out.txt", "w", stdout); 52 int kase = 0; 53 char c; 54 55 while(cin >> H >> W && H){ 56 memset(pix, 0, sizeof(pix)); //Prior to this position clear on the outside while, leading to wa. Each process will have a new image after the image is cleared 57 is int Val, Y = . 1 ; 58 for ( int I = . 1 ; I <= H; I ++) { // input processing operation 59 Y = . 1 ; 60 for ( int J = 0 ; J <W is; ++ J) { 61 is the while ((C = getchar ()) == ' \ n- ' ); 62 is Val = chartonum (C); 63 is for ( int X = 0 ; X < . 4; ++x){ 64 pix[i][y] = (val & 0x08) >> 3; 65 y = (y+1) % (4*W+1); 66 val = val << 1; 67 } 68 } 69 } 70 memset(idx, 0, sizeof(idx)); 71 memset(mcopy, 0, sizeof(mcopy)); 72 int cnt = 0 ; 73 is for ( int I = 0 ; I <H + 2 ; I ++) { // the original image processing, cnt is the number of the original image pictograph 74 for ( int J = 0 ; J <* W is . 4 + 2 ; ++ J) { 75 IF (IDX [I] [J] == 0 && PIX [I] [J] == . 1 ) { 76 DFS (I, J, ++ CNT, . 1 ); 77 } 78 } 79 } 80 the printf ( "% D Case: " , ++ kase); 81 String ANS; 82 for ( int I = 0 ; I <CNT; I ++) { // for each pictograph 83 Memset (IDX, 0 , the sizeof (IDX) ); // access idx cleared state array 84 int NUM = 0 ; 85 for ( int J = 0 ; J <H + 2 ; ++ J) { 86 for ( int K = 0 ; K <W is * . 4 + 2; ++ K) { 87 IF (IDX [J] [K] == 0 && mcopy [I] [J] [K] == 0 ) { // the number of white patches have several 88 DFS (J, K, NUM ++, 0 , I); // if (j, k) position has not been accessed && (j, k) on a blank pixel is, from its start DFS, to find a link block 89 } 90 } 91 } 92 code = + ans [num- . 1 ]; // NUM Unicom is the number of white blocks, so that which can correspond to a pictograph, ans was added in 93 } 94 Sort (ans.begin (), ans.end ( )); //Size are arranged in alphabetical order 95 COUT ANS << << " \ n- " ; 96 ans.clear (); 97 } 98 99 100 }
PS: Read the author's implementation code, it will also be recorded, learning ~