题干:

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

题目大意:

一个冰箱上有4*4共16个开关,改变任意一个开关的状态(即开变成关,关变成开)时,此开关的同一行、同一列所有的开关也会同时改变状态。要想打开冰箱,要所有开关全部打开才行。‘+’代表关闭,‘-’代表打开。

解题报告:

直接2^16暴力枚举,注意状态的更新,不要全部更新一遍,而是只记录行和列的更新即可。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
const int up = 1<<16;
char s[5][5];
int R[5],C[5],ok[5][5],ansk=1e8,ans;
bool tt[5][5];
int main()
{
//  printf("%lld\n",(1<<15)+(1<<14)+(1<<12)+(1<<0)+(1<<2)+(1<<3));for(int i = 0; i<=3; i++) {scanf("%s",s[i]);}for(int i = 0; i<=3; i++) {for(int j = 0; j<=3; j++) {if(s[i][j] == '-') ok[i][j]=1;else ok[i][j]=0;}}for(int bit = 0; bit<up; bit++) {
//      if(bit == 53261) {
//          printf("ok\n");
//      }int k=0,flag = 1,zs=0;for(int i = 0; i<=3; i++) R[i]=C[i]=0;memset(tt,0,sizeof tt);for(int x=bit;x;x>>=1,k++) {if(x%2 == 1) {zs++;int row = k/4,col = k%4;R[row]++,C[col]++;tt[row][col]=1;}}for(int i = 0; i<=3; i++) {for(int j = 0; j<=3; j++) {if((R[i]+C[j]+ok[i][j]+tt[i][j])%2 == 0) {flag = 0;break;}}if(flag == 0) break;}if(flag == 1) {if(zs < ansk) {ansk=zs;ans=bit;}}}printf("%d\n",ansk);int k=0;for(int x = ans;x;x>>=1) {if(x%2 == 1) {int row = k/4,col=k%4; printf("%d %d\n",row+1,col+1);}k++;}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. The Pilots Brothers' refrigerator DFS+枚举

    Description The game "The Pilots Brothers: following the stripy elephant" has a quest wher ...

  9. The Pilots Brothers‘ refrigerator(思维)

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

  10. POJ-2965 The Pilots Brothers' refrigerator

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

最新文章

  1. Ubuntu实时监测系统性能工具
  2. VMWare虚拟机与主机共享文件夹(如何安装VMWare tools)windows与windows共享
  3. Eclipse编写Java程序
  4. 性能高1倍,价格低3/4!数据库实时同步新选择!
  5. 点赞!一个程序员花了14小时寻找问题疫苗的流向
  6. canvas 实现图片局部模糊_Canvas 在高清屏下绘制图片变模糊的解决方法
  7. boot idea无法识别spring_IDEA 的这款插件真是逆天了,代码那都不是事
  8. Ubuntu下解压缩文件
  9. 如何吧本地仓库提交到github_如何将本地代码提交到github远程仓库(第一次,建立连接并且提交)...
  10. php 抽象类,接口,抽象方法,静态方法
  11. IT行业必须知道的基础知识
  12. matlab dcm文件,CT的原始图像.dcm文件的读取
  13. matlab 图例 显示几个,matlab图例拆分成两个多个分别显示
  14. 浅析 微信公共平台消息 开发原理
  15. 关于C语言中的绝对值函数
  16. Pandas入门超详细教程,看了超简单
  17. PADS 在 Windows 11 下闪退解决方法
  18. php 获取中英文字符的数量;和JS获取中英文字符的数量
  19. 轻松识别文字,这款Python OCR库支持超过80种语言
  20. PPT怎么转换成PDF?有哪些转换方法?

热门文章

  1. strlwr,strupr函数
  2. [剑指offer]面试题第[50]题[JAVA][第一个只出现一次的字符][哈希表][HashMap]
  3. [Leedcode][JAVA][第199题][二叉树的右视图][BFS][DFS][前中后序遍历]
  4. 如图所示是一种轧钢计算机控制系统,高速线材厂轧钢工艺培训(活套)
  5. python打开文件要wordcloud吗,使用python创建wordcloud
  6. 180C. Letter
  7. B. Trouble Sort Codeforces Round #648 (Div. 2)
  8. Java并发编程实战 代码bug,Java并发编程实战(1)- 并发程序的bug源头
  9. hadoop 计算几点 主节点_01-Hadoop的介绍
  10. echarts 生成 迁徙图_echarts3 迁徙图 迁入迁出(示例代码)