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 openhe the refrigerator.

在poj 1753的基础上增加了路径保存,递归输出即可。

#include<iostream>
#include<limits.h>
#include<string.h>
using namespace std;
int sta=0;
bool mi[65536];
short int st[65536];
int ori[65536];
bool is_end(int status,int step){if (status==0) {cout<<step<<endl;return(true);}else return(false);
}
int work2(int n,int status){int tt=1<<n;return(status^tt);
}
int work(int n,int status){int temp=status;int ii=n/4,jj=n%4;for (int i=0;i<4;i++)temp=work2(i*4+jj,temp);for (int i=0;i<4;i++)temp=work2(ii*4+i,temp);temp=work2(n,temp);return(temp);
}
void bfs(int status){int head=0,tail=0,temp,step,temp_status;int que1[65536],que2[65536];bool t1=true;que1[0]=status;que2[0]=0;while (head<=tail){temp=que1[head];step=que2[head];head++;for (int i=15;i>=0;i--){temp_status=work(i,temp);       if (!mi[temp_status]){mi[temp_status]=true;st[temp_status]=i;ori[temp_status]=temp;tail++;que1[tail]=temp_status;que2[tail]=step+1;}if (is_end(temp_status,step+1)) {t1=false;break;}}if (!t1) break; }if (t1) cout<<"Impossible"<<endl;
}
void print(int status){if (status!=sta){print(ori[status]);cout<<(4-st[status]/4)<<' '<<(4-st[status]%4)<<endl;}
}
int main(){char ch;memset(mi,sizeof(mi),false);for(int i=0;i<16;i++){cin>>ch;sta=sta<<1;sta+=(ch=='+');}mi[sta]=true;bfs(sta);print(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(bfs+路径输出/思维+位运算)

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

  5. POJ 2965 The Pilots Brothers' refrigerator

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

  6. poj 2965 The Pilots Brothers#39; refrigerator

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

  7. B - The Pilots Brothers' refrigerator

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

  8. POJ2965 The Pilots Brothers‘ refrigerator

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

  9. The Pilots Brothers‘ refrigerator(思维)

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

最新文章

  1. matlab 图像处理函数(第八章) 图像的增强
  2. 安装MYSQL最低的RAM_安装MySQL后,需要调整的10个性能配置项
  3. 2017-2018-1 Java演绎法 第三周 作业
  4. 题目:16版.雇员的工作职责(一)
  5. 华为鸿蒙HarmonyOS,HDC2020,华为鸿蒙HarmonyOS会带来哪些不一样的体验?
  6. UVA 10564 - Paths through the Hourglass (dp)
  7. php 中文名称排序 源码,四种排序算法PHP实现类
  8. fcntl实现对文件加锁功能
  9. 《软件质量保证与测试》读书笔记(一)
  10. eas bos 常用代码
  11. cc9.3 indesign_Adobe InDesign CC2019
  12. 联想小新 Pro 16 2023 评测
  13. java获取微信绑定的手机号码
  14. python 开启子进程的两种方式
  15. Excel的使用——比对俩列内容的相同与不同,并突出显示
  16. Agile Office 365 免积分下载
  17. 电脑中的"倚天剑+屠龙刀"【推荐】
  18. 图像超分算法SRLUT: Practical Single-Image Super-Resolution Using Look-Up Table图像超分辨率重建
  19. SDUT_人活着系列
  20. 什么是SOA(面向服务的架构)?

热门文章

  1. Aura Component Cope Snippets
  2. JAVA散列表个人通讯录_散列表实现简易通讯录
  3. 微商是如何推广的呢?
  4. 【MOOC】华中科技大学计算机组成原理慕课答案-第六章-中央处理器(一)
  5. FBEC金陀螺奖·侧记 | 七载相伴,致敬创业路上的每一位勇毅前行者!
  6. java windows静音_java – 如何创建静音选项
  7. 湖北大学计算机系2020录取分数线,2020湖北大学本科投档录取分数线
  8. [AcWing] 2058. 笨拙的手指(C++实现)秦九韶算法
  9. linux安装包安装方法
  10. 云服务器 架设传奇_阿里云虚拟主机,ECS服务器,轻量应用服务器有什么区别,该如何选择?...