http://acm.timus.ru/problem.aspx?space=1&num=1119

 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#define maxn 1010
using namespace std; int head[maxn],e,n,m;
int dir[][]={{,-},{,},{,},{-,}};
bool vis[maxn][maxn];
bool visi[maxn][maxn];
double step; struct node
{
int x,y;
double step;
}st,st1,st2; void bfs(node st)
{
queue<node>q;
st.step=0.0;
q.push(st);
memset(visi,false,sizeof(visi));
visi[st.x][st.y]=true;
while(!q.empty())
{
st1=q.front();
q.pop();
if(st1.x==m&&st1.y==n) {step=st1.step;return;}
for(int i=; i<; i++)
{
int xx=st1.x+dir[i][];
int yy=st1.y+dir[i][];
if(xx>=&&xx<=m&&yy>=&&yy<=n&&!visi[xx][yy])
{
st2.step=st1.step+100.0;
visi[xx][yy]=true;
st2.x=xx;
st2.y=yy;
q.push(st2);
}
}
if(vis[st1.x+][st1.y+]&&st1.x+<=m&&st1.y+<=n&&st1.x+>=&&st1.y+>=)
{
vis[st1.x+][st1.y+]=true;
st2.x=st1.x+;
st2.y=st1.y+;
st2.step=st1.step+sqrt()*100.0;
q.push(st2);
}
}
}
int main()
{
int k,a,b;
step=;
scanf("%d%d",&n,&m);
scanf("%d",&k);
memset(vis,false,sizeof(vis));
for(int i=; i<=k; i++)
{
scanf("%d%d",&a,&b);
vis[b][a]=true;
}
st.x=;
st.y=;
bfs(st);
printf("%.0lf\n",step);
return ;
}

ural 1119 Metro的更多相关文章

  1. 递推DP URAL 1119 Metro

    题目传送门 /* 题意:已知起点(1,1),终点(n,m):从一个点水平或垂直走到相邻的点距离+1,还有k个抄近道的对角线+sqrt (2.0): 递推DP:仿照JayYe,处理的很巧妙,学习:) 好 ...

  2. URAL 1119. Metro(BFS)

    点我看题目 题意  : 这个人在左下角,地铁在右上角,由很多格子组成的地图,每一条边都是一条路,每一条边都是100米.还有的可以走对角线,问你从起点到终点最短是多少. 思路 : 其实我想说一下,,,, ...

  3. ural 1119. Metro(动态规划)

    1119. Metro Time limit: 0.5 second Memory limit: 64 MB Many of SKB Kontur programmers like to get to ...

  4. URAL 1119. Metro(DP)

    水题. #include <cstring> #include <cstdio> #include <string> #include <iostream&g ...

  5. URAL DP第一发

    列表: URAL 1225 Flags URAL 1009 K-based Numbers URAL 1119 Metro URAL 1146 Maximum Sum URAL 1203 Scient ...

  6. URAL(DP集)

    这几天扫了一下URAL上面简单的DP 第一题 简单递推 1225. Flags #include <iostream> #include<cstdio> #include< ...

  7. 要back的题目 先立一个flag

    要back的题目 目标是全绿!back一题删一题! acmm7 1003 1004 acmm8 1003 1004 sysu20181013 Stat Origin Title Solved A Gy ...

  8. ural 1272. Non-Yekaterinburg Subway

    1272. Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to co ...

  9. wp已死,metro是罪魁祸首!

    1.这篇文章肯定会有类似这样的评论:“我就是喜欢wp,我就是喜欢metro,我就是软粉“等类似的信仰论者发表的评论. 2.2014年我写过一篇文章,windows phone如何才能在中国翻身? 我现 ...

随机推荐

  1. otl获得sql出错位置(oracle)

    项目的一个需要,要获得sql出错的位置,从而给出类似sqlplus的错误提示(如下) sql出错原因易获得,记录在otl_exception::msg,但出错位置就不是那么容易了. 默认情况下otl异 ...

  2. Sublime代码折叠

    一.显示折叠小三角 1.点击Sublime的Preferences->Setting-Default菜单,打开它的配置文件. 2.找到行 // Fold buttons are the tria ...

  3. Android打包常见错误之Export aborted because fatal lint errors were found

    打包时报如下错误: <ignore_js_op> Export aborted because fatal lint errors were found. These are listed ...

  4. Android-Uiautomator:[5]停止monkey测试

    方法/步骤 1 其实停止很简单,无非就是结束掉monkey的进程即可 如何停止呢 2 ps命令  查找uiautomator的进程 打开cmd命令行窗口 输入: adb shell ps | grep ...

  5. C primer plus 读书笔记第五章

    本章的标题是运算符,表达式和语句.主要研究如何处理数据. 示例代码展示了一个使用简单的while循环的代码,难度不大. 下面简单介绍本章的基本概念. 1.基本运算符. 基本运算符有:赋值运算符(C语言 ...

  6. linux杂谈(二十):apache服务配置

    1.apache简单介绍 ​ ​我们常常要浏览网页,提供这种服务是apache.提供apache服务的软件是httpd服务. ​ ​Apache支持許多特性,大部分通过编译的模块实现.這些特性從伺服器 ...

  7. javascript中的继承用法

    本文实例汇总了javascript关于继承的用法,希望本文所述对大家的javascript程序设计有所帮助.分享给大家供大家参考.具体如下:代码如下: /** * 实现子类继承父类,但不会产生多余的属 ...

  8. img的onerror事件

    使用场景 其实on error使用上是比较简单的. 当我们网站上出现了无效图片,而我们希望用友好的方式告诉用户,而不是显示红叉叉. w3c上解释的 定义和用法: onerror 事件会在文档或图像加载 ...

  9. dsoframer组件详细使用(aspx.net)

    近来由于工作需要,要求实现一个office文档在线编辑器 关于在线操作office 我是一点经验没有 网上查了半天资料 锁定了一款组件(ActiveX控件dsoframer,一个用C++实现的offi ...

  10. [译]一个灵活的 Trello 敏捷工作流

    [译]一个灵活的 Trello 敏捷工作流 翻译自 An Agile Trello Workflow That Keeps Tasks Flexible Getting things done 可不只 ...