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
思路:dfs,加个数组保存路径
实现代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<list>
using namespace std;
#define ll long long
#define sd(x) scanf("%d",&x)
#define sdd(x,y) scanf("%d%d",&x,&y)
#define sddd(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sf(x) scanf("%s",x)
#define ff(i,x,y) for(int i = x;i <= y;i ++)
#define fj(i,x,y) for(int i = x;i >= y;i --)
#define mem(s,x) memset(s,x,sizeof(s));
#define pr(x) printf("%d",x);
const int Mod = 1e9+;
const int inf = 1e9;
const int Max = 1e5+;
void exgcd(ll a,ll b,ll& d,ll& x,ll& y){if(!b){d=a;x=;y=;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}
ll inv(ll a,ll n){ll d, x, y;exgcd(a,n,d,x,y);return (x+n)%n;}
int gcd(int a,int b) { return (b>)?gcd(b,a%b):a; }
int lcm(int a, int b) { return a*b/gcd(a, b); }
//int mod(int x,int y) {return x-x/y*y;}
char s[];
int mp[][];
int ans = inf,i,j;
int rankx[],ranky[],fx[],fy[];
int check()
{
for(i=;i<;i++){
for(j=;j<;j++){
if(mp[i][j]!=)
return ;
}
}
return ;
} void fan(int x,int y){
for(i=;i<;i++){
mp[x][i] = !mp[x][i];
mp[i][y] = !mp[i][y];
}
mp[x][y] = !mp[x][y];
} int dfs(int x,int y,int t)
{
if(check()){
if(ans>t){
ans = t;
for(i=;i<t;i++){
rankx[i] = fx[i];
ranky[i] = fy[i];
}
}
return ;
}
if(x>=||y>=)
return ;
int nx = (x+)%;
int ny = y+(x+)/;
dfs(nx,ny,t);
fan(x,y); fx[t] = x+;
fy[t] = y+; dfs(nx,ny,t+);
fan(x,y); return ;
}
int main()
{
for(i=;i<;i++){
cin>>s;
for(j=;j<;j++){
if(s[j]=='+')
mp[i][j] = ;
else
mp[i][j] = ;
}
}
dfs(,,);
cout<<ans<<endl;
for(i=;i<ans;i++){
cout<<rankx[i]<<" "<<ranky[i]<<endl;
}
return ;
}

poj2965 【枚举】的更多相关文章

  1. poj2965枚举

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

  2. 假期训练八(poj-2965递归+枚举,hdu-2149,poj-2368巴什博奕)

    题目一(poj-2965):传送门 思路:递归+枚举,遍历每一种情况,然后找出最小步骤的结果,与poj-1753类似. #include<iostream> #include<cst ...

  3. poj2965 The Pilots Brothers&#39; refrigerator(直接计算或枚举Enum+dfs)

    转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://poj.org/problem? id=2965 ---- ...

  4. dfs+枚举,flip游戏的拓展POJ2965

    POJ 2965             The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: fo ...

  5. POJ-2965 The Pilots Brothers' refrigerator---思维题

    题目链接: https://vjudge.net/problem/POJ-2965 题目大意: 一个冰箱上有4*4共16个开关,改变任意一个开关的状态(即开变成关,关变成开)时,此开关的同一行.同一列 ...

  6. poj2965 The Pilots Brothers' refrigerator —— 技巧性

    题目链接:http://poj.org/problem?id=2965 题解:自己想到的方法是枚举搜索,结果用bfs和dfs写都超时了.网上拿别人的代码试一下只是刚好不超时的,如果自己的代码在某些方面 ...

  7. Swift enum(枚举)使用范例

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  8. 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)

    建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...

  9. Objective-C枚举的几种定义方式与使用

    假设我们需要表示网络连接状态,可以用下列枚举表示: enum CSConnectionState { CSConnectionStateDisconnected, CSConnectionStateC ...

随机推荐

  1. SkylineGlobe 如何实现工程进度管理或者说是对象生命周期管理

    SkylineGlobe 的 TerraExplorer Pro里面,给我们提供了一个Timespan Tags工具,通过这个工具,我们可以设置ProjectTree任务组对象的生命周期: 然后通过调 ...

  2. ASP.NET Core 防止跨站请求伪造(XSRF/CSRF)攻击 (转载)

    什么是反伪造攻击? 跨站点请求伪造(也称为XSRF或CSRF,发音为see-surf)是对Web托管应用程序的攻击,因为恶意网站可能会影响客户端浏览器和浏览器信任网站之间的交互.这种攻击是完全有可能的 ...

  3. Log4j2使用笔记

                 log4j2是log4j的最新版,现在已经有很多公司在使用了.log4j2和log4j的优缺点对比,请自行百度. 上一篇笔记讲了关于log4j的使用.这篇笔记主要讲解log4 ...

  4. 学习ML.NET(2): 使用模型进行预测

    训练模型 在上一篇文章中,我们已经通过LearningPipeline训练好了一个“鸢尾花瓣预测”模型, var model = pipeline.Train<IrisData, IrisPre ...

  5. Mvc_缓存浅谈

    缓存是将信息放在内存中以避免频繁访问数据库从数据库中提取数据,在系统优化过程中,缓存是比较普遍的优化做法和见效比较快的做法. 对于MVC有Control缓存和Action缓存. 一.Control缓存 ...

  6. Runaway argument错误 [Overleaf: 在线Latex] [Type 3问题后续]

    [背景与问题描述] 在Latex中,经常出现各种问题: Runaway argument? {\contentsline {subsection}{\numberline {6.3}General c ...

  7. Android环境准备

    Android环境准备: 1.安装Java环境(自行安装) 2.下载Android SDK包 3.配置系统环境变量 新建ANDROID_HOME 变量值:SDK安装路径(如:D:\android-sd ...

  8. Gitlab环境快速部署(RPM包方式安装)

    之前梳理了一篇Gitlab的安装CI持续集成系统环境---部署Gitlab环境完整记录,但是这是bitnami一键安装的,版本比较老.下面介绍使用rpm包安装Gitlab,下载地址:https://m ...

  9. centos6.5虚拟机安装后,没有iptables配置文件

    openstack环境里安装centos6.5系统的虚拟机,安装好后,发现没有/etc/syscofig/iptables防火墙配置文件. 解决办法如下: [root@kvm-server005 ~] ...

  10. 牛客OI赛制测试赛-序列-模拟

    哇这道题好坑啊,可能是我太菜了 题意就是叫把一个连续序列分成K组,使得每个组的和都相等 我最开始的想法是由于要分成K组,那我们知道,每组一定有sum(a[i])/k这样我们只需要每次当num==sum ...