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

【题意】

在这里输入题意

【题解】

对于没有出现的,当成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;
}

最新文章

  1. OEL上使用yum install oracle-validated 简化主机配置工作
  2. Mysql安装及主从复制配置
  3. SQL Server 2012故障转移的looksalive check和is alive check
  4. android必须要进行为不同分辨率设备切图
  5. freeCodeCamp:Where do I belong
  6. jquery总结05-常用事件05-触发事件
  7. jquery元素插入、删除、清空
  8. codeforces 381 D Alyona and a tree(倍增)(前缀数组)
  9. Creating a SharePoint BCS .NET Connectivity Assembly to Crawl RSS Data in Visual Studio 2010
  10. Codeforces Round #284 (Div. 1)
  11. C#Winform从页面获取数据,传入数据库
  12. Scrapy安装、爬虫入门教程、爬虫实例(豆瓣电影爬虫)
  13. asp.net mvc下ckeditor使用
  14. vmplayer中的fedora20无法进入图形界面
  15. SQL Server 数据库定时自动备份【转】
  16. MediaInfo使用简介(新版本支持HEVC)
  17. LinQ学习手册
  18. win32多线程程序设计笔记(第五章)
  19. Lua学习(5)——迭代器与泛型for
  20. 命运(经典dp)

热门文章

  1. python 多线程学习小记
  2. pwd---以绝对路径的方式显示用户当前工作目录
  3. python编写PAT 1007 Maximum Subsequence Sum(暴力 分治法 动态规划)
  4. 绕过open_basedir读文件脚本
  5. jQuery11 data() : 数据缓存
  6. vim-缓存区中打开另外一个文件的方法
  7. Vue的响应原理
  8. 关于obj.currentStyle.property、window.getComputedStyle(obj,null).property、obj.style.property的理解
  9. Impala通过JDBC方式访问
  10. JQ 实施编辑 (clone()复制行||双击编辑)