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. 洛谷 U19159 采摘毒瘤

    题目背景 Salamander见到路边有如此多的毒瘤,于是见猎心喜,从家里拿来了一个大袋子,准备将一些毒瘤带回家. 题目描述 路边共有nn 种不同的毒瘤,第i 种毒瘤有k_i 个,每个需要占据d_i  ...

  2. [xsy2213]tower

    题意:给一个地图,地图上的每个位置是空地或一个炮或一些敌人,给定每个炮的方向(上/下/左/右),每个炮只能打一个位置且炮弹轨迹不能相交,问最多打到多少敌人 原题貌似是TC SRM 627的题,题解在这 ...

  3. [BZOJ4398]福慧双修/[BZOJ2407]探险

    题目大意: 给定一个$n(n\leq40000)$个点$m(m\leq100000)$条边的有向图,求从$1$出发回到$1$的不经过重复结点的最短路. 思路: 首先Dijkstra求出从1出发到每个结 ...

  4. hdu 4826 Labyrinth DP

    题目链接:HDU - 4826 度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每一次只能走一格,且只能向 ...

  5. Java多线程设计模式(2)生产者与消费者模式

    1 Producer-Consumer Pattern Producer-Consumer Pattern主要就是在生产者与消费者之间建立一个“桥梁参与者”,用来解决生产者线程与消费者线程之间速度的不 ...

  6. 任务驱动,学习.NET开发系列第2篇------单词统计

    一 高效学习编程的办法 1 任务驱动方式学习软件开发 大部分人学习软件开发技术是通过看书,看视频,听老师上课的方式.这些方式有一个共同点即按知识点进行讲解.比如拿c#编程为例,首先是讲解大量的基础概念 ...

  7. 墨卡托投影、高斯-克吕格投影、UTM投影及我国分带方法

    转自原文 墨卡托投影.高斯-克吕格投影.UTM投影及我国分带方法 一.墨卡托投影.高斯-克吕格投影.UTM投影 1. 墨卡托(Mercator)投影 墨卡托(Mercator)投影,是一种" ...

  8. 去掉wget烦人的 “eta(英国中部时间)” 提示

    gentoo 里的 wget ,从1.12版本开始,就一直有个不影响功能的小毛病:由于中文翻译的失误,进度提示的时候,会被拉成很多行.原因就是原来英文的ETA这3个字母,被翻译成了 “eta(英国中部 ...

  9. 设计模式之装饰器模式(PHP实现)

    /** * 装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其结构.这种类型的设计模式属于结构型模式,它是作为现有的类的一个包装. * 这种模式创建了一个 ...

  10. c++之map函数/迭代器

    参考文献:https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html #include <iostream> #include < ...