HDU 1198 Farm Irrigation (query set optimization, diagram)

Source: Internet
Author: User

HDU 1198 Farm Irrigation (query set optimization, diagram)

This is similar to the HDU smooth project, except that the smooth project provides the connection relationship between numbers,

This question requires you to determine the connectivity, that is, whether the two water pipes can be connected together is also the difficulty of this question.

Record the status and continuously combine (). Note that you only need to judge the left side and the top side. This will not repeat the judgment, and it will certainly be able to traverse all the states.

# Include
 
  
# Include
  
   
# Include
   
    
// Record the shape of the pipe. Each pipe is represented by a 4-character string consisting of '0' and '1'. // It indicates whether there is an interface between the upper, lower, and left sides, respectively, '0' none, '1' has char a [11] [5] = {"1010", "1001", "0110", "0101", "1100 ", "0011", "1011", "1110", "0111", "1101", "1111"}; int father [51] [51]; char map [51] [51]; int n, m; using namespace std; int find (int x) // find the parent node, and the compression path {if (father [x/n] [x % n]! = X) father [x/n] [x % n] = find (father [x/n] [x % n]); return father [x/n] [x % n];} void Union (int x, int y) // merges the set of x and y {x = find (x ); y = find (y); if (x! = Y) father [y/n] [y % n] = x;} void judge (int I, int j) // determine whether map [I] [j] is connected to the left and top sides of map, for example, if (j> 0 & a [map [I] [j]-'a'] [2] = '1' & A [map [I] [J-1]-'a'] [3] = '1 ') // determine the Union above (I * n + j, I * n + J-1 ); if (I> 0 & a [map [I] [j]-'a'] [0] = '1' & A [map [I-1] [j] -'a'] [1] = '1 ') // determine the left side of Union (I * n + j, (I-1) * n + j);} int main () {int I, j, count; while (scanf ("% d", & m, & n )! =-1 & (n! =-1 | m! =-1) {for (I = 0; I
    
     

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.