POJ2965----The Pilots Brothers' refrigerator

来源:互联网 发布:linux命令源代码 编辑:程序博客网 时间:2024/05/21 03:25
The Pilots Brothers' refrigerator
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 14029 Accepted: 5261 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х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 row i and all handles in column j.

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

假如只想改变(1, 2) 的开关的状态,则这个时候需要将第1 行第2 列的所有开关都按下,此时,则第一行和第一列除了(1, 2) 外都改变了4 次,相当于没有改变,而(1, 2) 改变了7 次,相当于改变了1 次,剩下的改变了2 次,相当于没改变。
#include<iostream>using namespace std;int main(){//input_char存储输入字符,input_count对要翻转的把手计数(要想改变一个把手的状态,可以把对应的行和列的把手都翻转一边,最后则只有该把手的状态改变)。char input_char[4][4];int i,j;char input_count[4][4];for(i=0;i<4;i++)for(j=0;j<4;j++)input_count[i][j]=0;for(i=0;i<4;i++)for(j=0;j<4;j++){cin>>input_char[i][j];if(input_char[i][j]=='+'){for(int k=0;k<4;k++){input_count[i][k] +=1;input_count[k][j] +=1;}//该把手重复计数了+1input_count[i][j] -=1;}}int count = 0;int output[16][2];for(i=0;i<4;i++)for(j=0;j<4;j++){//翻转偶数次等于不翻转,count记录需要翻转的把手,output存储坐标if(input_count[i][j]%2==1){output[count][0] = i+1;output[count][1] = j+1;count++;}}cout<<count<<endl;for(i=0;i<count;i++){cout<<output[i][0]<<"  "<<output[i][1]<<endl;}}