The Pilots Brothers' refrigerator
2965
| 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
#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的更多相关文章
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ2965The Pilots Brothers' refrigerator(枚举+DFS)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22057 ...
- The Pilots Brothers' refrigerator(dfs)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19718 ...
- 枚举 POJ 2965 The Pilots Brothers' refrigerator
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...
- 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 ...
- POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16868 ...
- POJ2965——The Pilots Brothers' refrigerator
The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: following the stripy el ...
- POJ 2965 The Pilots Brothers' refrigerator 位运算枚举
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 151 ...
- POJ 2965 The Pilots Brothers' refrigerator (DFS)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15136 ...
随机推荐
- 夺命雷公狗---Thinkphp----11之管理员的增删改查的完善
由于我们刚才的帐号还没通过任何的验证就可以直接进入数据库了,这当然不是不合理的交互逻辑,所以我们要修改下,让他变得3合理一些, 所以我们还是要按照套路来修改几处即可解决问题: 首先修改下添加的控制器: ...
- LDA-math-MCMC 和 Gibbs Sampling
http://cos.name/2013/01/lda-math-mcmc-and-gibbs-sampling/ 3.1 随机模拟 随机模拟(或者统计模拟)方法有一个很酷的别名是蒙特卡罗方法(Mon ...
- 让git忽略文件模式的改变
使用git的过程中发现,就算文件的内容没改变,只有文件的权限改变的话,git也会检测到文件被修改了. 解决方法是配置一下: git config --global core.filemode fals ...
- 《Focus On 3D Terrain Programming》中一段代码的注释二
取自<Focus On 3D Terrain Programming>中的一段: bool CTERRAIN::MakeTerrainFault( int iSize, int iIter ...
- RSYNC--数据迁移、备份
前言 一台Solaris主机要下线了,准备将数据迁移至一台AIX主机上,可是在Solaris主机上有一个文件系统有1200万个小文件,因为是跨平台的数据迁移,采用磁盘底层复制无法进行,采用数据备份恢复 ...
- vc获取特殊路径(SpecialFolder)
%SystemDrive% 操作系统所在的分区号.如 C: %SystemRoot% 操作系统根目录.如 C:\WINDOWS %windir% 操作系统根目录.如 C:\WINDOWS %ALLUS ...
- HTML5与移动端Web
概述 HTML5 提供了很多新的功能,主要有: 新的 HTML 元素,例如 section, nav, header, footer, article 等 用于绘画的 Canvas 元素 用于多媒体播 ...
- zabbix源码安装
Zabbix通过C/S模式采集数据,通过B/S模式在web端展示和配置. 被监控端:主机通过安装agent方式采集数据,网络设备通过SNMP方式采集数据 Server端:通过收集SNMP和agent发 ...
- flex datagrid 换行
<mx:DataGrid id="myGrid" width="100%" height="90%" headerStyleName= ...
- javascript,jquery代码规范
jquery代码规范 Coding Standards & Best Practices 中文翻译版:jquery编程的标准写法和最佳实践 javascript代码规范 JavaScript编 ...