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 ...
随机推荐
- Python BeautifulSoup4 使用指南
前言: 昨天把传说中的BeautifulSoup4装上了,还没有装好的童鞋,请看本人的上一篇博客: Python3 Win7安装 BeautifulSoup,依照里面简单的步骤就能够把Beautifu ...
- iOS面试题01-多线程网络
1.面试题方向: 1>.多线程+网络 2>.项目(简历上的项目,每一个细节:技术实现细节.业务.项目周期.人数) 3>.性能优化:图片优化.内存优化(tableView的循环利用) ...
- DevExpress ASP.NET 使用经验谈(1)-XPO模型的创建
这个系列通过一些简单例子循序渐进,介绍DevExpress ASP.NET控件的使用.先来介绍一下XPO的使用,安装的DevExpress版本为DXperienceUniversal-12.2.4,使 ...
- 我的IOS学习之路(三):手势识别器
在iOS的学习中,对于手势的处理是极为重要的,如对于图片,我们经常需要进行旋转,缩放以及移动等.这里做一下总结,详见代码. - (void)viewDidLoad { [super viewDidLo ...
- oracle 11g 物理内存 - 此先决条件将测试系统物理内存总量是否至少为 922MB (944128.0KB)
- Android 开发笔记 “android调试遇到ADB server didn't ACK以及顽固的sjk_daemon进程 ”
资源来源:http://blog.csdn.net/wangdong20/article/details/20839533 做Android调试的时候经常会遇到,程序写好了,准备接上手机调试,可不一会 ...
- LATEX使用之字体颜色深浅不一
今天用Ctex写论文,发现出来的pdf在屏幕上会出现字体颜色深浅不一的现象. google一下之后,在饮水思源bbs上找到了解决方法,用latex+dvitopdf来编译就不会有这个现象了. 另外,对 ...
- [LeetCode]题解(python):130-Surrounded Regions
题目来源: https://leetcode.com/problems/surrounded-regions/ 题意分析: 给定给一个二维的板,这个板只包括‘X’和‘O’.将被‘X’包围的‘O’变成‘ ...
- [LeetCode]题解(python):095-Unique Binary Search Trees II
题目来源: https://leetcode.com/problems/unique-binary-search-trees-ii/ 题意分析: 给一个整数,返回所有中序遍历是1到n的树. 题目思路: ...
- [LeetCode]题解(python):067-Add Binary
题目来源: https://leetcode.com/problems/add-binary/ 题意分析: 这题是要将二进制相加,比如“11”,“1”,那么就返回“100”. 题目思路: 模拟加法的过 ...