POJ:2695-The Pilots Brothers' refrigerator
题目链接:http://poj.org/problem?id=2965
The Pilots Brothers’ refrigerator
Time Limit: 1000MS Memory Limit: 65536K
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
题意就是给你一个4*4的图,要通过翻转将图全改为‘-’,并打印出翻转过程,每次翻转一个点,这个点所在的行和列也要同时翻转。
刚看到的时候就以为是POJ1753题的升级版 ,其实这也是一个思维题,要翻转一个点并且除了这个点外其他点不变,就只能将这个点所在的行列上所有的点都给翻转一下。然而一个点如果翻转偶数次就和没翻转的效果一样。这样在实现的时候就可以开一个4*4的int数组,每个是‘+’的点它所在的行列上的点全加一,最后将这个int数组上的所有的数全mod2,如果int数组中1的个数就是需要翻转的次数,1所在的点就是需要翻转的点。
然而自己在写这个题的时候用poj1753的思路写了个bfs超时了,看到网上都是用dfs过的好像没有bfs。
丑代码:
#include<stdio.h>
using namespace std;
const int maxn = 10;
char s[maxn][maxn];
int maps[maxn][maxn];
void deal(int x,int y)
{
int x2,y2;
maps[x][y]++;
//上下作业操作
x2 = x-1;
while(x2>=0)
{
maps[x2][y]++;
x2--;
}
y2 = y-1;
while(y2>=0)
{
maps[x][y2]++;
y2--;
}
x2 = x+1;
while(x2<4)
{
maps[x2][y]++;
x2++;
}
y2 = y+1;
while(y2<4)
{
maps[x][y2]++;
y2++;
}
}
void solve()
{
for(int i=0;i<4;i++)
scanf("%s",s[i]);
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if(s[i][j] == '+')
deal(i,j);
}
int sum = 0;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
maps[i][j] = maps[i][j]%2;
if(maps[i][j])
sum++;
}
printf("%d\n",sum);
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if(maps[i][j])
printf("%d %d\n",i+1,j+1);
}
return ;
}
int main()
{
solve();
}
POJ:2695-The Pilots Brothers' refrigerator的更多相关文章
- POJ 2695 The Pilots Brothers' refrigerator(神奇的规律)
转载请注明出处:http://blog.csdn.net/a1dark 分析:如果想要将一个“+”翻转成“-”,那么必然会把对应的行和列上的所有点翻转一次.由于一个点翻偶数次就相当于不翻转.所以我需要 ...
- 【POJ 2965】 The Pilots Brothers' refrigerator
[题目链接] http://poj.org/problem?id=2965 [算法] 位运算 [代码] #include <algorithm> #include <bitset&g ...
- The Pilots Brothers' refrigerator 分类: POJ 2015-06-15 19:34 12人阅读 评论(0) 收藏
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20304 ...
- 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
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...
- 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 暴力 难度:1
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16868 ...
- 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 ...
随机推荐
- (转)启动网卡报错(Failed to start LSB: Bring up/down networking )解决办法总结
启动网卡报错(Failed to start LSB: Bring up/down networking )解决办法总结 原文:http://blog.51cto.com/11863547/19059 ...
- Swagger 2.0 集成配置
传统的API文档编写存在以下几个痛点: 对API文档进行更新的时候,需要通知前端开发人员,导致文档更新交流不及时: API接口返回信息不明确 大公司中肯定会有专门文档服务器对接口文档进行更新. 缺乏在 ...
- C. Journey
C. Journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- vuex填坑记录
vuex是需要等待页面加载完成后才会更新的,如果页面点击刷新有用到vuex的地方,那么vuex会保持旧的数据,等刷新完成后vuex的数据才会重置,所以要在页面加载后再调用vuex的数据才是正确的,如果 ...
- P3290 寻找第K大数
描述 寻找第K大数 N个小朋友在一起做游戏.每个小朋友在自己的硬纸板上写一个数,然后同时举起来.接着,小y老师提一个问题,看哪个小朋友先抢答出来.问题是:在这N个数中,第K大的是哪个数?请你编程完成. ...
- dubbo服务降级(1)
1. 在 dubbo 管理控制台配置服务降级 上图的配置含义是:consumer 调用 com.zhang.HelloService 的方法时,直接返回 null,不发起远程调用. 实际操作是:在 z ...
- DHTMLX 使用汇总
1.dhtmlxGrid 底部总出现滚动条 ------------------------------------------ 发现使用DHTMLXGRID时 GRID 底边总有 滚动条 测试 ...
- (二)我的JavaScript系列:JavaScript面向对象旅程(下)
剪不断,理还乱,是离愁. 前面已经提到过新语言开发的两个步骤,分别是:一.定义基本的数据类型,完善结构化编程语言的设计:二.为函数类型绑定this的概念,好在对象的方法中可以引用到对象自身.下面是继续 ...
- Java之栈空间和堆空间
1.变量的命名 (1)由字母,数字和下划线构成,首字母以字母或下划线开头 (2)变量的命名遵循见名知义 (3)Java变量命名建议不用中文 (4)变量名首字母建议不用大写字母开头 (5)用驼峰命名法命 ...
- 2017.10.6 QBXT 模拟赛
题目链接 T1 Sort 一下与原数组比较 ,若有两个数或者没有数发生位置交换 ,则输出YES ,否则输出NO #include <algorithm> #include <ccty ...