【宽搜】Vijos P1206 CoVH之再破难关
题目链接:
题目大意:
给你开始和结束两张4x4的01图,每次操作只能够交换相邻的两个格子(有公共边),问最少的操作步数。
题目思路:
【搜索】
这题一看就是一道BFS(宽搜),判重的时候2进制压位就好,总共16位,最大不会超过216 -1(65535)。
//
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) (a)*(a)
#define swap(a,b) (a)^=(b),(b)^=(a),(a)^=(b)
#define eps 1e-8
#define S 10000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 24
#define M 65544
using namespace std;
int n,m,cas,lll,ans;
int r[N]={,,,,,,,,,,,,,,,,};
char s1[N];
int map[][];
int dx[]={,-,,};
int dy[]={,,,-};
int s,e;
int q[M],v[M];
bool u[M];
int work()
{
int i,j,k,h,t,now,xx,yy,x;
q[]=e;h=;t=;
while(h++<t)
{
now=q[h];
if(now==s)return v[h];
for(i=;i<;i++)
{
for(j=;j<;j++)
{
for(k=;k<;k++)
{
xx=i+dx[k];
yy=j+dy[k];
if(<=xx && xx< && <=yy && yy<)
{
map[i][j]=(now&r[-i*-j])>;map[xx][yy]=(now&r[-*xx-yy])>;
x=now-map[i][j]*r[-i*-j]+map[i][j]*r[-*xx-yy]+map[xx][yy]*r[-*i-j]-map[xx][yy]*r[-xx*-yy];
if(!u[x])
{
u[x]=;
q[++t]=x;
v[t]=v[h]+;
}
}
}
}
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
// while(~scanf("%d",&n) && n)
// {
for(i=,j=;i<;i++)
{
scanf("%s",s1);
for(k=;k<;k++,j--)
s+=(s1[k]-'')*r[j];
}
for(i=,j=;i<;i++)
{
scanf("%s",s1);
for(k=;k<;k++,j--)
{
e+=(s1[k]-'')*r[j];
map[i][k]=s1[k]-'';
}
}
printf("%d\n",work());
// }
return ;
} /*
// //
*/
【宽搜】Vijos P1206 CoVH之再破难关的更多相关文章
- Vijos 1206 CoVH之再破难关 [BFS] [位运算]
1.题意:一个由01组成的4*4的矩阵,可以实现相邻元素交换位置的操作,给出初试状态和目标状态,试求最少操作数的方案: 2.输入输出:输入给出初试矩阵和目标矩阵:要求输出最小操作的次数: 3.分析:输 ...
- 【宽搜】【并查集】Vijos P1015 十字绣
题目链接: https://vijos.org/p/1015 题目大意: n*m的网格,线只能在网格的顶点处才能从布的一面穿到另一面.每一段线都覆盖一个单位网格的两条对角线之一,而在绣的过程中,一针中 ...
- 【宽搜】Vijos P1360 八数码问题
题目链接: https://vijos.org/p/1360 题目大意: 3x3格子上放1~8数字,一个空位,每次空位可与上下左右交换,固定终止布局,求输入的起始布局需要几步到达终止布局 题目思路: ...
- 【宽搜】Vijos P1051 送给圣诞夜的极光
题目链接: https://vijos.org/p/1051 题目大意: 给一张‘-’和‘#’的图,规定曼哈顿距离小于等于2的‘#’属于同一图案,求图案数.[曼哈顿距离:对于A(x1,y1)和B(x2 ...
- POJ1426 Find The Multiple (宽搜思想)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24768 Accepted: 102 ...
- 【拓扑】【宽搜】CSU 1084 有向无环图 (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1804 题目大意: 一个有向无环图(DAG),有N个点M条有向边(N,M<=105 ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。
利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...
- Colorado Potato Beetle(CF的某道) & 鬼畜宽搜
题意: 一个人在一张大图上走,给你路径与起点,求他走出的矩形面积并.(大概这个意思自行百度标题... SOL: 与其说这是一道图论题不如说是一道生动活泼的STL-vector教学.... 离散化宽搜, ...
随机推荐
- python-集合(第二篇(七):集合)
第二篇(七):集合 python 集合 集合标准操作 摘要: 说明: ·类似于数学中学的集合,Python中的集合可以实现去重的功能,通过set()函数来实现: ·sets支持x in set, ...
- python之enumerate枚举 第二篇(六):enumerate枚举
[Python之旅]第二篇(六):enumerate枚举 python enumerate枚举 摘要: 1.普通情况下打印列表中索引号及其对应元素 使用下面的循环: 1 2 3 4 5 6 ...
- 关于移动端的Click事件
在移动端执行Click事件,通常情况出现有300毫秒的延迟,为防止这种不必要的延迟效果,我们可以换种方式来实现,同样达到快速执行Click事件的效果. 先了解一下移动端Click的执行顺序: touc ...
- SGU 186.The Chain
看懂题就是水题... code #include <iostream> #include <algorithm> using namespace std; int a[110] ...
- Mac开机黑屏解决办法
开机黑屏问题 *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !import ...
- Linux内存点滴:用户进程内存空间
原文出处:PerfGeeks 经常使用top命令了解进程信息,其中包括内存方面的信息.命令top帮助文档是这么解释各个字段的.VIRT , Virtual Image (kb)RES, Residen ...
- jQuery-弹窗登录
在jQuery中实现弹窗常要用到的方法有: width() :元素的宽度 outerWidth() 元素的宽度 盒子的padding+border 总的宽度 scrollTop() 鼠标滚轮自上 ...
- An erroroccurred while filtering resources
maven报错: maven An error occurred while filtering resources Maven -> Update Project... resolved th ...
- 【面霸1】php知识点
PHP简介 Hypertext Preprocessor,超文本预处理器的缩写,主要是用于服务端的脚本程序 PHP 标记风格 1.xml风格 < ? php ? > 2.脚本风格 & ...
- web字体格式转换
@font-face { font-family: 'emotion'; src: url('emotion.eot'); /* IE9*/ src: url('emotion.eot?#iefix' ...