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. luogu P1437 [HNOI2004]敲砖块

    三角形向右对齐后 你想打掉一个砖块,那么你必须打掉右上方的三角形,前缀和维护 若是第i列若是k个,那么它右边的那一列至少选了k-1个 f[i][j][k] 表示从后向前选到第 i 列第j个一共打了k次 ...

  2. COCOS2d 标准 android.MK

    LOCAL_PATH := $(call my-dir) include$(CLEAR_VARS) LOCAL_MODULE := game_shared PP_CPPFLAGS := -frtti ...

  3. NOIP 2017 赛后反思 [补档]

    首先写一下比赛的情况: D1: T1: 之前做过类似的题目, 因而知道大致的结论, 迅速完成. T2: 貌似直接模拟就可以了, 涉及到字符串信息提取, 比较麻烦, 因而想放到最后做. T3: 非常简洁 ...

  4. NHibernate官方文档——第八章 继承映射(Inheritance Mapping)

    本文翻译自NHibernate官方文档NHibernate Reference Documentation 4.1. 受限于个人知识水平,有些地方翻译可能不准确,但是我还是希望我的这些微薄的努力能为他 ...

  5. 个人对JAVA的SSH三大框架组合的偏见

    多数人JavaWeb的入门是学习SSH:struts+spring+hibernate:我在十年前(2006年)学习的,那时火的是struts1.x ,struts2还没诞生.   这三个框架组合,我 ...

  6. A system tap script to detect UDP beacons

    https://gist.github.com/jbradley89/178bbf3944786c494bd78f3df16a5472

  7. MailKit---发送邮件

    一封最复杂的电子邮件的基本情况为:含有邮件正文和邮件附件,邮件正文可以同时使用HTML格式和普通文本格式表示,并且HTML格式的正文中又引用了其他的内嵌资源.对于这种最复杂的电子邮件,可以采用如图所示 ...

  8. 2017.6.30 使用git新建项目、仓库并拉取、提交代码

    1.在码云上新建一个项目rms 2.在本地指定位置新建仓库,生成.git文件夹 3.同步远程仓库,并拉取最新代码 远程仓库默认名为orgin.可以修改,这里就是用默认名了. 注意:这里使用ssh方式的 ...

  9. Angular 学习笔记——service &constant

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...

  10. 自动播放——幻灯片缓冲效果&&带Loading效果的图片切换&&移动效果(按轨迹移动)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...