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 ...
随机推荐
- scan design flow(二)
在scan stitch之后,scan synthesis就已经完成, Scan extraction主要用来从scan design中extracing所有的instance,来保证scan cha ...
- PAT乙级 1017. A除以B (20)
1017. A除以B (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求计算A/B,其中A是不超过 ...
- imread函数、namedWindow函数、imshow函数、imwrite函数
1.imread函数 首先,我们看imread函数,可以在OpenCV官方文档中查到其原型如下: Mat imread(const string& filename, int flags=1 ...
- Openstack的配额共功能的使用
在一个云系统中,一个项目不能无限制的使用资源,必须对项目进行配额管理,在openstack中主要的命令是nova quota-update, 但是可能会提示的错误: DEBUG (shell:740) ...
- JavaSPI机制学习笔记
最近在阅读框架源代码时,常常看到 SPI 的子包, 忍不住查了下: Service Provider Interface : 服务提供接口. JavaSPI 实际上是“基于接口的编程+策略模式+配置文 ...
- Backup: Date and Time in Perl6
时间 Date #Operators ==, <, <= , >, >=, !=, eq, lt, le # Methods $date = Date.new(YEAR, MO ...
- arm驱动linux异步通知与异步IO【转】
转自:http://blog.csdn.net/chinazhangzhong123/article/details/51638793 <[ arm驱动] linux异步通知与 异步IO> ...
- https笔记
TCP提供了可靠的,面向连接的字节流服务. 1)应用数据分割成TCP认为适合发送的数据块,通过MSS(最大数据包长度)来控制. 2)重传机制 3)对首部和数据进行校验 4)TCP对收到的数据进行排序, ...
- Hibernate,Session清理缓存时间点
当应用程序调用org.hibernate.Transaction的commit()的时候,commit()方法先清理缓存,然后再向数据库提交事务. 当应用程序显示调用Session.flush()方法 ...
- 严重: IOException while loading persisted sessions: java.io.EOFException
tomcat在启动时出现如下异常问题: 严重: IOException while loading persisted sessions: java.io.EOFException 严重: Excep ...