2965

he Pilots Brothers' refrigerator
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 19995   Accepted: 7695   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

Source

Northeastern Europe 2004, Western Subregion
 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; int map[][],ak[],AK[],flg,n,step; int judge(int map[][])
{
for(int i=;i<=;i++)
for(int j=;j<=;j++)
{
if(map[i][j]!=)
return ;
}
return ;
} void flip(int r,int c)
{
int i,j;
for(i=;i<r;i++)
{
if(map[i][c]==)
map[i][c]=;
else
map[i][c]=;
}
for(i=r+;i<=;i++)
{
if(map[i][c]==)
map[i][c]=;
else
map[i][c]=;
}
for(j=;j<c;j++)
{
if(map[r][j]==)
map[r][j]=;
else
map[r][j]=;
}
for(j=c+;j<=;j++)
{
if(map[r][j]==)
map[r][j]=;
else
map[r][j]=;
}
if(map[r][c]==)
map[r][c]=;
else
map[r][c]=;
return;
} void dfs(int r,int c,int deep)
{
int i,j;
if(deep==step)
{
flg=judge(map);
return;
}
if(flg== || r>)
{
return;
}
flip(r,c);
ak[n]=r,AK[n]=c;
n++;
if(c<)
dfs(r,c+,deep+);
else
dfs(r+,,deep+); if(flg!=)
{
flip(r,c);
n--;
if(c<)
dfs(r,c+,deep);
else
dfs(r+,,deep);
}
return;
} int main()
{
int i,j;
char x;
memset(map,,sizeof(map));
for(i=;i<=;i++)
{
for(j=;j<=;j++)
{
scanf("%c",&x);
if(x=='-')
map[i][j]=;
}
getchar();
}
for(step=;step<=;step++)
{
n=;
dfs(,,);
if(flg==)
break;
}
printf("%d\n",step);
for(i=;i<=n-;i++)
{
printf("%d %d\n",ak[i],AK[i]);
}
return ;
}

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

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

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

  2. POJ2965The Pilots Brothers' refrigerator(枚举+DFS)

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

  3. The Pilots Brothers' refrigerator(dfs)

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

  4. 枚举 POJ 2965 The Pilots Brothers' refrigerator

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

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

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

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

  7. POJ2965——The Pilots Brothers' refrigerator

    The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: following the stripy el ...

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

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

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

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

随机推荐

  1. 博创arm板编译内核makefile不兼容问题解决

    导致这种结果的是:Make工具对低版本内核的Makefile一些旧的规则兼容不好,我们只需修改对应的Makefile. 改1:: 原始的:          大概在 1503行 / %/: prepa ...

  2. wireshark抓包

    ip.addr==IP地址(192.168.1.100)&& http

  3. Eclipse安装插件支持jQuery智能提示

    Eclipse安装插件支持jQuery智能提示 最近工作中用到jQuery插件,需要安装eclipse插件才能支持jQuery智能提示,在网上搜索了一下,常用的有三个插件支持jQuery的智能提示:1 ...

  4. mysql字符串相关

    使用MySQL,我们很多时候都会出现需要截取字符串的情况,所以关于字符串的截取的方式有必要记录下去. MySQL截取字符串的函数有: left(str, length):从左边开始截取,length是 ...

  5. python编码:gbk编码与解码

    从RF输入的中文会进行unicode编码:u'\u6587\u4ef6\u5230\u8fbe\u6210\u529f' 从orc数据库查询到的中文会进行gbk编码得到ASCII:'\xce\xc4\ ...

  6. iOS使用静态变量

    之前看"Effective Objective-C 2.0", 第4条, 多用静态变量, 少用define. 正好我的项目有些东西是静态变量, 之前java我习惯起一个类, 里面全 ...

  7. zabbix agent 类型自带的key

    zabbix服务器端通过与zabbix agent通信来获取客户端服务器的数据,agent分为两个版本,在配置主机我们可以看到一个是agent,另一个是agent(active). agent:zab ...

  8. inupt textarea提示文字(点击消失,不输入恢复)及限制字数

    效果: input: textarea: 限100字 源码: input: <input name="textfield" type="text" max ...

  9. textarea输入框限制字数(JS)

    第一种: <textarea onkeyup="checkLen(this)"></textarea> <div>您还可以输入 <span ...

  10. yii2通过foreach循环遍历在一个用户组中取出id去另一表里查寻信息并且带着信息合并原数组信息---案例

    yii2通过foreach循环遍历在一个用户组中取出id去另一表里查寻信息并且带着信息合并元数组信息---案例 public function actionRandomLists(){ //查询到了所 ...