poj-2965 The Pilots Brothers' refrigerator -- 枚举
2015-07-28 08:44
218 查看
Total Submissions: 20783 | Accepted: 8001 | Special Judge |
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; }
继续努力,加油啊 !!!
相关文章推荐
- 第三周第一天(【正则表达式的应用】【卖票问题】【同一个账号两人同时取钱】【生产消费问题】【join】【死锁问题】)
- 如此理解面向对象编程
- 极客头条---人人都是主编(上)
- 容器时代,难道这就是我们想要的未来?
- Calculation 2-欧拉函数的运用
- UVA 442 Matrix Chain Multiplication
- C++使用libcurl做HttpClient
- 安卓手机来电亮屏流程分析
- 计算机视觉目标检测的框架与过程(转)
- leetcode 240: Search a 2D Matrix II C++Version
- Javascript高级程序设计
- SqlServer 2008 express的自动备份实现
- 自我服务偏好
- SVN客户端(TortoiseSVN)保存密码自动登录后,如何切换使用其它帐户登录方法
- 网络通讯中的字节序转换及大端、小端
- 深度学习 CNTK使用笔记
- Sublime Text3 快捷键汇总及设置快捷键配置环境变量
- nginx proxy-pass简单的应用
- Objective-C 省市区 字典 封装
- KMP + 求最小循环节 --- POJ 2406 Power Strings