poj2965--The Pilots Brothers' refrigerator

2024-08-25 01:38

本文主要是介绍poj2965--The Pilots Brothers' refrigerator,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

The Pilots Brothers' refrigerator
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 17642 Accepted: 6685 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>
struct node{int a[16] ;int t , n ;int s[16] ;int top ;
}p[1000000];
int main()
{int i , j , a[16] , min_t = 999999 , to ;char str[4][4] ;for(i = 0 ; i < 4 ; i++)scanf("%s", str[i]);for(i = 0 ; i < 4 ; i++)for(j = 0 ; j < 4 ; j++)if(str[i][j] == '+')a[4*i+j] = 1 ;elsea[4*i+j] = 0 ;int low = 0 , top = 1 ;for(i = 0 ; i < 16 ; i++)p[0].a[i] = a[i] ;p[0].t = 0 ; ;p[0].n = -1 ;p[0].top = 0 ;while(low < top){node k = p[low++] ;int num = 0 ;for(i = 0 ; i < 16 ; i++)num += k.a[i] ;if(num == 0 && k.t < min_t){min_t = k.t ;to = low-1 ;}if(k.n == 15)continue ;if(k.t >= min_t)continue ;p[top] = k ;p[top].n++ ;top++ ;p[top] = k ;p[top].n++ ;p[top].t++ ;p[top].s[ p[top].top++ ] = p[top].n ;i = p[top].n / 4 ;j = p[top].n % 4 ;int s ;for(s = 0 ; s < 4 ; s++){p[top].a[4*i+s] = 1 - p[top].a[4*i+s] ;p[top].a[4*s+j] = 1 - p[top].a[4*s+j] ;}p[top].a[4*i+j] = 1 - p[top].a[4*i+j] ;top++ ;}printf("%d\n", p[to].top);int q ;for(q = 0 ; q < p[to].top ; q++){i = p[to].s[q] / 4 ;j = p[to].s[q] % 4 ;i++;j++ ;printf("%d %d\n", i , j );}return 0;
}


这篇关于poj2965--The Pilots Brothers' refrigerator的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1104189

相关文章

poj 2965 The Pilots Brothers' refrigerator——DFS(分类是枚举)

The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 17929 Accepted: 6794 Special Judge Description The game “The Pilots Brothers: following the s

干吧跌!~brothers!~~

ladies and 乡亲们: 轮到我写战地日记的时候偏偏就开始做第一个项目... -.- 是不是很衰...不发牢骚了,赶紧扯完做项目去。 来到兄弟连一个多月了,让我值得欣慰的是:九年义务教育+高中三年+大学三年的时间都没过得比现在充实(当然有点小小的夸张), 这星期我寝室4位兄弟在班上熬夜做项目,而我则是在宿舍熬到3点多实在熬不下去才睡觉的,看来我还得加把火候阿.. 说实

poj2965_refrigerator(BFS+枚举)

结题思想: 1.此题一定要使用枚举,将每一个位置的值变化的可能都枚举一下。但是个要么变,要么不变,并且和改变的顺序无关。(具体的证明我还不是很清楚,希望看到博客的朋友,如果知道怎么证明,请不吝赐教)。 2.要找最少的情况,则一定是要使用广度优先遍历各种情况。 介绍代码中的几个变量: q[i] 做队列使用,用于存储矩阵的不同状态。 f[i] 此数组和q配合起来,用来记录对应位置状态的是由谁

POJ-2965-The Pilots Brothers' refrigerator-2013-12-05 11:18:12

The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 16671 Accepted: 6327 Special Judge Description The game “The Pilots Brothers: following the st

Flight Simulator X For Pilots Real World Training

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp Get ready to take flight as two certified flight instructors guide you through the pilot ratings as it is

外汇天眼:香港监管机构禁止Nerico Brothers前持牌代表五年

香港证券及期货事务监察委员会(SFC)已经禁止Nerico Brothers Limited的前持牌代表林清超先生和黄肇峰先生重新进入行业,为期五年。禁令将从2024年2月6日持续至2029年2月5日,此举是因为林和黄分别因行贿罪被判有罪。 林和黄于2022年8月在区域法院被判有罪,涉及向香港金融工程公司有限公司(HKFECL)首席执行官行贿,与使用一款用于期货交易的计算机算法程序有关。该首

[BZOJ 2096][Poi2010]Pilots:单调队列

点击这里查看原题 维护两个单调队列,一个递增,一个递减。 /*User:SmallLanguage:C++Problem No.:2096*/#include<bits/stdc++.h>#define ll long long#define inf 999999999using namespace std;const int M=3e6+5;int lx,rx,mx[M]

poj 2965 The Pilots Brothers' refrigerator 普通dfs 超时 暑假第二题

代码: //#include<iostream>#include<string.h>#include<stdio.h>//using namespace std;int step=0;int visit[5][5]= {0};char a[5][5];bool b[5][5];bool c[5][5];int k=0;struct Str{int x;int y;};

poj 2965 The Pilots Brothers' refrigerator 枚举+组合 暑假第二题

其实和  poj 1753样,甚至更简单,套用1753代码打的,并优化了一部分; 具体参考:http://blog.csdn.net/sholck222/article/details/46695087 但在这道题中,可能限制时间交紧,相同代码提交两次才过,第一次超时,第二次险过,953ms; 这道题还有其他解法,如高斯解法,枚举+dfs,这两份代码及简析明天会发上来 枚举+组合的代码:

【NOIP2016提高A组模拟9.9】Brothers

在遥远的西方有一个古老的王国,国王将他的王国分成了网格状,每一块称之为一个城市。在国王临死前,他将这些城市分给了自己的N个儿子(编号为0到N-1)。然而这N个王子的关系不是很好,0讨厌1,1讨厌2,2讨厌3……N-1讨厌0。 在国王死后,这种不好的关系使得王子之间爆发了战争。战斗只会在相邻的两个城市之间爆发(共有一条边称之为相邻),并且只有当A讨厌B时,A才会对B发起战斗,结果必定是A获得这次战