一定要仔细算内存,,,又少写一个零。。

 #include <bits/stdc++.h>

 using namespace std;

 template<const int _n,const int _m>
struct Edge
{
struct Edge_base { int to,next,w; }e[_m]; int cnt,p[_n];
void insert(const int x,const int y,const int z)
{ e[++cnt].to=y; e[cnt].next=p[x]; e[cnt].w=z; p[x]=cnt; }
void clear() { cnt=,memset(p,,sizeof(p)); }
Edge() { clear(); } int start(const int x) { return p[x]; }
Edge_base& operator[](const int x) { return e[x]; }
}; int n,m,Dis[];
bool visited[];
Edge<,>e; void Dijkstra(const int S)
{
int i,t,temp;
typedef pair<int,int> PII;
priority_queue<PII,vector<PII>,greater<PII> >Q;
memset(Dis,0x3f,sizeof(Dis));
Dis[S]=;
Q.push(make_pair(,S));
while(!Q.empty())
{
t=Q.top().second;Q.pop();
if(visited[t])continue;
visited[t]=true;
for(i=e.start(t);i;i=e[i].next)
{
temp=e[i].to;
if(Dis[temp]>Dis[t]+e[i].w)
{
Dis[temp]=Dis[t]+e[i].w;
Q.push(make_pair(Dis[temp],temp));
}
}
}
return ;
} int Get(const int x,const int y,const int z)
{
if(x< || y>=m)return (n-)*(m-)*+;
if(x>=n || y<)return ;
return ((x-)*(m-)+y)<<|z;
} int main()
{
int i,j,x; scanf("%d%d",&n,&m); for(i=;i<=n;++i)
{
for(j=;j<m;++j)
{
scanf("%d",&x);
e.insert(Get(i,j,),Get(i-,j,),x);
e.insert(Get(i-,j,),Get(i,j,),x);
}
} for(i=;i<n;++i)
{
for(j=;j<=m;++j)
{
scanf("%d",&x);
e.insert(Get(i,j-,),Get(i,j,),x);
e.insert(Get(i,j,),Get(i,j-,),x);
}
} for(i=;i<n;++i)
{
for(j=;j<m;++j)
{
scanf("%d",&x);
e.insert(Get(i,j,),Get(i,j,),x);
e.insert(Get(i,j,),Get(i,j,),x);
}
} Dijkstra(); printf("%d\n",Dis[(n-)*(m-)*+]); return ;
}

最新文章

  1. Swift编程语言资料合集
  2. QT5中全屏显示子窗口和取消全屏的方法
  3. [PCL]4 PCL中图像匹配的几个类图
  4. SSH+DWZ、JQuery-UI ,swfobject.embedSWF属性与用法,IE下日期控件被flash控件挡住
  5. tr DEMO
  6. 常用的几种 SQLServer 分页查询方式实现
  7. ueditor的工具栏显示乱码解决方法 小问题.. 是你的页面编码与语言包js编码不符所导致的
  8. C#中String和string有什么区别
  9. 李洪强漫谈iOS开发[C语言-039]-剪刀石头布
  10. 推动Common Lisp的实际应用
  11. adb连接安卓模拟器
  12. Python之路(第十八篇)shutil 模块、zipfile模块、configparser模块
  13. TOP100summit:【分享实录】Twitter 新一代实时计算平台Heron
  14. 【转】4G18的低成本NA玩法
  15. Java的8种基本数据类型
  16. VS+QT中文乱码问题
  17. 深入了解java虚拟机(JVM) 第十二章 类加载器
  18. k8s+docker学习连接汇总
  19. C#、devExpress 的 给bandedGrid加菜单功能 :复制、粘贴的例子(转)
  20. python教程(二)&#183;数据类型

热门文章

  1. Can&#39;t install &#39;*&#39; from pristine store, because no checksum is recorded for this file (SVN报错)
  2. linux vi 块操作、多窗口
  3. 每天学点Linux命令: 管道| 与 xargs的区别
  4. 365 Water and Jug Problem 水壶问题
  5. T-SQL编程以及常用函数
  6. Cesium加载影像
  7. myeclipse中js文件报错
  8. JavaScript设计模式 (1) 原型模式
  9. Java 基础入门随笔(8) JavaSE版——静态static
  10. LockDemo 锁对象