2901: G-险恶逃生II

时间限制: 1 Sec  内存限制: 128 MB

提交: 44  解决: 14

题目描述

    SOS!!!koha is trapped in the dangerous maze.He need your help again.
    The maze is a 2D grid consisting of n rows and m columns. Each cell in the maze may have a stone or may
be occupied by zero or more monsters. The cell that has a stone Koha(including the monsters) cannot enter. Only one of the cells is designated as the exit cell.
    Kona,including the monsters may move in the maze.In a single move,each of them may perform one of the Following actions:
    1. do nothing
    2. move from the current cell to one of the four adjacent cells.
    3. if Koha is located on the exit cell, he may leave the maze. Only he can perform this move — all Monsters will never leave the maze by using this type of movement.
    After each time Kona makes a single move,each of the monsters simultaneously make a single move ,however the choice of which move to make may be different for each of the monsters.
 
    If koha and x(x>0) monsters are located on the same cell, exactly x monsters will ensue that time(since he will be battling each of those x breeders once).After the battle, all of those x monsters will be killed.
    Now,Koha would like to leave the maze,however the monsters will all know his exact sequence of moves even before he makes his first move.All of them will move in such way that will guarentee a monster battle with Koha,if possible. The monsters that
couldn't battle him will do nothing.
 
    All right.Your task is to print the mininum number of monster battles that kona must participates in,note that you are not required to minimize the number of moves kona makes.

输入

For each case,the first line consists of two integes: n and m(1<=n,m<=1000),denoting the number of rows and the number of columns in the maze.the next n rows will echo depict a row of the map,where each character represents the content of a single cell:
'T':A cell occupied by a stone.
'S':An empty cell,and Kona's starting position.
'E':An empty cell,and where the exit is located.
A digit(0-9): A cell represented by a digit x means that the cell is empty and is occupied by x monsters(if x is zero,it means the cell is not occupied by any monsters).
 
It is guaranteed that it will be possible for Kona to leave the maze.

输出

For each case,ouput a single line denoted the mininum possible number of monster battles that koha has to participate in if you pick a strategy that minimize this number.

样例输入

5 7
000E0T3
T0TT0T0
010T0T0
2T0T0T0
0T0S000
1 4
SE23

样例输出

3
2

提示

For the second case,kona and the monsters located in (0,2) will reach
the exit cell simultaneously ,so he must kill them.
im0qianqian_站在回忆的河边看着摇晃的渡船终年无声地摆渡,它们就这样安静地画下黄昏画下清晨......

#include <iostream>
#include <cstring>
#define size 1000
using namespace std;
char map[1011][1011];
int res[1011][1011];
int x1,x2,y1,y2,n,m;
struct point
{
int x,y;
} r[size*size+11];
int dis[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};
int main()
{
void dfs();
int i,j;
int num,max=0;
while(cin>>m>>n)
{
for(i=0; i<=n+1; i++)
map[0][i]=map[m+1][i]='T';
for(i=0; i<=m+1; i++)
map[i][0]=map[i][n+1]='T';
for(i=1; i<=m; i++)
for(j=1; j<=n; j++)
{
cin>>map[i][j];
if(map[i][j]=='E')
{
x1=i;
y1=j;
}
if(map[i][j]=='S')
{
x2=i;
y2=j;
}
}
dfs();
num=res[x2][y2];
max=0;
for(i=1; i<=m; i++)
for(j=1; j<=n; j++)
if(map[i][j]>'0'&&map[i][j]<='9')
if(res[i][j]<=num&&res[i][j]!=-1)
max+=map[i][j]-'0';
cout<<max<<endl;
}
return 0;
}
void dfs()
{
int i,tail,head,xx,yy,x11,y11;
memset(res,-1,sizeof(res));
res[x1][y1]=0;
r[0].x=x1;
r[0].y=y1;
tail=1;
head=0;
while(tail != head)
{
x11=r[head].x;
y11=r[head].y;
for(i=0; i<4; i++)
{
xx=x11+dis[i][0];
yy=y11+dis[i][1];
if(map[xx][yy]!='T'&&res[xx][yy]==-1)
{
r[tail].x=xx;
r[tail].y=yy;
res[xx][yy] = 1 + res[x11][y11];
tail++;
}
}
head++;
} }

