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 ...
随机推荐
- STL 全特化/偏特化
template<class T> class Compare { public: static bool isEqual(const T& lh,const T& rh) ...
- 具有 CSA CCM 证明的 SOC 2 可简化 Windows Azure 客户的安全性评估过程
编辑人员注释:本文章由 Windows Azure 产品市场营销总监 Sarah Fender 撰写. 今天,我们宣布 Microsoft 的公共审计师 Deloitte 已经发布了有关 Window ...
- 12.06 JavaScript
任务 掌握JavaScript基础知识,能够使用JavaScript编写一些复杂度不大的交互功能. 任务: JavaScript基础 做完任务一的时候深深地感觉到自己的基础非常的薄弱,在这里再次感谢一 ...
- NGUI使用教程(1) 安装NGUI插件
前言 鉴于当前游戏开发的大势,Unity3d的发展势头超乎我的预期,作为一个Flash开发人员,也是为Flash在游戏开发尤其是手游开发中的地位感到担忧....所以 近期一段时间都在自己学习unity ...
- 使用LAMP创建基于wordpress的个从博客站点
參考: http://blog.csdn.net/ck_boss/article/details/27866117 一.mysql配置 1.安装mysql yum install mysql-serv ...
- Activity切换动画(overridePendingTransition)-翻页效果
Activity的切换动画指的是从一个activity跳转到另外一个activity时的动画.{它包括两个部分:一部分是第一个activity退出时的动画:另外一部分时第二个activity进入时的动 ...
- 将Oracle数据库导出为txt格式
将Oracle数据库导出为txt格式: 方法1: 对于Windows系统,可以采用以下方式: 选择控制面板-->管理工具-->数据源(ODBC),添加一个新的数据源(系统或用户DSN均可) ...
- PGA_AGGREGATE_TARGET 原理
PGA_AGGREGATE_TARGET参数的理解 PGA结构图: 在Oracle9i之前,PGA的计算和控制都是比较复杂的事情,从 ...
- 清除缓存、开启IO统计
SQL性能优化前期准备-清除缓存.开启IO统计 如果需要进行SQl Server下的SQL性能优化,需要准备以下内容: 一.SQL查询分析器设置: 1.开启实际执行计划跟踪. 2.每次执行需优化SQL ...
- mybatis+postgresql平台
mybatis+postgresql平台 最近有个项目的数据库使用postgresql,使用原生态的mybatis操作数据,原生态的没什么不好,只不过国内有个tk.mybatis的工具帮 ...