Poj 2965 the pilots brothers 'refrigerator search + Enumeration

Source: Internet
Author: User

Description

The game "the pilots brothers: Following the stripy elephant" has a quest where a player needs to open a refrigerator.

There are 16 handles on the refrigerator door. every handle can be in one of two States: open or closed. the refrigerator is open only when all handles are open. the handles are represented as a matrix 4 records 4. you can change the state of a handle in any location[I, j](1 ≤ I, j ≤ 4). However, this also changes states of all handles in rowIAnd all handles in ColumnJ.

The task is to determine the minimum number of handle switching necessary to open the refrigerator.

Input

The input contains four lines. each of the four lines contains four characters describing the initial state of appropriate handles. A symbol "+" means that the handle is in closed state, whereas the symbol "?" Means "open". At least one of the handles is initially closed.

Output

The first line of the input contains N-the minimum number of switching. the rest n lines describe switching sequence. each of the lines contains a row number and a column number of the matrix separated by one or more spaces. if there are several solutions, you may give any one of them.

Sample Input

-+-----------+--

Sample output

61 11 31 44 14 34 4


It is similar to 1753. You can play chess each time, but you have to seek the minimum number of steps in the same column in the same row and output the results in a forward (not necessarily) Order;

Code:

# Include <iostream> # include <cstdio> using namespace STD; int Step1 [18] [3]; int step2 [18] [3]; bool MAP2 [5] [5]; char map1 [5] [5]; int s; int min1; bool judge () {int I, j; for (I = 0; I <4; I ++) for (j = 0; j <4; j ++) if (MAP2 [I] [J] = false) return false; return true;} void DFS (int x, int y) {int I, j; for (I = 0; I <4; I ++) for (j = 0; j <4; j ++) {if (I = x) MAP2 [I] [J] =! MAP2 [I] [J]; If (j = y) MAP2 [I] [J] =! MAP2 [I] [J];} MAP2 [x] [Y] =! MAP2 [x] [Y];} void work (int K, int step) {int I; If (k = 16) {If (Judge () & step <min1) {min1 = step; for (I = 0; I <min1; I ++) step 2 [I] [0] = Step 1 [I] [0], step 2 [I] [1] = Step 1 [I] [1]; // key retention steps} else {int x = K/4; int y = K % 4; Work (k + 1, step); DFS (x, y ); step 1 [STEP] [0] = x; Step 1 [STEP] [1] = y; Work (k + 1, step + 1); DFS (x, y );}} int main () {int I, j; for (I = 0; I <4; I ++) for (j = 0; j <4; j ++) {CIN> map1 [I] [J]; If (map1 [I] [J] = '+') MAP2 [I] [J] = false; else MAP2 [I] [J] = true;} min1 = 17; Work (0, 0); cout <min1 <Endl; for (I = 0; I <min1; I ++) cout <step2 [I] [0] + 1 <''<step2 [I] [1] + 1 <Endl; 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.