Description

  Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.
Yifenfei’s home is at the countryside, but Merceki’s home is
in the center of city. So yifenfei made arrangements with Merceki to
meet at a KFC. There are many KFC in Ningbo,  they want to choose one
that let the total time to it be most smallest.

  Now give you a Ningbo map, Both yifenfei and Merceki can move up, down ,left, right to the adjacent road by cost 11 minutes.

  就是求两个人到某一个KFC的最小值,这个题记得以前做的时候被坑惨了,要注意初始化为INF,以及说人的起始位置要表示为可通过。

代码如下:

#include<iostream>
#include<cstring> using namespace std; const int INF=1e7; short map1[][];
int que[],las,fir;
int ans[][];
int ans1[][];
int N,M;
int couKFC,Si,Sj,Ei,Ej; bool judge(int x,int y,int (*rem)[])
{
if(x<=||y<=||x>N||y>M)
return ; if(rem[x][y]!=INF)
return ; if(map1[x][y]==)
return ; return ;
} void bfs(int x,int y,int (*rem)[])
{
las=fir=;
int cou=;
int temp,t1,t2; que[las++]=x*+y;
rem[x][y]=; while(las-fir)
{
temp=que[fir++];
t1=temp/;
t2=temp%;
temp=rem[t1][t2]; if(map1[t1][t2]==)
++cou; if(cou>=couKFC)
return; --t1;
if(judge(t1,t2,rem))
{
rem[t1][t2]=temp+;
que[las++]=t1*+t2;
}
t1+=;
if(judge(t1,t2,rem))
{
rem[t1][t2]=temp+;
que[las++]=t1*+t2;
}
--t1;
--t2;
if(judge(t1,t2,rem))
{
rem[t1][t2]=temp+;
que[las++]=t1*+t2;
}
t2+=;
if(judge(t1,t2,rem))
{
rem[t1][t2]=temp+;
que[las++]=t1*+t2;
}
}
} int slove()
{
bfs(Si,Sj,ans);
bfs(Ei,Ej,ans1); int minn=INF; for(int i=;i<=N;++i)
for(int j=;j<=M;++j)
if(map1[i][j]==)
if(minn>ans[i][j]+ans1[i][j])
minn=ans[i][j]+ans1[i][j]; return minn*;
} int main()
{
ios::sync_with_stdio(false); char c; while(cin>>N>>M)
{
couKFC=; for(int i=;i<=N;++i)
for(int j=;j<=M;++j)
{
cin>>c;
ans[i][j]=ans1[i][j]=INF; switch(c)
{
case 'Y':
map1[i][j]=;
Si=i;
Sj=j;
break;
case 'M':
map1[i][j]=;
Ei=i;
Ej=j;
break;
case '.':
map1[i][j]=;
break;
case '#':
map1[i][j]=;
break;
case '@':
map1[i][j]=;
++couKFC;
break;
}
} cout<<slove()<<endl;
} return ;
}

最新文章

  1. 三、基于hadoop的nginx访问日志分析--计算时刻pv
  2. java实现Haffman编码
  3. 黄永成-thinkphp讲解-个人博客讲解26集
  4. EF Core 1.0中使用Include的小技巧
  5. iOS开发工程师面试知识点汇总
  6. python datetime 时间日期处理小结
  7. C# 匿名方法及Lambda表达式
  8. 解决ListView 跟ScroolView 共存 listItem.measure(0, 0) 空指针
  9. Python学习6.1_函数参数及参数传递
  10. #1042 - Can&#39;t get hostname for your address
  11. Oracle EBS-SQL (INV-3):检查仓库库存价值明细.sql
  12. Professional C# 6 and .NET Core 1.0 - What’s New in C# 6
  13. 网络编程-day2
  14. Icehouse 创建Instance代码分析
  15. LVS DR模式搭建 keepalived lvs
  16. 阿里云服务器购买 发布web项目全过程
  17. poj 3026(BFS+最小生成树)
  18. linux jar 命令使用
  19. PHP获取数组长度的方法 函数参数的比较
  20. 【Android】Eclipse自己主动编译NDK/JNI的三种方法

热门文章

  1. 【转】RestQL:现代化的 API 开发方式
  2. 转载:数位DP模板
  3. UVA - 11732 &quot;strcmp()&quot; Anyone?左兄弟右儿子trie
  4. XListview刷新和加载
  5. parseint和parsefloat总结number。隐形转换
  6. POJ 2084 Game of Connections(卡特兰数)
  7. Struts2 语法--异常处理
  8. Ubuntu 12.04 怎样安装 Google Chrome
  9. Ubuntu系统如何修改主机名
  10. POJ 1062 昂贵的聘礼详解最短路变形