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 ...
随机推荐
- 传纸条(scrip)
传纸条(scrip) 题目背景 Awson是某国际学校信竞组的一只菜鸡.每次竞赛考试都只能垫底.终于有一天,他决定不再苟活,发挥他的人脉优势,准备在一次竞赛考试时传纸条作弊. 题目描述 他预先知道了考 ...
- MariaDB 实现主从复制
實驗目的: MariaDB為MySQL的一個分支,其完全開源.無版權之虞且操作上與 MySQL 一脈相承,實際應用中非常廣泛,軟件本身很小,安裝容易,使用簡單. 但其也有缺點,指令行方式操作,無原生G ...
- ES5数组遍历
reduce() 方法接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值. array.reduce(function(total, currentValue, curren ...
- SpringMVC的基础配置及视图定位
概要 记录一下搭建SpringMVC框架的步骤 视图定位也就是改变jsp在项目中的路径 一.新建javaweb项目springmvc1,在lib中导入jar包 此项目上传了GitHub,方便去下载ja ...
- docker部署mysql远程连接 解决1251 client does not support ..
现象:用虚拟机上Docker启动mysql之后无法在本地安装的navicat上远程连接已启动的mysql,错误截图: 原因:mysql 8.0 默认使用 caching_sha2_password 身 ...
- calibre电子书管理软件
软件介绍: Calibre 是电子书管理软件,支持 Amazon.Apple.Bookeen.Ectaco.Endless Ideas.Google/HTC.Hanlin Song 设备及格式,功能十 ...
- 织梦list/arclist标签调用文章内容
list标签: 1. 进入后台->模型表单-> 频道模型 -> 内容模型管理 -> 修改对应的模型 2. 列表附加字段-填写body 3. 调用时添加“addfields='b ...
- HttpRunner环境搭建
官方文档地址:http://cn.httprunner.org/官方源码地址:https://github.com/HttpRunner/HttpRunner HttpRunner 是一款面向 HTT ...
- 一个SQL server的事务存储
-- ============================================= -- Author: Evan -- Create date: 2018年6月14日 16点27分 - ...
- HYSBZ 1010 玩具装箱toy (决策单调DP)
题意: 有n个玩具,要将它们分为若干组,玩具长度C可能不同.给出n个玩具的摆放顺序,连续的任意多个玩具都可以成为一组.区间[i,j]成为一组的费用是cost=(j-i+Sigma(Ck)-L)2且i& ...