The Pilots Brothers’ refrigerator
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 27917 Accepted: 10810 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

飞行员兄弟的冰箱
原题链接
时间限制: 1000MS 内存限制: 65536K
提交总数: 27917 接受: 10810 特别法官
描述

游戏“飞行员兄弟:跟随有条纹的大象”有玩家需要打开冰箱的任务。

冰箱门上有16个把手。每个把手可以处于以下两种状态之一:打开或关闭。冰箱仅在所有把手打开时才打开。把手表示为矩阵4х4。您可以在任何位置[i,j](1≤i,j≤4)更改句柄的状态。但是,这也会改变第i行所有句柄的状态和第j列所有句柄的状态。

其任务是确定打开冰箱所需的最少手柄开关次数。

输入

输入包含四行。四行中的每一行都包含四个描述适当句柄初始状态的字符。符号“+”表示手柄处于关闭状态,而符号“ - ”表示“打开”。至少有一个手柄最初是关闭的。

输出

输入的第一行包含N - 最小切换次数。其余的N行描述开关顺序。每行包含由一个或多个空格分隔的矩阵的行号和列号。如果有几个解决方案,你可以给他们中的任何一个。

示例输入

-+--
----
----
-+--

示例输出

6
1 1
1 3
1 4
4 1
4 3
4 4
资源

东北欧2004年,西部分区域

题解

这题和上次的POJ-1753 Flip Game一题差不多,大致想法就是矩阵转化成一个二进制数,那么 0 到 217−1217−12^{17}-1 之间,每个数字都是一种状态。说白了总共就只有这么点状态,所以刷 BFS 就可以了。

当然,也可以刷DFS,每个点最多会被选中一次(因为选中两次等于没选中),这样一来,我们可以把选中的点看作 +,没选中的看作 -,然后枚举这个矩阵,最多也是 2172172^{17} 次就可以了。

代码

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=(1<<17)+3;
int L[6],R[6],vis[maxn],lst[maxn],q[maxn],X[maxn],Y[maxn],til,hea;
int readch()
{char ch=getchar();while (ch!='+'&&ch!='-')ch=getchar();return (int)(ch=='+');
}
void dfs(int stp)
{if (lst[stp]<0) return;printf("%d %d\n",X[stp]+1,Y[stp]+1);dfs(lst[stp]);
}
int main()
{int sum=0;for (int i=0;i<4;i++)for (int j=0;j<4;j++) L[i]|=1<<(i<<2)+j,R[j]|=1<<(i<<2)+j,sum|=(1<<(i<<2)+j)*readch();lst[1]=-1;vis[sum]=1;q[til=1]=sum;while (til!=hea){int x=q[++hea];for (int i=0;i<4;i++)for (int j=0;j<4;j++){int y=x^L[i]^R[j]^1<<(i<<2)+j;if (vis[y]) continue;q[++til]=y;lst[til]=hea;X[til]=i;Y[til]=j;vis[y]=vis[x]+1;if (!y) {printf("%d\n",vis[x]);dfs(til);return 0;}}}return 0;
}

POJ-2965 The Pilots Brothers' refrigerator相关推荐

  1. POJ 2965.The Pilots Brothers‘ refrigerator

    POJ 2965.The Pilots Brothers' refrigerator Ideas 题意:给你4*4的矩阵.每个点有两种状态,+代表关,-代表开.每个点有一个操作就是该点所在行列所有状态 ...

  2. ACM POJ 2965 The Pilots Brothers' refrigerator

    http://poj.org/problem?id=2965 The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65 ...

  3. poj 2965 The Pilots Brothers' refrigerator

    http://poj.org/problem?id=2965 poj 1753扩展,dfs+枚举,不过加了一个路径. The Pilots Brothers' refrigerator Time Li ...

  4. Poj 2965 The Pilots Brothers‘ refrigerator

    The game "The Pilots Brothers: following the stripy elephant" has a quest where a player n ...

  5. POJ - 2965 The Pilots Brothers' refrigerator(bfs+路径输出/思维+位运算)

    题目链接:点击查看 题目大意:给出一个4*4的矩阵,每个点都代表一个开关,'+'代表关,'-'代表开,每次操作可以任意改变一个开关(x,y)的状态,但代价是x行和y列的开关都要一起改变状态,题目要求将 ...

  6. POJ 2965 The Pilots Brothers' refrigerator

    这个题是一个枚举题. 用的是八皇后算法. 具体操作不说了. 下面是代码: #include <stdio.h> struct node {int x,y; }de[200],dr[200] ...

  7. poj 2965 The Pilots Brothers#39; refrigerator

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

  8. B - The Pilots Brothers' refrigerator

    B - The Pilots Brothers' refrigerator 文章目录 B - The Pilots Brothers' refrigerator 题目描述: Input: Output ...

  9. POJ2965 The Pilots Brothers‘ refrigerator

    POJ2965 The Pilots Brothers' refrigerator 题干 Description Input Output Sample Input Sample Output 题意 ...

  10. The Pilots Brothers‘ refrigerator(思维)

    题面:The Pilots Brothers'refrigerator 题目大意 "飞行员兄弟"这个游戏,需要玩家打开一个有着16把手的冰箱. 每个把手有且只有两种状态:打开(−- ...

最新文章

  1. 京东千万并发 API 网关实践之路!
  2. vue文件快速生成模板代码
  3. 【数学与算法】牛顿法的两种应用:求根和最优化
  4. python学习之列表的定义以及增删改查
  5. 从SOURCE_BUFFER单元开始存放了20个字母A, 编程将这20个字母A的字符串传送到DEST_BUFFER开始的单元中.
  6. 系统性能调优(5)----Java循环与字符串代码优化
  7. 阿里云IoT Studio升级版新增解决方案引擎 大幅提升方案交付效率
  8. android java 实体类 object变量 保存_Java中的实体类--Serializable接口、transient 关键字...
  9. 五、QPushButton按钮和QLineEdit控件操作
  10. idea里边创建类的时候和方法自动生成注释
  11. pytreebank︱情感分析可视化——情感结构树
  12. javascript写字技巧_关于 js的一些书写习惯 实用风格 小技巧
  13. 创客匠人知识付费SaaS系统功能介绍
  14. 解决360N4S骁龙版在国外使用碰到的问题,附详细root教程
  15. Linux下图片 jpg、png、gif 与 eps 格式的相互转换
  16. rsa签名算法c语言,数字签名算法rsa
  17. java中utp_5类UTP比3类UTP扭矩_______。
  18. Hessian矩阵\海塞矩阵\海森矩阵
  19. hive 按行打印出截止日期和开始日期之间的日期
  20. 夜班媒体人援助项目在京启动,陈于冰说:“一直以来.....

热门文章

  1. 网络安全学习--操作系统安全防护
  2. 三国群英传霸业之王服务器维护,20200901维护公告
  3. 星际争霸pymarl的环境搭建(pymarl+smac)
  4. 记一次面试(被骗)经历
  5. 各种本地存储对比 cookie,localStorage,sessionStorage,indexDB以及他们和vuex的区别
  6. C#中ref和out关键字的应用以及区别。
  7. 写文三年了,给大家说点儿心里话
  8. 兼职做淘宝客好吗?淘客APP怎么盈利?
  9. Arduino直流电动机控制
  10. 自然语言处理(NLP)任务中常用的分词工具及底层算法支持