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

【题意】

在这里输入题意

【题解】

对于没有出现的,当成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. 学习参考《零基础入门学习Python》电子书PDF+笔记+课后题及答案

    国内编写的关于python入门的书,初学者可以看看. 参考: <零基础入门学习Python>电子书PDF+笔记+课后题及答案 Python3入门必备; 小甲鱼手把手教授Python; 包含 ...

  2. debian8平滑升级到debian9

    本文在Creative Commons许可证下发布. 首先,在升级时可以查看一下自己的版本号: uname -a ##查看内核信息 cat /etc/issue ##查看发行版本号   方法1:利用网 ...

  3. nio实现文件读取写入数据库或文件

    1.nio实现读取大文件,之后分批读取写入数据库 2.nio实现读取大文件,之后分批写入指定文件 package com.ally; import java.io.File; import java. ...

  4. [Python] Python list slice syntax fun

    # Python's list slice syntax can be used without indices # for a few fun and useful things: # You ca ...

  5. Python标准库:内置函数ascii(object)

    这个函数跟repr()函数一样,返回一个可打印的对象字符串方式表示.当遇到非ASCII码时,就会输出\x,\u或\U等字符来表示. 与Python 2版本号里的repr()是等效的函数. 样例: #a ...

  6. hdu4253 Two Famous Companies --- 二分+MST

    给n个点.m条边的图.每条边要么属于a公司,要么属于b公司.要求一颗最小生成树,条件是当中属于a公司的边数为k. 这题做法非常巧妙. 要求最小生成树,但有一定限制,搜索.贪心显然都不正确. 要是能找到 ...

  7. 如何分解json值设置到text文本框中

    <td><input type="text" id="name11"></td> //4设置访问成功返回的操作 xhr.on ...

  8. C#与Linux守护进程

    用C#编写Linux守护进程   如果要在Red Hat Enterprise Linux上将.NET Core进程作为后台进程运行,则可以创建自定义systemd单元.今天我将为.NET Core编 ...

  9. Sparse Autoencoder(二)

    Gradient checking and advanced optimization In this section, we describe a method for numerically ch ...

  10. kali之EtterCap学习

    EtterCap是一个基于ARP地址欺骗方式的网络嗅探工具,主要适用于交换局域网络.借助于EtterCap嗅探软件,渗透测试人员可以检测网络内明文数据通讯的安全性,及时采取措施,避免敏感的用户名/密码 ...