The Pilots Brothers' refrigerator
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 15136   Accepted: 5660   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
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue> using namespace std; char str[][]; int change[]={ , , ,, ,,,
,, ,,,, , , }; int vis[];
int path[]; struct node{
int status;
int step;
}; void BFS(int curstate){
queue<node> q;
while(!q.empty())
q.pop();
node cur,next;
cur.status=curstate, cur.step=;
vis[cur.status]=;
q.push(cur);
while(!q.empty()){
cur=q.front();
q.pop();
for(int i=;i<;i++){
next.status=cur.status^change[i];
next.step=cur.step+;
if(!vis[next.status]){
vis[next.status]=;
path[next.status]=i;
q.push(next);
}
if(next.status==){
printf("%d\n",next.step);
int k=next.status;
while(k!=curstate){
printf("%d %d\n",path[k]/+,path[k]%+);
k=k^change[path[k]];
}
return ;
}
}
}
}
/*
int num[16]; //即求change[]的方法 void init(){
for(int i=0;i<16;i++){
num[i]=0;
for(int j=0;j<16;j++)
if((i/4==j/4) || (i%4==j%4))
num[i]=(num[i]<<1)+1;
else
num[i]<<=1;
}
}
*/
int main(){ //freopen("input.txt","r",stdin);
/*
init();
for(int i=0;i<16;i++)
printf("%d ",num[i]);
printf("\n");
*/
while(~scanf("%s",str[]+)){
for(int i=;i<;i++)
scanf("%s",str[i]+);
int status=;
for(int i=;i<=;i++)
for(int j=;j<=;j++){
status<<=;
if(str[i][j]=='-')
status |= ;
}
if(status==){
printf("0\n");
continue;
}
memset(vis,,sizeof(vis));
BFS(status);
}
return ;
}
4 4

Source

Northeastern Europe 2004, Western Subregion
 
 
 

POJ 2965 The Pilots Brothers' refrigerator (DFS)的更多相关文章

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

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

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

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

  3. 枚举 POJ 2965 The Pilots Brothers' refrigerator

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

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

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

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

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

  6. The Pilots Brothers' refrigerator(dfs)

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

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

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

  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(压位+bfs)

    The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to op ...

随机推荐

  1. 我所遭遇过的游戏中间件--Apex

    我所遭遇过的游戏中间件--Apex Apex是PhysX的扩展中间件,它是在PhysX的基础上封装了一层.用于实现布料,粒子,破碎这三种物理效果.我只研究其布料处理.使用Apex做物理最大的好处是:它 ...

  2. 【转载】Hybrid APP了解

    原文:http://uikoo9.com/blog/detail/hpp 不错的hybrid app框架:http://www.dcloud.io/case/#group-1 HPP hybirdAp ...

  3. super-pow

    // https://discuss.leetcode.com/topic/50489/c-clean-and-short-solution class Solution { ; int powMod ...

  4. 新鲜出炉!9个超高分辨率的iPhone 6原型素材打包下载

    iPhone 6 出场,设计师又有得忙活了,但是新鲜的资源你们在哪里?!今天我们收集了一组精致的iPhone 6 模型素材,超高分辨率,多种视图,全都打包完毕,点一下就可以拿回家!赶紧来取吧!——   ...

  5. IOS 设置圆角用户头像

    在App中有一个常见的功能,从系统相册或者打开照相机得到一张图片,然后作为用户的头像.从相册中选取的图片明明都是矩形的图片,但是展示到界面上却变成圆形图片,这个神奇的效果是如何实现的呢? 请大家跟着下 ...

  6. NTP Server

    Network Time Protocol互联网时间协议 NTP is intended to synchronize all participating computers to within a ...

  7. 内容匹配广告投放技术4:网盟CTR预估(百度文库课程)

    原文:http://wbj0110.iteye.com/blog/2043065 该文是百度文库课程<计算广告学之内容匹配广告&展示广告原理.技术和实践>的课程笔记,感谢百度! 课 ...

  8. [Backbone]2. More detail in Models

    Our Appointment model doesn't seem too useful yet. Add two default attributes, title as the string & ...

  9. JSTL详解(二)

    JSTL详解(二) 在JSTL中,一般用途的标签只要是指具有输出,设置变量,和错误处理等功能的标签,他们在jsp中使用很频繁,它们有: l         <c:out> l        ...

  10. 腾讯云兑现存储获取临时授权C#版

    腾讯官方没有提供C#版的,没办法自己根据java版改写了一个,这里面的坑花了我20多个小时,所以记录下 <%@ WebHandler Language="C#" Class= ...