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. 阿里客户端工程师试题简析——Android应用的闪退(crash)分析

    1. 问题描述 闪退(Crash)是客户端程序在运行时遭遇无法处理的异常或错误时而退出应用程序的表现,请从crash发生的原因分类与解决方法.在出现crash后如何捕捉并分析异常这两个问题给出自己的解 ...

  2. 对于RegExp反向引用的一点理解

    置顶文章:<纯CSS打造银色MacBook Air(完整版)> 上一篇:<关于js的Array.prototype.slice.call> 作者主页:myvin 博主QQ:85 ...

  3. #Linux学习笔记# Linux系统查看文件内容的命令

    1.cat 连结多个文件的内容并显示在屏幕上:如果没有指定文件或文件名为“-”,则读取标准输入.语法如下: cat [option] ... [file] ... 常用的选项有: 选项-n:编号所有行 ...

  4. 记录nginx 搭建集群环境踏过的坑

    因为生产环境做了负载均衡,为了尽可能跟线上环境一致,所以想在本地也搭集群,这样测试更靠谱.首先就想到nginx 这货,搭个简单的web 服务器实在太简单了. nginx 这玩意11年简单玩过,那是版本 ...

  5. 《TCP/IP详解卷1:协议》第3章 IP:网际协议(2)-读书笔记

    章节回顾: <TCP/IP详解卷1:协议>第1章 概述-读书笔记 <TCP/IP详解卷1:协议>第2章 链路层-读书笔记 <TCP/IP详解卷1:协议>第3章 IP ...

  6. setter方法的内存错误

    - (void)setList:(ClassicList *)list { self.list = list; _titleLabel.text = list.activityName; _addre ...

  7. JavaIO中的Reader和writer

    1.reader package com.io.Reader; import java.io.BufferedReader; import java.io.FileInputStream; impor ...

  8. hdu1507二分匹配

    1 //hdu1507 挺不错的题 #include<stdio.h> #include<string.h> #define INF 99999999 struct node ...

  9. 打印cell的视图层次结构

    #ifdef DEBUG NSLog(@"Cell recursive description:\n\n%@\n\n", [cell performSelector:@select ...

  10. RIP、OSPF、BGP、动态路由选路协议、自治域AS

    相关学习资料 tcp-ip详解卷1:协议.pdf http://www.rfc-editor.org/rfc/rfc1058.txt http://www.rfc-editor.org/rfc/rfc ...