HDUOJ----(2612)Find a way
Find a way
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3177 Accepted Submission(s): 1031
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.
Each test case include, first two integers n, m. (2<=n,m<=200).
Next n lines, each line included m character.
‘Y’ express yifenfei initial position.
‘M’ express Merceki initial position.
‘#’ forbid road;
‘.’ Road.
‘@’ KCF
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<deque>
using namespace std;
const int maxn=;
typedef struct Map
{
char ss;
int x,y;
int value;
}gmap;
unsigned int dir[][]={{,},{-,},{,},{,-}}; /*·½Ïò*/
gmap bb[maxn][maxn];
int ans[maxn][maxn];
int n,m;
void bfs1(gmap a[][],int x,int y)
{
deque<gmap>q;
gmap temp;
q.push_back(a[x][y]);
while(!q.empty())
{
temp=q.front();
q.pop_front();
for(int i=;i</*&&temp.ss!='@'*/;i++)
{ if((temp.x+dir[i][])<||(temp.x+dir[i][])>=n||(temp.y+dir[i][])<||(temp.y+dir[i][])>=m) continue;
if(a[temp.x+dir[i][]][temp.y+dir[i][]].ss=='.'||a[temp.x+dir[i][]][temp.y+dir[i][]].ss=='@')
{
a[temp.x+dir[i][]][temp.y+dir[i][]].value+=temp.value+;
q.push_back(a[temp.x+dir[i][]][temp.y+dir[i][]]);
if(a[temp.x+dir[i][]][temp.y+dir[i][]].ss=='@')
{
a[temp.x+dir[i][]][temp.y+dir[i][]].ss='d';
ans[temp.x+dir[i][]][temp.y+dir[i][]]+=a[temp.x+dir[i][]][temp.y+dir[i][]].value;
}
else
a[temp.x+dir[i][]][temp.y+dir[i][]].ss='r';
}
}
}
} int main()
{
int i,j,sx1,sy1,sx2,sy2;
while(scanf("%d%d",&n,&m)!=EOF)
{
getchar();
memset(ans,,sizeof(ans));
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
scanf("%c",&bb[i][j].ss);
bb[i][j].value=;
bb[i][j].x=i;
bb[i][j].y=j;
if(bb[i][j].ss=='Y')
{
sx1=i;
sy1=j;
}
else if(bb[i][j].ss=='M')
{
sx2=i;
sy2=j;
}
}
getchar();
}
bfs1(bb,sx1,sy1);
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
bb[i][j].value=;
if(bb[i][j].ss=='d')
bb[i][j].ss='@';
else
if(bb[i][j].ss=='r')
bb[i][j].ss='.';
}
}
bfs1(bb,sx2,sy2);
int minm=INT_MAX;
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
if(bb[i][j].ss=='d'&&minm>ans[i][j])
minm=ans[i][j];
}
}
printf("%d\n",minm*);
}
return ;
}
HDUOJ----(2612)Find a way的更多相关文章
- HDU.2612 Find a way (BFS)
HDU.2612 Find a way (BFS) 题意分析 圣诞节要到了,坤神和瑞瑞这对基佬想一起去召唤师大峡谷开开车.百度地图一下,发现周围的召唤师大峡谷还不少,这对基佬纠结着,该去哪一个...坤 ...
- HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)
Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- HTML CSS 特殊字符表(转载)
转载地址:http://blog.csdn.net/bluestarf/article/details/40652011 转载原文地址:http://zhengmifan.com/news/noteb ...
- 架构设计:负载均衡层设计方案(5)——LVS单节点安装
1.概述 上篇文章<架构设计:负载均衡层设计方案(4)——LVS原理>(http://blog.csdn.net/yinwenjie/article/details/46845997),我 ...
- Microsoft SQL2000 错误代码 (@@error)
Microsoft SQL 2000 错误代码(@@error) 0 操作成功完成. 1 功能错误. 2 系统找不到指定的文件. 3 系统找不到指定的路径. 4 系统无法打开文件. 5 拒绝 ...
- android -- 蓝牙 bluetooth (三)搜索蓝牙
接上篇打开蓝牙继续,来一起看下蓝牙搜索的流程,触发蓝牙搜索的条件形式上有两种,一是在蓝牙设置界面开启蓝牙会直接开始搜索,另一个是先打开蓝牙开关在进入蓝牙设置界面也会触发搜索,也可能还有其它触发方式,但 ...
- js特殊符号(转)
HTML有许多特殊的字符,您对此有多少了解?平时在WEB制作中,您又有用到多少?或者说你在平时使用之时,是否也会碰到,有许多特殊字符要如何打印出来?比如说“笑脸”,比如说“版权号”.要是你用时忘记了这 ...
- TCP/UDP端口列表(WIKIpedia)
计算机之间依照互联网传输层TCP/IP协议不同的协议通信,都有不同的对应端口.所以,利用短信(datagram)的UDP,所采用的端口号码不一定和采用TCP的端口号码一样.以下为两种通信协议的端口列表 ...
- ZT android -- 蓝牙 bluetooth (三)搜索蓝牙
android -- 蓝牙 bluetooth (三)搜索蓝牙 分类: Android的原生应用分析 2013-05-31 22:03 2192人阅读 评论(8) 收藏 举报 bluetooth蓝牙s ...
- 新旧图号(图幅号)转换/计算/检查,经纬度转换计算,C#代码
图号(图幅号):地图图号是指为便于使用和管理,按照一定方法将各分幅地图进行的编号. 经常用到图号,但是在网上一直没有找到一个完整的图号转换程序,因此自己写了一个图号处理的库,分享出来.如有错误请指正. ...
随机推荐
- C++中模板单例的跨SO(DLL)问题:RTTI,typeid,static,单例
(转载请注明原创于潘多拉盒子) C++的模板可以帮助我们编写适合不同类型的模板类,给代码的复用性提供了极大的方便.近来写了一个涉及单例的C++模板类,简化下来可以归结为以下的代码: template ...
- key-value 多线程server的Linux C++实现
项目需求 整体思路 网络通信 字符解析 数据存储与查询 1 存储管理 2 数据查询 多线程 待改进未实现的想法 GitHub源代码 项目需求 设计一个基于Socket或基于HTTP的server,服务 ...
- [实时更新]jquery全部版本号下载
jquery-2.1.0 注!不再支持IE 6/7/8 直接引用地址: 开发版地址1: <script src="http://code.jquery.com/jquery-2. ...
- 前端新手如何安装webstorm ,初步搭建react项目
下载安装webstorm:配置成功: 配置成功后就可以开启webstorm项目了.(存微信收藏..) 1:在webstorm下配置node环境: 2:完成之后: React官方脚手架地址: https ...
- Git 学习(七)标签管理
Git 学习(七)标签管理 发布版本时,通常会先在版本库中打一个标签,这样,就唯一确定了打标签时刻的版本.取出某个标签的版本,就是把那个打标签的时刻的历史版本取出来.所以,标签也是版本库的一个快照. ...
- PHP自己定义安装
① 自己定义安装(先要在管理里停止apache服务,再卸载apache.再安装时不须要重新启动电脑) apache+php+mysql+phpmyadmin自行安装 我们建议大家,安装的时候安装到同一 ...
- EF实体类的枚举属性映射设计方法
public class FoundationInfo { [Column("id")] public int ID { get; set; } public InvestType ...
- visual studio2013 php
C:\Users\Administrator\AppData\Local\Microsoft\VisualStudio\12.0\Extensions\DEVSENSE\PHP Tools for V ...
- [转]DOM 中 Property 和 Attribute 的区别
angular的文档: https://angular.io/guide/template-syntax#property-binding https://blog.csdn.net/sunq1982 ...
- [CSS3]Clearfix
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="index ...