YTU 2901: G-险恶逃生II的更多相关文章

  1. G - Harmonic Number (II) 找规律--> 给定一个数n,求n除以1~n这n个数的和。n达到2^31 - 1;

    /** 题目:G - Harmonic Number (II) 链接:https://vjudge.net/contest/154246#problem/G 题意:给定一个数n,求n除以1~n这n个数 ...

  2. YTU 2899: D-险恶逃生 I

    2899: D-险恶逃生 I 时间限制: 1 Sec  内存限制: 128 MB 提交: 130  解决: 55 题目描述 Koha被邪恶的巫师困在一个m*n的矩阵当中,他被放在了矩阵的最左上角坐标( ...

  3. G - Harmonic Number (II) LightOJ - 1245

    算是一个找规律的题目吧. 枚举前sqrt(n)个数,数i出现的次数为n/i-n/(i+1),对答案的贡献为(n/i-n/(i+1))*i. 对于sqrt后边的数,可以直接由n/i获得,并且一定只出现一 ...

  4. LightOJ 1245 Harmonic Number (II)(找规律)

    http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS    ...

  5. HDU 5807 Keep In Touch DP

    Keep In Touch Problem Description   There are n cities numbered with successive integers from 1 to n ...

  6. THE SENSE OF BEAUTY

    #include<stdio.h> int main() { ][] = { " ,.:;j", " ,: i. .,:;ff", " : ...

  7. 【解题报告】zju-1030 Farmland

    原题地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=30 题目大意: 平面图有一些点和一条边,要求找这样的多边形: 1.边的 ...

  8. 凯尔卡C68全球版汽车电脑诊断仪

    产品简介: C68汽车故障诊断仪是凯尔卡公司新推出的一款集经济.简约.稳定.耐用于一体的汽车诊断设备, 该产品采用了最新的智能移植技术,集成度高:C68车型覆盖广,测试功能强大.数据准确等优点, 是目 ...

  9. poj 3735 Training little cats(矩阵快速幂,模版更权威,这题数据很坑)

    题目 矩阵快速幂,这里的模版就是计算A^n的,A为矩阵. 之前的矩阵快速幂貌似还是个更通用一些. 下面的题目解释来自 我只想做一个努力的人 @@@请注意 ,单位矩阵最初构造 行和列都要是(猫咪数+1) ...

随机推荐

  1. 【Codeforces 449A】Jzzhu and Chocolate

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 设最后行分成了x行,列分成了y列. 那么答案就是floor(n/x)floor(n/y) 然后x+y-2=k //即平均分配x行.y列 我们可 ...

  2. Python+selenium鼠标、键盘事件

    鼠标操作 现在的Web产品提供了丰富的鼠标交互方式,例如鼠标右击.双击.悬停.甚至是鼠标拖动等功能,在Webdriver中,将这些关于鼠标操作的方法封装在ActionChains类提供. 1.鼠标右击 ...

  3. python和shell获取命令行参数的区别

    一.命令行参数的取得对于一些功能性的脚本来说非常有用,不至于将功能写死在脚本中. shell的命令行参数直接用 $ 1,$2 等就可以直接获取 其中 $1 表示 第二个参数,即命令行的第一个参数,因为 ...

  4. var声明的成员变量和函数内声明的变量区别

    1.函数内部,有var声明的是局部变量,没var的,声明的全局变量. 2.在全局作用域内声明变量时,有var 和没var声明的都是全局变量,是window的属性.通过变量var声明全局对象的属性无法通 ...

  5. CodeForces 556 --Case of Fake Numbers

    B. Case of Fake Numbers time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. asp.net 引发类型为“System.OutOfMemoryException”的异常

    asp.net 引发类型为“System.OutOfMemoryException”的异常通常发生在IIS进程获取不到内存时. 临时解决方法是: 回收IIS的应用程序池. 如果要比较好的解决办法是: ...

  7. windows 配置 apache的多个站点

    windows 配置apache的多个站点 第一步打开apache的conf/extra/httpd-vhosts.conf,复制<VirtualHost></VirtualHost ...

  8. php之memcache学习

    php之memcache学习 简介: memcache是一个分布式高速缓存系统. 分布式是说可以部署在多台服务器上,实现集群效果: 高速是因为数据都是维护在内存中的: 特点和使用场景: 1.非持久化存 ...

  9. softmax函数理解

    https://www.zhihu.com/question/23765351   因为这里不太方便编辑公式,所以很多公式推导的细节都已经略去了,如果对相关数学表述感兴趣的话,请戳这里的链接Softm ...

  10. uva 10559

    记忆话搜索 DP 看了网上题解  状态方程真是巧妙 orz #include <cstdio> #include <cstdlib> #include <cmath> ...