Poj 2965 the pilots brothers 'refrigerator

Source: Internet
Author: User

The pilots brothers 'refrigerator
Time limit:1000 ms   Memory limit:65536 K
Total submissions:19011   Accepted:7277   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

Refer to the efficient solution of experts:
> Proof: to change a '+' symbol to '-', the corresponding row and column operands must be odd. It can be proved that, if an operation is performed at each position of the row and column corresponding to the '+' position, only the symbols at the '+' position change in the entire graph, and the rest remain unchanged.
> Set a 4*4 integer array with the initial value of zero to record the operands of each vertex. Then, 1 is added to the positions of rows and columns on each '+, the result is calculated as mod 2 (because the result of an even number operation is the same as that of no operation, which is the inverse principle mentioned above), and then calculates
> The number is the operand, and the position of the first operation is the location where the operation is to be performed (other operations with the original number being an even number do not work, so no operation is performed)
*********************************
Here, Shanghai Stock Exchange can make the values of the array '-' as follows '-'
********************************
After adding 1 to the positions of all rows and columns in the above proof, before modulo 2, perform operations on all locations on the given array status to the number of operations it stores, for example, if a [I] [J] = N, the (I, j) operation is performed n times. After all the operations are completed, all are '-' arrays.
In fact, it is not a model 2 operation, and has done a lot of useless work.
The above operation sequence does not affect the result. If there is a minimum step, this step must be included in the above operation. (To put it simply: the above operations already include all the operations that can change the location)
The operation after mod 2 removes all useless operations. This operation also contains the minimum step.
However, after mod 2 is removed from any or several steps, it is impossible to get all. (This also proves that, because the operation sequence is not affected, the minimum step is first performed and the result is '-'. If step m is left, then, after performing the M step operation in the "-" array state, you will get
'-' Array status, which can only be an even number of operations at the same position, conflicts with the preceding mod 2, so m = 0 ), therefore, the operation after mod 2 is the operation of the minimum step.


#include <iostream>using namespace std;bool mark[4][4];char s[4][4];/*void print(){int i,j;for(i=0;i<4;i++){for(j=0;j<4;j++)cout<<mark[i][j]<<" ";cout<<endl;}}*/int main(){    int i,j,k;    int ci[16],cj[16];    int nas = 0;    memset(mark,0,sizeof(mark));for(i = 0;i < 4;i++)cin >> s[i];    for(i = 0;i < 4;i++)        for(j = 0;j < 4;j++)        {            char c = s[i][j];            if(c == '+')            {//cout<<i+1<<"  "<<j+1<<endl;                mark[i][j] = !mark[i][j];                for(k = 0;k < 4;k++)                {                    mark[i][k] = !mark[i][k];                    mark[k][j] = !mark[k][j];                }//print();            }        }for(i = 0;i < 4;i++)for(j = 0;j < 4;j++)if(mark[i][j] == true){ci[nas] = i + 1;cj[nas] = j + 1;nas ++;}printf("%d\n",nas);for(i = 0;i < nas;i++){printf("%d %d\n",ci[i],cj[i]);}return 0;}


Poj 2965 the pilots brothers 'refrigerator

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.