题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+'记为1, '-'记为0 1. 从(1, 1)走到(4, 4),每一点DFS两次(改点反转或不反转):used记录反转的位置 详细解释:http://poj.org/showmessage?message_id=346723 2. 比较巧妙的解法:抓住'+'位置反转,'-'位置相对不反转的特点,从状…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286   Accepted: 8603   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
  The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15176   Accepted: 5672   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17450   Accepted: 6600   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16868   Accepted: 6393   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
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…
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 o…
题目:http://poj.org/problem?id=2965 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#problem/B 题意: 就是把题目中给出的状态图,全部翻转成 ---- ---- ---- ----状态 翻转: 每次翻转一个,那么它所在的行和列都要翻转 问最小翻转次数,同时输出翻转路径. 算法: 暴力 + 枚举 + dfs 思路: 可以证明每个把手要么翻转,要么不翻转,那么从左到右,从上到下依次枚…
//题目:http://poj.org/problem?id=2965//题意:电冰箱有16个把手,每个把手两种状态(开‘-’或关‘+’),只有在所有把手都打开时,门才开,输入数据是个4*4的矩阵,因此考虑用位表示.可以改变任意一个把手的位置,但同时改变其所在的行和列.求最小步骤.//耗时 800MS1 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> using…
http://poj.org/problem?id=2965 题意: 一个4*4的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全部变成'-'. 思路: 这道题和黑白棋那道题目差不多,唯一的差别就是需要记录一下路径. 我是用BFS来做的,用二进制来存储.翻转时用位运算的异或比较方便,可以看一下我的这篇博客(http://www.cnblogs.com/zyb993963526/p/6347741.html),上面写的比较清楚.…
https://vjudge.net/problem/POJ-2965 与poj-1753相似,只不过这个要记录路径.poj-1753:https://www.cnblogs.com/fht-litost/p/9160723.html 题意 4*4的方格,翻转其中的一个把手,会带动同行同列的把手一起动.现要求把所有把手都翻成‘-’状态,问最少需要几步. 分析 异曲同工之妙.加个vector记录路径即可.使用状态压缩的写法输出路径也很方便. #include<iostream> #include…
题目链接 题意:一个冰箱上有4*4共16个开关,改变任意一个开关的状态(即开变成关,关变成开)时,此开关的同一行.同一列所有的开关都会自动改变状态.要想打开冰箱,要所有开关全部打开才行. 输入:一个4×4的矩阵,+表示关闭,-表示打开:输出:使冰箱打开所需要执行的最少操作次数,以及所操作的开关坐标. 题解:核心其实就是,把开关本身以及其同一行同一列的开关(总共7个)都进行一次操作,结果是,开关本身状态改变了7次,开关同一行.同一列的开关状态改变了4次,其他开关状态改变了2次.这就相当于只改变了本…
题目链接: http://poj.org/problem?id=1753 题意: 给定冰箱门的开关情况,改变一个门则其所在行列的门都会发生改变,求出改变门的最少操作使得最终所有门都是打开状态. 代码: bfs+状态压缩很容易想到~~ 这里的状态压缩要需要多加小心,注意一下存储的是翻转门的情况~ #include<iostream> #include<cstdio> #include<queue> using namespace std; typedef pair<…
题目链接:http://poj.org/problem?id=2965 The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Description The game "The Pilots Brothers: following the stripy elephant" has a quest where a player needs to open a refrigerator. Ther…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19356   Accepted: 7412   Special Judge Description The game "The Pilots Brothers: following the stripy elephant" has a quest where a player needs to o…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18040   Accepted: 6841   Special Judge Description The game "The Pilots Brothers: following the stripy elephant" has a quest where a player needs to o…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27893   Accepted: 10802   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open…
链接:poj 2965 题意:给定一个4*4矩阵状态,代表门的16个把手.'+'代表关,'-'代表开.当16个把手都为开(即'-')时.门才干打开,问至少要几步门才干打开 改变状态规则:选定16个把手中的随意一个,能够改变其本身以及同行同列的状态(即若为开,则变为关,若为关,则变为开),这一次操作为一步. 分析:这题与poj 1753思路差点儿相同,每一个把手最多改变一次状态, 全部整个矩阵最多改变16次状态 思路:直接dfs枚举全部状态,直到找到目标状态 可是要打印路径,全部应在dfs时记录路…
转载请注明出处:http://blog.csdn.net/a1dark 分析:如果想要将一个“+”翻转成“-”,那么必然会把对应的行和列上的所有点翻转一次.由于一个点翻偶数次就相当于不翻转.所以我需要统计“+”.然后将对应行和列的值+1.最后统计奇数值的个数.便是要翻转的点. #include<stdio.h> int mpt[5][5]; int main(){ char ch; for(int i=1;i<=4;i++){ for(int j=1;j<=4;j++){ scan…
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 op…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22057   Accepted: 8521   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20304   Accepted: 7823   Special Judge Description The game "The Pilots Brothers: following the stripy elephant" has a quest where a player needs to o…
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…
The Pilots Brothers' refrigerator 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 stat…
  Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20325   Accepted: 7830   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 hand…
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 refrigerat…
题目链接:http://poj.org/problem?id=2965 题解:自己想到的方法是枚举搜索,结果用bfs和dfs写都超时了.网上拿别人的代码试一下只是刚好不超时的,如果自己的代码在某些方面不够优化,那超时很正常.看来这题用dfs和bfs都不是好办法. 然后又看到比较厉害的技巧:“可知翻偶数次等于没翻,即没有翻的必要,翻奇数次的结果与翻一次的结果一样“”.有了这个重要结论,那么可以具体操作了:设一个二维数组以记录每个的翻转次数.对于每个‘+’,都翻转其所在的行列(注意‘+’只翻一次),…
题意 游戏“The Pilots Brothers:跟随有条纹的大象”有一个玩家需要打开冰箱的任务. 冰箱门上有16个把手.每个手柄可以处于以下两种状态之一:打开或关闭.只有当所有把手都打开时,冰箱才会打开.手柄表示为矩阵4х4.您可以在任何位置[i,j](1≤i,j≤4)更改句柄的状态.但是,这也会更改第i行中所有句柄的状态以及第j列中的所有句柄. 任务是确定打开冰箱所需的最小手柄切换次数. 思路 一个和“费解的开关”,"棋盘翻转",这样的位运算的题目很像,只不过这次一次翻转1行+1…
[题目链接] http://poj.org/problem?id=2965 [算法] 位运算 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #includ…
题目链接:http://poj.org/problem?id=2965 分析:1.这道题和之前做的poj1753题目差不多,常规思路也差不多,但是除了要输出最少步数外,还要输出路径.做这道题的时候在怎么输出bfs的路径上卡了下,然后为了方便输出试用dfs写了下,结果TLE了.T^T(不开森.... 2.还有个地方调bug调了挺久的,bfs里面记录路径的时候要记录当前状态的上一个状态,结果没有判断这个状态是否加入队列过就直接改变了,见代码注释处. 3.重点是会写bfs记录路径了. 4.听说这道题有…