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. android studio1.0 for Mac环境搭建与demo运行(手动下载gradle,科学上google) 转载

    http://blog.csdn.net/allenffl/article/details/41957907 官网下载 http://developer.android.com/sdk/install ...

  2. word - 如何让 图片任意移动

    选中图片, 设置图片的自动换行  为四周环绕型

  3. 在ASP.NET非MVC环境中(WebForm中)构造MVC的URL参数

    目前项目中有个需求,需要在WebForm中去构造MVC的URL信息,这里写了一个帮助类可以在ASP.NET非MVC环境中(WebForm中)构造MVC的URL信息,主要就是借助当前Http上下文去构造 ...

  4. 关于UIView(转)

    曾经有人这么说过,在iphone里你看到的,摸到的,都是UIView,所以UIView在iphone开发里具有非常重要的作用.那么UIView我们到底知道多少呢.请看看下面的问题, 如果这些你都知道, ...

  5. Objective-C代码的文件扩展名与数据类型

    Objective-C数据类型可以分为:基本数据类型.对象类型和id类型. 基本数据类型有:int.float.double和char类型. 对象类型就是类或协议所声明的指针类型,例如:SAutore ...

  6. linux 文件删除原理

    文件删除: i_link 文件的硬连接数 i_count 引用计数(有一个程序使用i_count加1) 文件删除的条件: i_link=0 and i_count=0 被进程占用的文件可以删除

  7. mysql开启远程访问

    1.MySql-Server 出于安全方面考虑只允许本机(localhost, 127.0.0.1)来连接访问. 这对于 Web-Server 与 MySql-Server 都在同一台服务器上的网站架 ...

  8. scala的apply方法

    package com.test.scala.test /** * apply 方法 */ object ApplyTest { def main(args: Array[String]): Unit ...

  9. Xcode 项目配置学习

    Xcode有四种build for 分别是: build for Running build for Testing build for Profiling build for Archiving R ...

  10. struts2-json-plugin插件实现异步通信

    用例需要依赖的jar: struts2-core.jar struts2-convention-plugin.jar,非必须, struts2-json-plugin.jar org.codehaus ...