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

The Pilots Brothers' refrigerator - poj 2965的更多相关文章

  1. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  2. 枚举 POJ 2965 The Pilots Brothers' refrigerator

    题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...

  3. poj 2965 The Pilots Brothers' refrigerator (dfs)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17450 ...

  4. POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16868 ...

  5. POJ 2965 The Pilots Brothers' refrigerator 位运算枚举

      The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 151 ...

  6. POJ 2965 The Pilots Brothers' refrigerator (DFS)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15136 ...

  7. POJ:2695-The Pilots Brothers' refrigerator

    题目链接:http://poj.org/problem?id=2965 The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limi ...

  8. The Pilots Brothers' refrigerator 分类: POJ 2015-06-15 19:34 12人阅读 评论(0) 收藏

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20304 ...

  9. 2965 -- The Pilots Brothers' refrigerator

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27893 ...

随机推荐

  1. [POI2015]Kinoman

    题目大意: 给你一个长度为n的数列f,f中共有m种不同的数,每种数都有一个权值w[i]. 你可以选定一个f中的区间,定义区间的权值为这一区间只出现一次的数的权值和. 问权值最大的区间的权值是多少? 思 ...

  2. OVF? OVA? VMDK? – File Formats and Tools for Virtualization

    I recently worked on a project to create a “virtual appliance” for one of our customers. They have a ...

  3. Oracle ORA-01033: 错误解决办法

    转自 Oracle ORA-01033: 错误解决办法

  4. TCP/IP协议组随笔

    原文:https://my.oschina.net/xianggao/blog/654677 IP层负责网络主机的定位,数据传输的路由,由IP地址可以唯一的确定Internet上的一台主机. TCP层 ...

  5. log4j输出日志到flume

    现需要通过log4j将日志输出到flume,通过flume将日志写到文件或hdfs中 配置flume-config文件 将日志下沉至文件 a1.sources = r1 a1.sinks = k1 a ...

  6. Linux修改SSH端口

    为什么要修改默认22端口 最近公司ssh全部换掉了默认的22端口,主要是为了防止被黑客大规模的扫描. 修改步骤 如果有需要请关闭防火墙(防止改错端口无法登陆) 修改sshd_config vim /e ...

  7. 【Zookeeper】分布式服务框架 Zookeeper -- 管理分布式环境中的数据

    Zookeeper 分布式服务框架是 Apache Hadoop 的一个子项目,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务.状态同步服务.集群管理.分布式应用配置项的管理 ...

  8. Java程序中的Log文件配置

    log4j.properties文件 log4j.rootLogger=info,stdout,logfile #stdout log4j.appender.stdout=org.apache.log ...

  9. asp.net限制用户登录错误次数

    很经常在登录一个网站的时候看到,如果你登录的时候输入的账号密码错误超过三次就被锁定,然后等一段时间才能继续登录,最最经常使用的就是银行系统啦~~ 该功能处理流程如下: string uid = Req ...

  10. 用word2vec对语料进行训练

    在Linux上安装好word2vec, 进入trunk文件夹,把分词后的语料文件放在trunk文件夹内,执行:./word2vec -train tt.txt -output vectors.bin ...