The Pilots Brothers' refrigerator
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 19718   Accepted: 7583   Special Judge

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

Source

Northeastern Europe 2004, Western Subregion
 
 #include<stdio.h>
#include<iostream>
using namespace std;
bool a[][] = {} ;
bool flag ;
int step ;
int in[] ;
int dex ; bool judge_all ()
{
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
if (a[i][j])
return false ;
}
}
return true ;
} void flip (int row , int col)
{
for (int i = ; i < ; i++) {
a[row][i] = !a[row][i] ;
a[i][col] = !a[i][col] ;
}
a[row][col] = !a[row][col] ;
} void dfs (int row , int col , int deep)
{
if (deep == step) {
flag = judge_all ();
return ;
} if (flag || row == )
return ; flip (row , col) ;
if (col < )
dfs (row , col + , deep + ) ;
else
dfs (row + , , deep + ) ; flip (row , col) ;
if (flag) {
in[dex] = row ;
in[dex + ] = col ;
dex += ;
}
if (col < )
dfs (row , col + , deep) ;
else
dfs (row + , , deep) ; return ;
} int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
char x ;
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
cin >> x ;
if ( x == '+')
a[i][j] = ;
}
} for (step = ; step <= ; step++) {
dex = ;
dfs ( , , ) ;
if (flag)
break ;
} printf ("%d\n" , step) ;
for (int i = step * ; i >= ; i--) {
if ( i & )
printf ("%d %d\n" , in[i] , in[i + ]) ;
}
}

套Flip Game 模板,思路也一样

The Pilots Brothers' refrigerator(dfs)的更多相关文章

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

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

  2. POJ2965The Pilots Brothers' refrigerator(枚举+DFS)

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

  3. POJ 2965 The Pilots Brothers' refrigerator (暴力枚举)

    https://vjudge.net/problem/POJ-2965 与poj-1753相似,只不过这个要记录路径.poj-1753:https://www.cnblogs.com/fht-lito ...

  4. POJ 2965 The Pilots Brothers' refrigerator (枚举+BFS+位压缩运算)

    http://poj.org/problem?id=2965 题意: 一个4*4的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全 ...

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

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

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

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

  7. 枚举 POJ 2965 The Pilots Brothers' refrigerator

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

  8. The Pilots Brothers' refrigerator

    2965 he Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1 ...

  9. POJ2965——The Pilots Brothers' refrigerator

    The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: following the stripy el ...

随机推荐

  1. Jenkins进阶系列之——05FTP publisher plugin插件

    说明:这个插件可以将构建的产物(例如:Jar)发布到FTP中去. 官方说明:FTP publisher plugin 安装步骤: 系统管理→管理插件→可选插件→Artifact Uploaders→F ...

  2. Cocopod上更新上传自己的开源框架供别人下载

    为了更方便的集成第三方框架有了cocopods 的, 当我们有了相对比较好的框架的时候如何更新到cocopods 供他人参考呢? 下面我一步一步带大家开源自己的框架. 第一步 把自己的框架更新到git ...

  3. DOM系列---DOM操作样式

    发文不易,若转载传播,请亲注明出处,谢谢! 一.操作样式 CSS作为(X)HTML的辅助,可以增强页面的显示效果.但不是每个浏览器都能支持最新的CSS能力.CSS的能力和DOM级别密切相关,所以我们有 ...

  4. angular_$attrs

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. Codeforces Round #381 (Div. 2) D. Alyona and a tree 树上二分+前缀和思想

    题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsm ...

  6. 转-sql中的case when的用法

    Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END ...

  7. Java-小数点控制

    package 运算及类型转换类; import java.text.DecimalFormat; public class 控制小数点类 { public static double decimal ...

  8. Java基础-重写-子类重写父类中的方法后执行情况

    代码 public class Test { public static void main(String[] args) { Shape shape = new Circle(); System.o ...

  9. BZOJ1432 [ZJOI2009]Function

    Description Input 一行两个整数n; k. Output 一行一个整数,表示n 个函数第k 层最少能由多少段组成. Sample Input 1 1 Sample Output 1 H ...

  10. 【转】set容器的基本操作

    set的基本操作:begin()         返回指向第一个元素的迭代器clear()         清除所有元素count()         返回某个值元素的个数empty()        ...