题目链接: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的更多相关文章

  1. POJ 2695 The Pilots Brothers' refrigerator(神奇的规律)

    转载请注明出处:http://blog.csdn.net/a1dark 分析:如果想要将一个“+”翻转成“-”,那么必然会把对应的行和列上的所有点翻转一次.由于一个点翻偶数次就相当于不翻转.所以我需要 ...

  2. 【POJ 2965】 The Pilots Brothers' refrigerator

    [题目链接] http://poj.org/problem?id=2965 [算法] 位运算 [代码] #include <algorithm> #include <bitset&g ...

  3. 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 ...

  4. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  5. 枚举 POJ 2965 The Pilots Brothers' refrigerator

    题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...

  6. poj 2965 The Pilots Brothers' refrigerator (dfs)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17450 ...

  7. POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16868 ...

  8. POJ 2965 The Pilots Brothers' refrigerator 位运算枚举

      The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 151 ...

  9. POJ 2965 The Pilots Brothers' refrigerator (DFS)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15136 ...

随机推荐

  1. csu 1554: SG Value 思维题

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 这题在比赛的时候居然没想出来,然后发现居然是做过的题目的变种!!!! 先不考虑插入操作, ...

  2. 物体检测丨从R-CNN到Mask R-CNN

    这篇blog是我刚入目标检测方向,导师发给我的文献导读,深入浅出总结了object detection two-stage流派Faster R-CNN的发展史,读起来非常有趣.我一直想翻译这篇博客,在 ...

  3. Smarty中的请求变量和保留变量的使用范例

    PHP中提供的超全局数组 Smarty中对应的请求变量 $_GET               <{$smarty.get}> $_POST                         ...

  4. mysql通过sql语句判断某个字段在一张表中是否存在

    应用场景: 我有一张表,表里面都是用户用来激活游戏的激活码,当用户在前端页面输入激活码时,要查询数据表中是否有这条激活码,如果有就返回"1",没有则返回"0". ...

  5. 利用Jmeter 实现Json格式接口测试

    使用Jmeter模拟http请求测试接口,请求类型为json,步骤如下: 1.启动Jmeter:找到Jmeter.bat文件双击启动Jmeter. 2.在测试计划下面添加线程组:测试计划右键--添加 ...

  6. MS-SQL 时间的操作

    1. 当前系统日期.时间 select getdate()  2. dateadd 在向指定日期加上一段时间的基础上,返回新的 datetime 值 例如:向日期加上2天 select dateadd ...

  7. Linux命令-4类

    一.系统管理与维护   1. pwd:print working directory    打印工作目录   2. cd:  change directory    改变或进入路径       ● c ...

  8. 如何快速构建CMBD系统-glpi

    一.CMBD系统构建步骤 起初,开发这套CMBD系统是为了帮助朋友公司简化设备统计操作,以代替人工入库方式.举个例子,单位发放笔记本,或者设备更换了硬盘,都需要人工签到,手动输入统计,安装了CMBD系 ...

  9. Easy UI 关联表的字段展示

    刚接触的easy UI ,发现展示关联表的字段的时候,卡住了 好一段时间,后来通过qq群询问,终于得到答案 实体Record public class Record:Base { public Gui ...

  10. Protocol Buffer学习教程之编译器与类文件(三)

    Protocol Buffer学习教程之编译器与类文件(三) 1. 概述 在前面两篇中,介绍了Protobuf的基本概念.应用场景.与protobuf的语法等.在此篇中将介绍如何自己编译protobu ...