POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 16868 | Accepted: 6393 | 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 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
6
1 1
1 3
1 4
4 1
4 3
4 4
本来用位运算+bfs,但是tle,再进行剪枝太麻烦,结果看到如此简单的算法,果然应该三思而后行。
//poj2965
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int mem[4][4];//用于储存翻转次数,如果是偶数,则相当于没有翻转
int main(){
char ch;
for(int x=0;x<4;x++){//按sample的顺序,x代表纵行,y是横列
for(int y=0;y<=4;y++){
ch=getchar();
if(ch=='+'){//如果想只翻转这一个点而不改变其他,需要将该行该列以及该点本身各自翻转一次.,有点像魔方
for(int i=0;i<4;i++){//翻转该列
mem[i][y]++;//翻转一次相当于自增1
}
for(int j=0;j<4;j++){//翻转该行
mem[x][j]++;
}
mem[x][y]++;
}
}
}
int ans=0;
string str;
for(int x=0;x<4;x++){
for(int y=0;y<4;y++){
int index=mem[x][y];
if((index/2)*2!=index){
ans++;//先统计需翻转的个数
str+=('1'+x);//避免再统计一次,使用了c++字符串容器
str+=32;//空格
str+='1'+y;
str+='\n';
}
}
}
printf("%d\n",ans);
cout<<str;
return 0;
}
POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1的更多相关文章
- 枚举 POJ 2965 The Pilots Brothers' refrigerator
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- poj 2965 The Pilots Brothers' refrigerator (dfs)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17450 ...
- POJ 2965 The Pilots Brothers' refrigerator 位运算枚举
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 151 ...
- POJ 2965 The Pilots Brothers' refrigerator (DFS)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15136 ...
- POJ - 2965 The Pilots Brothers' refrigerator(压位+bfs)
The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to op ...
- POJ 2965 The Pilots Brothers' refrigerator (暴力枚举)
https://vjudge.net/problem/POJ-2965 与poj-1753相似,只不过这个要记录路径.poj-1753:https://www.cnblogs.com/fht-lito ...
- POJ 2965 The Pilots Brothers' refrigerator【枚举+dfs】
题目:http://poj.org/problem?id=2965 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#pro ...
- poj 2965 The Pilots Brothers' refrigerator枚举(bfs+位运算)
//题目:http://poj.org/problem?id=2965//题意:电冰箱有16个把手,每个把手两种状态(开‘-’或关‘+’),只有在所有把手都打开时,门才开,输入数据是个4*4的矩阵,因 ...
随机推荐
- Linux设备模型(总线、设备、驱动程序和类)
Linux设备驱动程序学习(13) -Linux设备模型(总线.设备.驱动程序和类)[转] 文章的例子和实验使用<LDD3>所配的lddbus模块(稍作修改). 提示:在学习这部分内容是一 ...
- uiZjs入门
具体基础的用法,可先看下这个文件做下了解,地址:http://files.cnblogs.com/dachuang/uizjs.rar 请先看完上面的文件,不然下面的可能看不懂,当然你要是之前了解过的 ...
- python把元组组合成字典
list=((","16g"), (","32g"), (","red"), (","bl ...
- Oracle中dual表的用途介绍
导读]dual是一个虚拟表,用来构成select的语法规则,oracle保证dual里面永远只有一条记录.我们可以用它来做很多事情. dual是一个虚拟表,用来构成select的语法规则,or ...
- JavaScript设计模式-单例模式、模块模式(转载 学习中。。。。)
(转载地址:http://technicolor.iteye.com/blog/1409656) 之前在<JavaScript小特性-面向对象>里面介绍过JavaScript面向对象的特性 ...
- eclipse右击打war包class没打上去的问题
今天,遇到个诡异的问题,一个工程eclipse打war包class就是打不上,别的能打上,发现这样选择tomcat,打包成功,谨此备注.
- javascript算术运算符详解
算术运算符 +.-.*./.%.++.-- ++.--分为前缀形式和后缀形式 前缀形式先加减1在执行 后缀形式先执行再加减1 注意 +号用来连接两个字符串 只要+连接的操作数中有一个是字符串型,JS就 ...
- ajax views
https://julian.pustkuchen.com/en/drupal-7-api-trigger-views-ajax-refresh-javascript-or-php-using-aja ...
- 教你开启红米的USB大容量存储选项,全网首发哦
教你开启红米的USB大容量存储选项,全网首发哦 http://bbs.7to.cn/thread-10732-1-1.html 发表于 2014-4-29 110643 红米note入手也有两天了.各 ...
- 一个比较全面的java随机数据生成工具包
最近,由于一个项目的原因需要使用一些随机数据做测试,于是写了一个随机数据生成工具,ExtraRanom.可以看成是Java官方Random类的扩展,主要用于主要用于测试程序.生成密码.设计抽奖程序等情 ...