Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 20325 |
|
Accepted: 7830 |
|
Special Judge |
Description
The game "The pilots brothers:following the stripy elephant" has a quest where a player needs to open a refrigerator.
There is handles on the refrigerator door. Every handle can is in one of the States:open or closed. The refrigerator is open if all handles is open. The handles is 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 are 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 is several solutions, you could give any one of the them.
Sample Input
-+-----------+--
Sample Output
61 11 31 44 14 34 4
1#include <stdio.h>2#include <string.h>3 intMain () {4 int inch[ -];5 inttmp[ -];6 intLength=4;7 intsize=length*length;8 Chartemp;9 //Change the input to 0, 1, 1, off 0, in the array inTen for(intI=0; i<size;i++){ Onescanf"%c",&temp); A if(temp=='\ n') -scanf"%c",&temp); - if(temp=='+') the inch[i]=0; - Else - inch[i]=1; - } + //for (int i=0;i<size;i++) { - //printf ("%d \ n", In[i]); + // } A //The COM array holds the combination of switches at intcom[ -]; - for(intI=1; i<size+1; i++){ - - for(intj=0; j<i;j++){ -com[j]=J; - } in intEnd=0; - while(1){ tomemcpy (TMP,inch, size*sizeof(int)); + //switch the refrigerator according to the combination of the search - for(intj=0; j<i;j++){ the introw=com[j]/4; * intcol=com[j]%4; $ for(intk=0; k<length;k++){Panax Notoginsengtmp[row*length+k]=1-tmp[row*length+K]; -tmp[k*length+col]=1-tmp[k*length+Col]; the } +tmp[row*length+col]=1-tmp[row*length+Col]; A } the intzero=0; + for(intj=0; j<size;j++){ - if(tmp[j]==1){ $zero+=1; $ } - } - //for (int k=0;k<4;k++) { the //printf ("%d\t", Com[k]); - // }Wuyi //printf ("\ n"); the //printf ("Sero is%d\n", zero); - //zero=size; Wu //determine if the answer is found - if(zero==size) { AboutEnd=1; $ Break; - } - //determine whether the switch is a combination of i have been all searched, is the search i+1 a situation - if(com[0]==size-i) A Break; + //search for a combination of the next switch for I the for(intj=i-1; j>=0; j--){ - if(Com[j]!=size-(ij)) { $com[j]++; the for(intk=j+1; k<i;k++) thecom[k]=com[k-1]+1; the Break; the } - in } the the } About //If the result is found, the output the if(end==1){ theprintf"%d\n", i); the for(intj=0; j<i;j++){ +printf"%d%d\n", com[j]/4+1, com[j]%4+1); - } the }Bayi } the the return 0; -}
The pilots ' Refrigerator-poj 2965