B - The Pilots Brothers' refrigerator
B - The Pilots Brothers’ refrigerator
文章目录
- B - The Pilots Brothers' refrigerator
- 题目描述:
- Input:
- Output:
- Sample Input:
- 题目大意:
- 思路分析:
- Sample Input:
- Sample Output:
- 代码块:
题目描述:
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:
题目大意:
就是有一个特别大的冰箱,有16个把手,每个把手有2种状态,+与-,如果全为-的时候,就可以打开冰箱。4v4中任何一个地方,改变一个地方,就会改变当前位置与所在到行与列的状态。输出最少次数打开冰箱,以及路径。
思路分析:
这道题和flip game 的思路差不多,只是多了一个数组记录状态就行了,也是通过一个一个去搜,就行了,可以用BFS找出最短路径去写,也可以用DFS去压栈,在输出即可,不过自己还是要发一下牢骚,这道题 因为错将==写成=导致不知道哪里出问题,卡了整整3个小时,心态炸了。
Sample Input:
Sample Output:
代码块:
#include<stdio.h>char c1[4][4];//把手状态int x2[1000][16];//记录路径x轴int y2[1000][16];//记录路径y轴int min=22,n1=0,n2;//min只要大于16就行了,随便设。void lemone3(int x,int y,int num);//num记录步数int len()//判断是否全为'-'号{int b,c;for(b=0;b<4;b++){for(c=0;c<4;c++){if(c1[b][c]=='+'){return 0;}}}return 1;}void Lemonscanf()//记录冰箱把手状态{int a,b;for(b=0;b<4;b++){gets(c1[b]);} }void LemonDFS(int x,int y,int num)//深搜开始,num记录步数{int c,x1,y1;if(x>=4)//如果x>=4,说明已经翻转完了{if(len()){if(num<min)//比较步数{min=num;for(c=0;c<min;c++)//这一步类似走迷宫,上一次//步数的路径复制给下一次步数的路径。{y2[c][0]=x2[c][0];y2[c][1]=x2[c][1];}}}return;}//x1=x+(y+1)/4;y1=(y+1)%4;//这2步主要是类似在4V4棋盘中一个一个的翻。lemone3(x,y,num);x2[num][0]=x;//记录路径x轴x2[num][1]=y;//记录路径y轴LemonDFS(x1,y1,num+1);// 这一步是退到上一步,回到上一个节点。lemone3(x,y,num);LemonDFS(x1,y1,num);}void lemone3(int x,int y,int num)//改变状态开始{int b,c;if(x>=4){return;}for(b=0;b<4;b++){if(c1[b][y]=='-'){c1[b][y]='+';}else{c1[b][y]='-';}}for(b=0;b<4;b++){if(b==y)continue;if(c1[x][b]=='-'){c1[x][b]='+';}else{c1[x][b]='-';}}}void Lemonprintf()//输出步数与路径{int b;printf("%d\n",min);for(b=0;b<min;b++){printf("%d %d\n",y2[b][0]+1,y2[b][1]+1);}}int main(){Lemonscanf();//记录冰箱状态LemonDFS(0,0,0);//开始搜索Lemonprintf();//输出最少步数与路径}
B - The Pilots Brothers' refrigerator相关推荐
- POJ 2965.The Pilots Brothers‘ refrigerator
POJ 2965.The Pilots Brothers' refrigerator Ideas 题意:给你4*4的矩阵.每个点有两种状态,+代表关,-代表开.每个点有一个操作就是该点所在行列所有状态 ...
- poj 2965 The Pilots Brothers' refrigerator
http://poj.org/problem?id=2965 poj 1753扩展,dfs+枚举,不过加了一个路径. The Pilots Brothers' refrigerator Time Li ...
- ACM POJ 2965 The Pilots Brothers' refrigerator
http://poj.org/problem?id=2965 The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65 ...
- POJ2965 The Pilots Brothers‘ refrigerator
POJ2965 The Pilots Brothers' refrigerator 题干 Description Input Output Sample Input Sample Output 题意 ...
- The Pilots Brothers‘ refrigerator(思维)
题面:The Pilots Brothers'refrigerator 题目大意 "飞行员兄弟"这个游戏,需要玩家打开一个有着16把手的冰箱. 每个把手有且只有两种状态:打开(−- ...
- POJ-2965 The Pilots Brothers' refrigerator
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27917 A ...
- The Pilots Brothers' refrigerator - poj 2965
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20325 Accepted: 7830 Special Judge ...
- 【POJ - 2965】The Pilots Brothers' refrigerator(暴力枚举,思维)
题干: The game "The Pilots Brothers: following the stripy elephant" has a quest where a play ...
- The Pilots Brothers‘ Refrigerator(高效贪心)
题目描述 The game "The Pilots Brothers: following the stripy elephant" has a quest where a pla ...
最新文章
- 利用 Git OpenSSH 查看/生成 本机 ssh 公钥
- AtCoder Regular Contest 063 E - Integers on a Tree 构造 + 二分图染色
- WPF快速入门系列(2)——深入解析依赖属性
- Javacript和AngularJS中的Promises
- android 如何 root权限获取,如何获取android手机root权限获取
- 中国石化:五年要建充换电站5000座
- 《Look at Boundary: A Boundary-Aware Face Alignment Algorithm》代码调试
- WinForm皮肤控件(SkinEngine)
- linux客户端掉线重连,SSH自动断开后重连的解决方案
- extjs的EditorGridPanel中的ComboBox列中显示值的问题
- nrf52840 spi 32MHz配置
- 玩客云宝塔面板安装到外接硬盘
- 开发者如何了解技术前沿? 再也不用看微信公众号的软文了!
- CTF密码学总结(一)
- 计算机在材料科学与工程中的应用课后答案,材料科学与工程导论课后习题答案...
- vue中使用echarts中国地图
- 贵阳副市长刚写了一本区块链的书,趁热乎推荐给你!
- 计算机主机显卡在哪里,苹果台式电脑显卡位置在哪里
- java soa是什么_如何通俗易懂地解释什么是SOA?
- png jpg android,PNG vs JPG,用于在Android应用程序中显示图片(而非图标)