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 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

6
1 1
1 3
1 4
4 1
4 3
4 4
 #include<stdio.h>
#include<string.h>
int main() {
int in[];
int tmp[];
int length=;
int size=length*length;
char temp;
//将输入变成0,1,开的为1,关的为0,放在数组in中
for(int i=;i<size;i++){
scanf("%c",&temp);
if(temp=='\n')
scanf("%c",&temp);
if(temp=='+')
in[i]=;
else
in[i]=;
}
// for(int i=0;i<size;i++){
// printf("%d \n",in[i]);
// }
//com数组存放的是开关的组合情况
int com[];
for(int i=;i<size+;i++){ for(int j=;j<i;j++){
com[j]=j;
}
int end=;
while(){
memcpy(tmp,in,size*sizeof(int));
//按照搜索到的组合情况对冰箱进行开关
for(int j=;j<i;j++){
int row=com[j]/;
int col=com[j]%;
for(int k=;k<length;k++){
tmp[row*length+k]=-tmp[row*length+k];
tmp[k*length+col]=-tmp[k*length+col];
}
tmp[row*length+col]=-tmp[row*length+col];
}
int zero=;
for(int j=;j<size;j++){
if(tmp[j]==){
zero+=;
}
}
// for(int k=0;k<4;k++){
// printf("%d\t",com[k]);
// }
// printf("\n");
// printf("sero is %d\n",zero);
// zero=size;
//判断是否找到答案
if(zero==size){
end=;
break;
}
//判断开关情况是i个的组合是否已经全部搜索完毕,是则搜索i+1个情况
if(com[]==size-i)
break;
//搜索下一个开关为i个的组合情况
for(int j=i-;j>=;j--){
if(com[j]!=size-(i-j)){
com[j]++;
for(int k=j+;k<i;k++)
com[k]=com[k-]+;
break;
} } }
//若找到结果,输出结果
if(end==){
printf("%d\n",i);
for(int j=;j<i;j++){
printf("%d %d\n",com[j]/+,com[j]%+);
}
}
} return ;
}

最新文章

  1. Run P4 without P4factory - A Simple Example In Tutorials.
  2. 初学者的python学习笔记1——作业篇
  3. HTML &lt;base&gt; 标签 为页面上的所有链接规定默认地址或默认目标
  4. oracle学习笔记系列------oracle 基本操作之基本函数的用法
  5. paper 97:异质人脸识别进展的资讯
  6. crackme1.exe解密过程
  7. UVa10917 A Walk Through the Forest(SPFA+记忆化搜索)
  8. IntPtr
  9. Ecshop图片不清晰怎么办?
  10. S3C2440触摸屏控制总结
  11. Simplify Path——LeetCode
  12. JAVA 异常 throw 与 throws
  13. 转载 Deep learning:二(linear regression练习)
  14. CSS3选择器~一看吓一跳,这么多不会
  15. Shiro第二篇【介绍Shiro、认证流程、自定义realm、自定义realm支持md5】
  16. js回到顶部------转载
  17. 考勤管理系统V1.0.3
  18. 2018.11.24 poj3261Milk Patterns(后缀数组)
  19. java接口应用—策略设计模式
  20. dp乱写2:论dp在不在dp中(但在dp范畴)内的应用

热门文章

  1. Android之Activity的启动模式
  2. 自己写Tiny6410的Bootloader总结!
  3. Persisting iOS Application Data in SQLite Database Using FMDB
  4. 为docker创建ubuntu带SSH的基础镜像
  5. 15 个 Docker 技巧和提示
  6. python3使用configparser解析配置文件
  7. POJ 3486 &amp;amp; HDU 1913 Computers(dp)
  8. asp.net显示评论的时候为几天前的格式
  9. [Angular] ViewChild &#39;read&#39; option
  10. IO流(一)File类