本文主要是介绍poj-2965 The Pilots Brothers' refrigerator -- 枚举,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Total Submissions: 20783 | Accepted: 8001 | 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 rowi 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
感觉和1753题目差不多,但是还有些差别,看不懂题目意思,英语也是很渣啊,看到别人的代码,才明白怎么做,唉,先去模仿吧,边看边想,
#include<stdio.h>
#include<string.h>
#include<stdlib.h>char ls[4][4];
bool map[4][4];
void change(int a,int b)
{map[a][b] = !map[a][b];
}
int main()
{int i, j;for(i = 0; i < 4; i++){scanf("%s",ls[i]);}for(i = 0; i < 4; i++){for(j = 0; j < 4; j++){if(ls[i][j] == '+'){for(int k = 0; k < 4; k++){change(i,k);}for(int k = 0; k < 4; k++){change(k,j);}change(i,j);}}}int c = 0;for(i = 0; i < 4; i++){for(j = 0; j < 4; j++){if(map[i][j] == true)c++;}}printf("%d\n",c);for(i = 0; i < 4; i++){for(j = 0; j < 4; j++){if(map[i][j] == true)printf("%d %d\n",i+1,j+1);}}return 0;
}
继续努力,加油啊 !!!
这篇关于poj-2965 The Pilots Brothers' refrigerator -- 枚举的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!