【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

对于没有出现的,当成0节点就好。
所以总是认为有3个人需要走到各自的终点。
将平面图转成点边图。这样比较好枚举。
(二维变成一维,模拟的时候变量都少了一半啦)
然后每次按照要求模拟走一下就好。
(三重循环,枚举每一个人下一步走到了哪个位置即可
(注意两个0节点可以走到相同的位置->因为实际上他们都不存在);
然后用一个三元组加入队列里。
f[x][y][z]来判重就好了。
(直接用map来判重会TLE到死。。

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
#include <bits/stdc++.h>
using namespace std; typedef pair<int,pair<int,int> > piii; const int N = 256;
const int NN = 16;
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0}; int n,m,tot;
int v[3][2];
char s[NN+5][NN+5];
vector <int> g[N+10];
int dic[N+10][N+10][N+10];
queue <piii> dl; bool jue(int x,int y){
if (x==0 || y==0) return false;
if (x==y) return true;
return false;
} int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
freopen("F:\\c++source\\rush_out.txt", "w", stdout); #endif
ios::sync_with_stdio(0),cin.tie(0);
while (cin >> m>> n >> tot){
if (n==0 && m==0 && tot==0) break;
cin.get();
memset(v,0,sizeof v);
for (int i = 0;i <=N;i++) g[i].clear();
for (int i = 0;i <= N;i++) g[i].push_back(i); for (int i = 1;i <= n;i++) cin.getline(s[i]+1,N+10); for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
if (s[i][j]!='#'){
for (int k = 0;k < 4;k++){
int ti = i + dx[k],tj = j + dy[k];
if (ti >=1 && ti <= n && tj>=1 && tj<=m && s[ti][tj]!='#'){
int x = (i-1)*m+j,y = (ti-1)*m+tj;
g[x].push_back(y);
}
}
for (int k = 0;k < tot;k++){
if (s[i][j]==('a'+k)) v[k][0] = (i-1)*m+j;
if (s[i][j]==('A'+k)) v[k][1] = (i-1)*m+j;
}
} memset(dic,-1,sizeof dic); dic[v[0][0]][v[1][0]][v[2][0]] = 0;
piii temp = make_pair(v[0][0],make_pair(v[1][0],v[2][0]));
dl.push(temp);
while (!dl.empty()){
temp = dl.front();
dl.pop();
int x = temp.first,y = temp.second.first,z = temp.second.second;
for (int i = 0;i < (int)g[x].size();i++)
for (int j = 0;j < (int)g[y].size();j++)
for (int k = 0;k < (int)g[z].size();k++){
int tx = g[x][i],ty = g[y][j],tz = g[z][k];
if (jue(tx,ty) || jue(tx,tz) || jue(ty,tz)) continue;
if (!(x==0||y==0)&&x == ty && tx == y) continue;
if (!(x==0||z==0)&&x == tz && tx == z) continue;
if (!(y==0||z==0)&&y == tz && ty == z) continue; piii temp1 = make_pair(tx,make_pair(ty,tz));
if (dic[tx][ty][tz]==-1){
dic[tx][ty][tz] = dic[x][y][z] + 1;
dl.push(temp1);
}
}
}
cout << dic[v[0][1]][v[1][1]][v[2][1]] <<endl;
}
return 0;
}

