Poj 2965 the pilots brothers 'refrigerator

Source: Internet
Author: User
The pilots brothers 'refrigerator
Time limit:1000 ms   Memory limit:65536 K
Total submissions:18109   Accepted:6871   Special Judge

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

Source

Northeastern Europe 2004, western subregion
# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; bool map [20] [20]; int best = 1000; int LJ [70000] [2]; int B [70000] [2]; int L = 0, T; int check () // check whether the door is fully open {int I, j, TOT = 0; for (I = 0; I <4; I ++) for (j = 0; j <4; j ++) TOT + = map [I] [J]; If (TOT = 16) return 1; return 0;} void change (INT X, int y) // change the door status {/* map [x] [Y] =! Map [x] [Y]; Map [x + 1] [Y] =! Map [x + 1] [Y]; If (x> 0) map [x-1] [Y] =! Map [x-1] [Y]; Map [x] [Y + 1] =! Map [x] [Y + 1]; If (Y> 0) map [x] [Y-1] =! Map [x] [Y-1]; */INT I, j; for (I = 0; I <4; I ++) map [x] [I] =! Map [x] [I]; for (j = 0; j <4; j ++) map [J] [Y] =! Map [J] [Y]; Map [x] [Y] =! Map [x] [Y]; // The point is changed back, so it must be changed once} void search (int K, int ans) {int X, Y; int I; if (k = 16) {If (check () & Ans <best) {best = ans; for (I = 0; I <best; I ++) {B [I] [1] = LJ [I] [1]; B [I] [0] = LJ [I] [0] ;}} else {// cout <ans <Endl; X = K/4; y = K % 4; search (k + 1, ANS ); LJ [l] [0] = x + 1; LJ [l] [1] = Y + 1; l ++; change (x, y ); search (k + 1, ANS + 1); change (x, y); // restore the door status l -- ;}} int main () {int I, J; char A; for (I = 0; I <4; I ++) {for (j = 0; j <4; j ++ ){ Cin> A; if (a = '-') map [I] [J] = 1; else map [I] [J] = 0 ;}} search (0, 0); If (best! = 1000) cout <best <Endl; else cout <"impossible" <Endl; for (I = 0; I <best; I ++) cout <B [I] [0] <"" <B [I] [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.