2965

he Pilots Brothers' refrigerator
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 19995   Accepted: 7695   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<string.h>
#include<algorithm>
using namespace std; int map[][],ak[],AK[],flg,n,step; int judge(int map[][])
{
for(int i=;i<=;i++)
for(int j=;j<=;j++)
{
if(map[i][j]!=)
return ;
}
return ;
} void flip(int r,int c)
{
int i,j;
for(i=;i<r;i++)
{
if(map[i][c]==)
map[i][c]=;
else
map[i][c]=;
}
for(i=r+;i<=;i++)
{
if(map[i][c]==)
map[i][c]=;
else
map[i][c]=;
}
for(j=;j<c;j++)
{
if(map[r][j]==)
map[r][j]=;
else
map[r][j]=;
}
for(j=c+;j<=;j++)
{
if(map[r][j]==)
map[r][j]=;
else
map[r][j]=;
}
if(map[r][c]==)
map[r][c]=;
else
map[r][c]=;
return;
} void dfs(int r,int c,int deep)
{
int i,j;
if(deep==step)
{
flg=judge(map);
return;
}
if(flg== || r>)
{
return;
}
flip(r,c);
ak[n]=r,AK[n]=c;
n++;
if(c<)
dfs(r,c+,deep+);
else
dfs(r+,,deep+); if(flg!=)
{
flip(r,c);
n--;
if(c<)
dfs(r,c+,deep);
else
dfs(r+,,deep);
}
return;
} int main()
{
int i,j;
char x;
memset(map,,sizeof(map));
for(i=;i<=;i++)
{
for(j=;j<=;j++)
{
scanf("%c",&x);
if(x=='-')
map[i][j]=;
}
getchar();
}
for(step=;step<=;step++)
{
n=;
dfs(,,);
if(flg==)
break;
}
printf("%d\n",step);
for(i=;i<=n-;i++)
{
printf("%d %d\n",ak[i],AK[i]);
}
return ;
}

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

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

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

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

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

  3. The Pilots Brothers' refrigerator(dfs)

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

  4. 枚举 POJ 2965 The Pilots Brothers' refrigerator

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

  5. 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 ...

  6. POJ 2965 The Pilots Brothers' refrigerator 暴力 难度:1

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

  7. POJ2965——The Pilots Brothers' refrigerator

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

  8. POJ 2965 The Pilots Brothers' refrigerator 位运算枚举

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

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

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

随机推荐

  1. 夺命雷公狗TP下关联查询

    记录下我们常用的关联查询: public function add4(){ $id=$_GET['id']; $this->list = M("student")->t ...

  2. PAT乙级 1008. 数组元素循环右移问题 (20)

    1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在不允 ...

  3. 解决ultravnc在win2008 R2下CTRL+ALT+DELETEA组合键发送失败的问题

    首先,请google “ultravnc ctrl+alt+delete”,得到的解决方法是,更改UAC.进入组策略-计算机配置-管理模板-windows登陆选项,“禁用或启用软件注意序列”,更改成“ ...

  4. 数据结构之,线性表去除等于x的元素

    问题看起来很简单,但是这里有个限制,就是算法的时间复杂度位O(n),空间复杂度为O(1),下面上代码 #include <iostream> #include <string.h&g ...

  5. C#(winform)浏览按钮

    FolderBrowserDialog folderBrowser = new FolderBrowserDialog();            //folderBrowser.SelectedPa ...

  6. Delphi中CoInitialize之探究

    CoInitialize(LPVOID),它将以特定参数调用CoInitializeEx,为当前单元初始化COM库,并标记协同模式为单线程模式.参数必须为NULL.这是关于OLE和COM的问题. Co ...

  7. NIOS II开发备忘录

    大概有一年没做NIOS II的开发了,回想上一次做NIOS II还是去年做毕业设计的时候.那时候做的是基于SOPC的频率特性测试仪,我大约花了2个月的时间,从无到有的学习了NIOS II开发.学习过N ...

  8. MySQL查询表内重复记录

    查询及删除重复记录的方法(一)1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select p ...

  9. javascript——web前端编程

    一.弹出提示框: 连接 function disp_prompt()  {  var name=prompt("请输入您的名字","Bill Gates")  ...

  10. python:配置文件configparser

    #-*- coding:utf8 -*- # Auth:fulimei import configparser #第一个标签 conf=configparser.ConfigParser() conf ...