poj 2965 The Pilots Brothers' refrigerator
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 18040 | Accepted: 6841 | 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 rowi 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
与这个点击打开雷同,可先看这题。
AC代码例如以下:
#include<iostream>
#include<cstdio>
using namespace std; int n,a[5][5];
char b[5][5];
int h[17],z[17],H[17],Z[17],minn; int PD()
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(a[i][j]!=0)
return 0;
return 1;
} void dfs(int x,int y)
{
int i;
for(i=0;i<4;i++)
a[x][i]=!a[x][i];
for(i=0;i<4;i++)
a[i][y]=!a[i][y];
a[x][y]=!a[x][y];
} void work(int cur,int step)
{
int i;
if(cur==16)
{
if(PD()&&step<minn)
{
minn=step;
for(i=0;i<minn;i++)
{
H[i]=h[i];Z[i]=z[i];
}
}
}
else{
work(cur+1,step);
dfs(cur/4,cur%4);
h[step]=cur/4;z[step]=cur%4;
work(cur+1,step+1);
dfs(cur/4,cur%4);
} } int main()
{
int i,j;
for(i=0;i<4;i++)
cin>>b[i];
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(b[i][j]=='+')
a[i][j]=1;
else a[i][j]=0;
minn=17;
work(0,0);
cout<<minn<<endl;
for(i=0;i<minn;i++)
cout<<H[i]+1<<" "<<Z[i]+1<<endl;
return 0;
}
poj 2965 The Pilots Brothers' refrigerator的更多相关文章
- 枚举 POJ 2965 The Pilots Brothers' refrigerator
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- poj 2965 The Pilots Brothers' refrigerator (dfs)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17450 ...
- POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16868 ...
- 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 ...
- POJ - 2965 The Pilots Brothers' refrigerator(压位+bfs)
The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to op ...
- poj 2965 The Pilots Brothers' refrigerator枚举(bfs+位运算)
//题目:http://poj.org/problem?id=2965//题意:电冰箱有16个把手,每个把手两种状态(开‘-’或关‘+’),只有在所有把手都打开时,门才开,输入数据是个4*4的矩阵,因 ...
- POJ 2965 The Pilots Brothers' refrigerator (枚举+BFS+位压缩运算)
http://poj.org/problem?id=2965 题意: 一个4*4的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全 ...
- POJ 2965 The Pilots Brothers' refrigerator【枚举+dfs】
题目:http://poj.org/problem?id=2965 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#pro ...
随机推荐
- 【Codeforces Round #451 (Div. 2) C】Phone Numbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用map<string,vector > dic;模拟就好. 后缀.翻转一下就变成前缀了. 两重循环剔除这种情况不输出就 ...
- ActiveMQ学习总结(6)——ActiveMQ集成Spring和Log4j实现异步日志
我的团队和我正在创建一个由一组RESTful JSON服务组成的服务平台,该平台中的每个服务在平台中的作用就是分别提供一些独特的功能和/或数据.由于平台中产生的日志四散各处,所以我们想,要是能将这些日 ...
- 背景剪除和OpenCV中的实现
转载请注明出处! ! ! http://blog.csdn.net/zhonghuan1992 背景剪除和OpenCV中的实现 背景与前景都是相对的概念.以快速公路为例:有时我们对快速公路上来来往往的 ...
- zico源代码分析(二) 数据读取和解析部分
第一部分:分析篇 首先,看一下zico的页面,左侧是hostname panel,右侧是该主机对应的traces panel. 点击左侧zorka主机名,右侧panel会更新信息,在火狐浏览器中使用f ...
- cv2.putText 文字换行('\n')无法解析换行
OpenCV putText() new line character cv2.putText 在向图像中添加文本信息时,如果在待添加的文本中含有换行转义符,一般它是无法正确处理的: cv2.putT ...
- 2.Spring Boot 入门
转自:https://blog.csdn.net/catoop/article/details/50501664
- 6.CPP风格数组
//数组初始化 1 #include <iostream> using namespace std; void main() { //C int a[5] = { 1,2,3,4,5 }; ...
- 1.16 Python基础知识 - 装饰器初识
Python中的装饰器就是函数,作用就是包装其他函数,为他们起到修饰作用.在不修改源代码的情况下,为这些函数额外添加一些功能,像日志记录,性能测试等.一个函数可以使用多个装饰器,产生的结果与装饰器的位 ...
- JS里面的indexOf()函数
stringObject.indexOf(searchvalue,formindex); searchvalue在字符串首次出现的位置,位置是从0开始算的.
- subline Text3 安装及汉化
因为自己的subline 有问题 所以决心重新改一下了. 三步: http://www.sublimetext.com/3 官网下载subline3 https://www.imjeff. ...