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. GIT 远程仓库:添加远程库、从远程库克隆

    到目前为止,我们已经掌握了如何在Git仓库里对一个文件进行时光穿梭,你再也不用担心文件备份或者丢失的问题了. 可是有用过集中式版本控制系统SVN的童鞋会站出来说,这些功能在SVN里早就有了,没看出Gi ...

  2. eclipse调试断点【转载】

    该片博文是转载他人的博客,原博客地址:http://blog.csdn.net/maritimesun/article/details/7815903 作为开发人员,掌握开发环境下的调试技巧十分有必要 ...

  3. pycharm 取消 rebase 操作

    291/5000 取消rebase操作从主菜单中选择VCS | Git | 中止重新定位(abrot rebasing)如果rebase在两个或多个本地存储库中启动,则会显示“中止重新排序”对话框. ...

  4. React-将元素渲染到 DOM 中

    首先我们在一个 HTML 页面中添加一个 id="root" 的 <div>,在此 div 中的所有内容都将由 React DOM 来管理,所以我们将其称之为 “根” ...

  5. P1438 无聊的数列

    P1438 无聊的数列 链接 分析: 等差数列可加,首项相加,公差相加. 代码: #include<cstdio> #include<algorithm> #include&l ...

  6. python语言程序设计7

    1, 特么的打个空格出现就出现个点是个怎么回事, 昨天虽然是我复制的代码,,但也是我一点一点写出来的啊.. 复制的时候缩进直接就没了.我去 但是我感觉它一开始给我讲的一些基础理论又有点忘了,我希望你能 ...

  7. 提升----你所不知道的JavaScript系列(3)

    很多编程语言在执行的时候都是自上而下执行,但实际上这种想法在JavaScript中并不完全正确, 有一种特殊情况会导致这个假设是错误的.来看看下面的代码, a = 2; var a; console. ...

  8. Git push 时如何避免出现 "Merge branch 'master' of ..."

    在使用 Git 的进行代码版本控制的时候,往往会发现在 log 中出现 "Merge branch 'master' of ..." 这句话,如下图所示.日志中记录的一般为开发过程 ...

  9. 递归遍历对象获取value值

    let menu = { name: '一级菜单', data: { name: '二级菜单', data: { name: '三级菜单', data: { name: '四级菜单' } } } }; ...

  10. 2018年高教社杯全国大学生数学建模竞赛C题解题思路

    题目 C题   大型百货商场会员画像描绘 在零售行业中,会员价值体现在持续不断地为零售运营商带来稳定的销售额和利润,同时也为零售运营商策略的制定提供数据支持.零售行业会采取各种不同方法来吸引更多的人成 ...