【例题 7-9 UVA-1601】The Morning after Halloween的更多相关文章

  1. UVA 1601 The Morning after Halloween

    题意: 给出一个最大为16×16的迷宫图和至多3个ghost的起始位置和目标位置,求最少经过几轮移动可以使三个ghost都到达目标位置.每轮移动中,每个ghost可以走一步,也可以原地不动,需要注意的 ...

  2. UVA - 1601 The Morning after Halloween (BFS/双向BFS/A*)

    题目链接 挺有意思但是代码巨恶心的一道最短路搜索题. 因为图中的结点太多,应当首先考虑把隐式图转化成显式图,即对地图中可以相互连通的点之间连边,建立一个新图(由于每步不需要每个鬼都移动,所以每个点需要 ...

  3. UVA - 1601 The Morning after Halloween (双向BFS&单向BFS)

    题目: w*h(w,h≤16)网格上有n(n≤3)个小写字母(代表鬼).要求把它们分别移动到对应的大写字母里.每步可以有多个鬼同时移动(均为往上下左右4个方向之一移动),但每步结束之后任何两个鬼不能占 ...

  4. <<操作,&0xff以及|的巧妙运用(以POJ3523---The Morning after Halloween(UVa 1601)为例)

    <<表示左移,如a<<1表示将a的二进制左移一位,加一个0,&0xff表示取最后8个字节,如a&0xff表示取a表示的二进制中最后8个数字组成一个新的二进制数, ...

  5. [uva P1601] The Morning after Halloween

    [uva P1601] The Morning after Halloween 题目链接 非常经典的一道题目,lrj的书上也有(貌似是紫书?). 其实这题看起来就比较麻烦.. 首先要保证小鬼不能相遇, ...

  6. UVa 1601 万圣节后的早晨

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. 【UVa】1601 The Morning after Halloween(双向bfs)

    题目 题目     分析 双向bfs,对着书打的,我还调了好久.     代码 #include<cstdio> #include<cstring> #include<c ...

  8. uva 1601 poj 3523 Morning after holloween 万圣节后的早晨 (经典搜索,双向bfs+预处理优化+状态压缩位运算)

    这题数据大容易TLE 优化:预处理, 可以先枚举出5^3的状态然后判断合不合法,但是由于题目说了有很多墙壁,实际上没有那么多要转移的状态那么可以把底图抽出来,然后3个ghost在上面跑到时候就不必判断 ...

  9. 【Uva 1601】The Morning after Halloween

    [Link]: [Description] 给你一张平面图; 最多可能有3只鬼; 给出这几只鬼的初始位置; 然后,这几只鬼有各自的终点; 每秒钟,这几只鬼能同时移动到相邻的4个格子中的一个 任意两只鬼 ...

  10. UVa 1601 || POJ 3523 The Morning after Halloween (BFS || 双向BFS && 降维 && 状压)

    题意 :w*h(w,h≤16)网格上有n(n≤3)个小写字母(代表鬼).要求把它们分别移动到对应的大写字母里.每步可以有多个鬼同时移动(均为往上下左右4个方向之一移动),但每步结束之后任何两个鬼不能占 ...

随机推荐

  1. ES6学习笔记(八)第七种类型Symbol

    1.概述 ES5 的对象属性名都是字符串,这容易造成属性名的冲突.比如,你使用了一个他人提供的对象,但又想为这个对象添加新的方法(mixin 模式),新方法的名字就有可能与现有方法产生冲突.如果有一种 ...

  2. 【LeetCode-面试算法经典-Java实现】【008-String to Integer (atoi) (字符串转成整数)】

    [008-String to Integer (atoi) (字符串转成整数)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Implement atoi to co ...

  3. Apache Thrift使用总结

    使用感受 之前对Thrift的理解有点不准确,使用之后发现Thrift比想象中的要简单得多. Thrift做的事情就是跨语言的分布式RPC,通过编写.thrift文件声明接口类和方法,client调用 ...

  4. es64 const

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 65.Express---express-session

    转自:https://blog.csdn.net/zhangweiwtmdbf/article/details/50723816 第一部分 session概述 1.1 session 是什么? Ses ...

  6. JavaScript笔记(5)

    1.return 跳出当前函数 返回一个结果 <script> //return可以跳出当前函数 所以return写在函数的最后一行 function out() { return fun ...

  7. logrotate---日志分割

    logrotate命令用于对系统日志进行轮转.压缩和删除,也可以将日志发送到指定邮箱.使用logrotate指令,可让你轻松管理系统所产生的记录文件.每个记录文件都可被设置成每日,每周或每月处理,也能 ...

  8. Interrupt distribution scheme for a computer bus

    A method of handling processor to processor interrupt requests in a multiprocessing computer bus env ...

  9. 洛谷——P3384 【模板】树链剖分

    https://www.luogu.org/problem/show?pid=3384#sub 题目描述 如题,已知一棵包含N个结点的树(连通且无环),每个节点上包含一个数值,需要支持以下操作: 操作 ...

  10. JMS基础知识

    JMS规范: jms的基本构件:  连接工厂(connectionFactory):客户用来创建连接的对象.比如:activeMQ提供的ActiveMQConnectionFactory. 连接(co ...