POJ2965----The Pilots Brothers' refrigerator
来源:互联网 发布:linux命令源代码 编辑:程序博客网 时间:2024/05/21 03:25
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
61 11 31 44 14 34 4
#include<iostream>using namespace std;int main(){//input_char存储输入字符,input_count对要翻转的把手计数(要想改变一个把手的状态,可以把对应的行和列的把手都翻转一边,最后则只有该把手的状态改变)。char input_char[4][4];int i,j;char input_count[4][4];for(i=0;i<4;i++)for(j=0;j<4;j++)input_count[i][j]=0;for(i=0;i<4;i++)for(j=0;j<4;j++){cin>>input_char[i][j];if(input_char[i][j]=='+'){for(int k=0;k<4;k++){input_count[i][k] +=1;input_count[k][j] +=1;}//该把手重复计数了+1input_count[i][j] -=1;}}int count = 0;int output[16][2];for(i=0;i<4;i++)for(j=0;j<4;j++){//翻转偶数次等于不翻转,count记录需要翻转的把手,output存储坐标if(input_count[i][j]%2==1){output[count][0] = i+1;output[count][1] = j+1;count++;}}cout<<count<<endl;for(i=0;i<count;i++){cout<<output[i][0]<<" "<<output[i][1]<<endl;}}
- POJ2965 The Pilots Brothers' refrigerator
- POJ2965----The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- POJ2965-The Pilots Brothers' refrigerator
- poj2965--The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- The Pilots Brothers' refrigerator Poj2965
- POJ2965-The Pilots Brothers' refrigerator
- POJ2965-The Pilots Brothers' refrigerator
- poj2965-The Pilots Brothers' refrigerator
- poj2965-The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- POJ2965-The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers\' refrigerator
- poj2965 The Pilots Brothers' refrigerator
- POJ2965 The Pilots Brothers' refrigerator 枚举
- poj2965——The Pilots Brothers' refrigerator
- 百钱百鸡:公鸡5元一只,母鸡3元一只,小鸡1元3只,100元要买100只鸡,共有几种情况
- 百钱百鸡
- linux系统网卡升级 oracle rac重启 及 ogg 重启
- linux模块管理命令
- 百钱百鸡 转载
- POJ2965----The Pilots Brothers' refrigerator
- <cctype> C字符函数
- structs2初学之与hibernate结合之增删改查
- 九九乘法表 c#
- Visual Studio中的快捷键
- JS正则表单邮箱验证实例
- Eclipse Java代码注释模板的设置
- linux下的原始套接字
- 新版有道云笔记3.1版本客户端无法登陆 解决方法