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的更多相关文章

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

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

  2. 枚举 POJ 2965 The Pilots Brothers' refrigerator

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

  3. poj 2965 The Pilots Brothers&#39; refrigerator(dfs 枚举 +打印路径)

    链接:poj 2965 题意:给定一个4*4矩阵状态,代表门的16个把手.'+'代表关,'-'代表开.当16个把手都为开(即'-')时.门才干打开,问至少要几步门才干打开 改变状态规则:选定16个把手 ...

  4. poj 2965 The Pilots Brothers' refrigerator枚举(bfs+位运算)

    //题目:http://poj.org/problem?id=2965//题意:电冰箱有16个把手,每个把手两种状态(开‘-’或关‘+’),只有在所有把手都打开时,门才开,输入数据是个4*4的矩阵,因 ...

  5. POJ 2965&&1753

    最近由于复习备考(然而考得还是很炸),很久没打题目了.现在开始刷寒假作业,不得不搞POJ 话说没有中文真的好烦啊! 先看1753 题目大意是说在一个4*4的格子中有黑白两色的棋子,你可以翻动其中的棋子 ...

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

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

  7. 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 ...

  8. 【POJ 2965】 The Pilots Brothers' refrigerator

    [题目链接] http://poj.org/problem?id=2965 [算法] 位运算 [代码] #include <algorithm> #include <bitset&g ...

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

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

随机推荐

  1. swift3.0基础语法(2)

    变量/常量,元组声明 var aaa = 0;//声明变量aaa 首次赋值时自动解析为Int类型 var aaa:Int = 0;//声明Int类型变量aaa let aaa = 0;//声明常量aa ...

  2. 封装的localstorge的插件,store.js

    封装的localstorge的插件,store.js https://github.com/marcuswestin/store.js/

  3. 解决Agent admitted failure to sign using the kye with ssh

    之前如果建立 ssh 连接,只要將公匙复制到~/.ssh/authorized_keys就可以直接登录而不需要建立密碼. 如果在使用时候出现如下信息: Agent admitted failure t ...

  4. 数字信号处理Day1自制电子音乐

    第一天的课程感觉比較简单,主要介绍Karplus-Strong Algorithm 给出方程 y[n]=αy[n−M]+x[n], x[n]是输入,M是延迟,α是衰弱系数 我们要衰减D次,总的採样数就 ...

  5. UNIX网络编程---简介

    UNIX网络编程---简介 一.           概述 a)       在编写与计算机通信的程序时,首先要确定的就是和计算机通信的协议,从高层次来确定通信由哪个程序发起以及响应在合适产生.大多数 ...

  6. ASP.NET产生随机验证码

    效果图:(Flowing) 1.项目中新建用于存储(位图)图片文件夹 图解: 2.前台可以添加一ASP.NET控件或其他任意用来展示图片标签等(如下) <div> <asp:Imag ...

  7. codeforces 622C. Optimal Number Permutation 构造

    题目链接 假设始终可以找到一种状态使得值为0, 那么两个1之间需要隔n-2个数, 两个2之间需要隔n-3个数, 两个3之间隔n-4个数. 我们发现两个三可以放到两个1之间, 同理两个5放到两个3之间. ...

  8. 【转载】python 模块 - random生成随机数模块

    随机数种子 要每次产生随机数相同就要设置种子,相同种子数的Random对象,相同次数生成的随机数字是完全相同的: random.seed(1) 这样random.randint(0,6, (4,5)) ...

  9. python3.4 使用pymssql 乱码

    问题:sqlserver数据库编码为gbk,使用python3.4+pymssql 查询,中文乱码 解决办法: conn = pymssql.connect(host="192.168.12 ...

  10. django 实现指定文件合并成压缩文件下载

    需求是在一列学生列表中选择指定的学生,然后下载他们上传的报告文档.