Poj 2965 the pilots brothers 'refrigerator

Source: Internet
Author: User

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


Similar to this one, you can read this question first.


The AC code is as follows:

#include<iostream>#include<cstdio>using namespace std;int n,a[5][5];char b[5][5];int h[17],z[17],H[17],Z[17],minn;int PD(){    int i,j;    for(i=0;i<4;i++)        for(j=0;j<4;j++)            if(a[i][j]!=0)            return 0;    return 1;}void dfs(int x,int y){   int i;   for(i=0;i<4;i++)        a[x][i]=!a[x][i];   for(i=0;i<4;i++)    a[i][y]=!a[i][y];   a[x][y]=!a[x][y];}void work(int cur,int step){    int i;    if(cur==16)    {        if(PD()&&step<minn)            {                minn=step;                for(i=0;i<minn;i++)                {                    H[i]=h[i];Z[i]=z[i];                }            }    }    else{        work(cur+1,step);        dfs(cur/4,cur%4);        h[step]=cur/4;z[step]=cur%4;        work(cur+1,step+1);        dfs(cur/4,cur%4);    }}int main(){    int i,j;    for(i=0;i<4;i++)        cin>>b[i];    for(i=0;i<4;i++)        for(j=0;j<4;j++)        if(b[i][j]=='+')        a[i][j]=1;        else a[i][j]=0;        minn=17;    work(0,0);    cout<<minn<<endl;    for(i=0;i<minn;i++)        cout<<H[i]+1<<" "<<Z[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.