poj 2965
http://poj.org/problem?id=2965
本题要结合poj 1753 来看最好。。。又有了一点搜索的经验。。加油。。。
#include <iostream>
#include<queue>
#include<cstring>
using namespace std;
int step[];
bool flag[];
unsigned qState[];
struct node{
int from,index;
} f[];//用于存它在队列中的生成他的那个节点的位置,和生成他的那个节点的在位置数组中的位置即--i---也就是index;
int rear = ,top = ;
void init(){
char c;
int temp = ;
memset(f,-,sizeof(f));
for(int i=;i<;i++)
for(int j=;j<;j++){
cin>>c;
if(c=='-'){
temp |=(<<(i*+j));
}
}
qState[rear++] = temp;
flag[temp]=true;
}
int mve(int state,int i){
int temp = ;
temp |= (<<i);
int x = i/;
int y = i%;
for(int k=;k<;k++)//所在的一行和一列都变
temp |= <<(x*+k);
for(int k=;k<;k++)
temp |= <<(k*+y);
return temp^state;
}
void bfs(){
while(rear>top){
int state = qState[top++];
for(int i=;i<;i++){
int temp = mve(state,i); if(state==){
cout<<step[state]<<endl;
int tt = top-;
while(f[tt].from!=-){//输出位置。。
cout<<f[tt].index/+<<" "<<f[tt].index%+<<endl;
tt = f[tt].from;
}
return ;
}
else if(!flag[temp]){
f[rear].from = top-;//存其生成节点的信息。。
f[rear].index = i;
qState[rear++] = temp;
flag[temp] = true;
step[temp] = step[state]+;
}
}
} } int main()
{
init();
bfs(); return ;
}
poj 2965的更多相关文章
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- 枚举 POJ 2965 The Pilots Brothers' refrigerator
题目地址:http://poj.org/problem?id=2965 /* 题意:4*4的矩形,改变任意点,把所有'+'变成'-',,每一次同行同列的都会反转,求最小步数,并打印方案 DFS:把'+ ...
- poj 2965 The Pilots Brothers' refrigerator(dfs 枚举 +打印路径)
链接:poj 2965 题意:给定一个4*4矩阵状态,代表门的16个把手.'+'代表关,'-'代表开.当16个把手都为开(即'-')时.门才干打开,问至少要几步门才干打开 改变状态规则:选定16个把手 ...
- poj 2965 The Pilots Brothers' refrigerator枚举(bfs+位运算)
//题目:http://poj.org/problem?id=2965//题意:电冰箱有16个把手,每个把手两种状态(开‘-’或关‘+’),只有在所有把手都打开时,门才开,输入数据是个4*4的矩阵,因 ...
- POJ 2965&&1753
最近由于复习备考(然而考得还是很炸),很久没打题目了.现在开始刷寒假作业,不得不搞POJ 话说没有中文真的好烦啊! 先看1753 题目大意是说在一个4*4的格子中有黑白两色的棋子,你可以翻动其中的棋子 ...
- POJ 2965 The Pilots Brothers' refrigerator (枚举+BFS+位压缩运算)
http://poj.org/problem?id=2965 题意: 一个4*4的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全 ...
- POJ 2965 The Pilots Brothers' refrigerator【枚举+dfs】
题目:http://poj.org/problem?id=2965 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#pro ...
- 【POJ 2965】 The Pilots Brothers' refrigerator
[题目链接] http://poj.org/problem?id=2965 [算法] 位运算 [代码] #include <algorithm> #include <bitset&g ...
- poj 2965 The Pilots Brothers' refrigerator (dfs)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17450 ...
随机推荐
- http 响应头之location
<pre name="code" class="html">jrhmpt01:/root# cat login_yylc.pl use LWP::U ...
- Android使用XML全攻略(2)
Android使用XML全攻略(2) Android 是针对移动设备的一种新兴的开源操作系统和 SDK.借助它,您可以创建功能强大的移动应用程序.当您的应用程序可以访问 Web 服务时,其吸引力会 ...
- Android eng版系统烧录
这里我只能记录下过程 Android有四层,最底层的Linux是一个kernel,然后是运行时库层,驱动大部分在这两层完成,接着是Framework层,主要是Android源码,最后是在源码基础上进行 ...
- [置顶] C#扩展方法 扩你所需
通过前面的学习,了解到:使用扩展方法,可以向现有类型“添加”方法.本文将使用扩展方法来对系统类型,自定义类型及接口进行方法扩展,一睹扩展方法的风采. 1.使用扩展方法来扩展系统类型 String是c# ...
- android解决内存溢出的问题(没有从根本上解决)
Android游戏虚拟机算法JNI 尽量不要使用setImageBitmap或setImageResource或BitmapFactory.decodeResource来设置一张大图,因为这些函数在完 ...
- mysql 数据备份
一.备份数据库并下载到本地[db_backup.php] php代码: <?php // 数据库参数(此处测试,直接给定,项目中使用配置文件) $cfg_dbname = 'blog'; $cf ...
- Android应用开发基础篇(11)-----ViewFlipper
链接地址:http://www.cnblogs.com/lknlfy/archive/2012/03/01/2376067.html 一.概述 ViewFlipper这个部件是用来实现多页显示的,多页 ...
- Android应用开发基础篇(7)-----BroadcastReceiver
链接地址:http://www.cnblogs.com/lknlfy/archive/2012/02/22/2363644.html 一.概述 BroadcastReceiver,意思就是广播信息接收 ...
- 1.1. chromium源代码分析 - chromiumframe - 介绍
本人能力有效,面对chromium庞大的代码就头大.还是先由前辈的chromiumFrame入手. 1. chromeFrame概貌 chromiumFrame是前辈的心血之作,以最小化的方式抽出ch ...
- 腾讯云部署Flask应用
由于新浪云现在不免费了.而且云豆也用完了.所以去腾讯云申请了个学生云主机,一元一个月. 不过部署开发环境还是有点麻烦的,搞了好几天,终于部署成功了! 下面说部署过程: 我云主机用的是 Ubuntu 1 ...