B. Biridian Forest

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/329/problem/B

Description

You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.

The forest

The Biridian Forest is a two-dimensional grid consisting of r rows and c columns. Each cell in Biridian Forest may contain a tree, or may be vacant. A vacant cell may be occupied by zero or more mikemon breeders (there may also be breeders other than you in the forest). Mikemon breeders (including you) cannot enter cells with trees. One of the cells is designated as the exit cell.

The initial grid, including your initial position, the exit cell, and the initial positions of all other breeders, will be given to you. Here's an example of such grid (from the first example):

Moves

Breeders (including you) may move in the forest. In a single move, breeders may perform one of the following actions:

  • Do nothing.
  • Move from the current cell to one of the four adjacent cells (two cells are adjacent if they share a side). Note that breeders cannot enter cells with trees.
  • If you are located on the exit cell, you may leave the forest. Only you can perform this move — all other mikemon breeders will never leave the forest by using this type of movement.

After each time you make a single move, each of the other breeders simultaneously make a single move (the choice of which move to make may be different for each of the breeders).

Mikemon battle

If you and t (t > 0) mikemon breeders are located on the same cell, exactly t mikemon battles will ensue that time (since you will be battling each of those t breeders once). After the battle, all of those t breeders will leave the forest to heal their respective mikemons.

Note that the moment you leave the forest, no more mikemon battles can ensue, even if another mikemon breeder move to the exit cell immediately after that. Also note that a battle only happens between you and another breeders — there will be no battle between two other breeders (there may be multiple breeders coexisting in a single cell).

Your goal

You would like to leave the forest. In order to do so, you have to make a sequence of moves, ending with a move of the final type. Before you make any move, however, you post this sequence on your personal virtual idol Blog. Then, you will follow this sequence of moves faithfully.

Goal of other breeders

Because you post the sequence in your Blog, the other breeders will all know your exact sequence of moves even before you make your first move. All of them will move in such way that will guarantee a mikemon battle with you, if possible. The breeders that couldn't battle you will do nothing.

Your task

Print the minimum number of mikemon battles that you must participate in, assuming that you pick the sequence of moves that minimize this number. Note that you are not required to minimize the number of moves you make.

Under two situations the player could score one point.

⋅1. If you touch a buoy before your opponent, you will get one point. For example if your opponent touch the buoy #2 before you after start, he will score one point. So when you touch the buoy #2, you won't get any point. Meanwhile, you cannot touch buoy #3 or any other buoys before touching the buoy #2.

⋅2. Ignoring the buoys and relying on dogfighting to get point.
If you and your opponent meet in the same position, you can try to
fight with your opponent to score one point. For the proposal of game
balance, two players are not allowed to fight before buoy #2 is touched by anybody.

There are three types of players.

Speeder:
As a player specializing in high speed movement, he/she tries to avoid
dogfighting while attempting to gain points by touching buoys.
Fighter:
As a player specializing in dogfighting, he/she always tries to fight
with the opponent to score points. Since a fighter is slower than a
speeder, it's difficult for him/her to score points by touching buoys
when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.

There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.

Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting.
Since Asuka is slower than Shion, she decides to fight with Shion for
only one time during the match. It is also assumed that if Asuka and
Shion touch the buoy in the same time, the point will be given to Asuka
and Asuka could also fight with Shion at the buoy. We assume that in
such scenario, the dogfighting must happen after the buoy is touched by
Asuka or Shion.

The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?

Input

The first line consists of two integers: r and c (1 ≤ r, c ≤ 1000), denoting the number of rows and the number of columns in Biridian Forest. The next r rows will each depict a row of the map, where each character represents the content of a single cell:

  • 'T': A cell occupied by a tree.
  • 'S': An empty cell, and your starting position. There will be exactly one occurence of this in the map.
  • 'E': An empty cell, and where the exit is located. There will be exactly one occurence of this in the map.
  • A digit (0-9): A cell represented by a digit X means that the cell is empty and is occupied by X breeders (in particular, if X is zero, it means that the cell is not occupied by any breeder).

It is guaranteed that it will be possible for you to go from your starting position to the exit cell through a sequence of moves.

.

Output

A single line denoted the minimum possible number of mikemon battles that you have to participate in if you pick a strategy that minimize this number.

Sample Input

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

Sample Output

  1. 3

HINT

题意

题目非常长,简单理解下就是给你一个n*m的图,S表示起点,E表示终点,有数字的就是表示有多少个人在那个格子里面

然后问你有多少个人可以比你先到E这个终点

题解:

由终点开始直接爆搜就好了

代码

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<queue>
  4. using namespace std;
  5.  
  6. int dx[]={,-,,};
  7. int dy[]={,,,-};
  8. string s[];
  9. int d[][];
  10. int main()
  11. {
  12. int n,m;
  13. scanf("%d%d",&n,&m);
  14. for(int i=;i<n;i++)
  15. cin>>s[i];
  16. pair<int,int> now;
  17. pair<int,int> goal;
  18. for(int i=;i<n;i++)
  19. {
  20. for(int j=;j<m;j++)
  21. {
  22. d[i][j]=*;
  23. if(s[i][j]=='E')
  24. {
  25. now.first = i;
  26. now.second = j;
  27. d[i][j]=;
  28. }
  29. if(s[i][j]=='S')
  30. {
  31. goal.first = i;
  32. goal.second = j;
  33. }
  34. }
  35. }
  36. queue<pair<int,int> > Q;
  37. Q.push(now);
  38. while(!Q.empty())
  39. {
  40. now = Q.front();
  41. Q.pop();
  42. for(int i=;i<;i++)
  43. {
  44. pair<int,int> next = now;
  45. next.first += dx[i];
  46. next.second += dy[i];
  47. if(next.first<||next.first>=n)
  48. continue;
  49. if(next.second<||next.second>=m)
  50. continue;
  51. if(s[next.first][next.second]=='T')
  52. continue;
  53. if(d[next.first][next.second] > d[now.first][now.second] + )
  54. {
  55. d[next.first][next.second] = d[now.first][now.second] + ;
  56. Q.push(next);
  57. }
  58. }
  59. }
  60. int ans = ;
  61. int pp = d[goal.first][goal.second];
  62. for(int i=;i<n;i++)
  63. {
  64. for(int j=;j<m;j++)
  65. {
  66. //cout<<d[i][j]<<" ";
  67. if(s[i][j]<=''&&s[i][j]>=''&&d[i][j]-<pp)
  68. {
  69. ans += s[i][j]-'';
  70. }
  71. }
  72. //cout<<endl;
  73. }
  74. printf("%d\n",ans);
  75. }

Codeforces Round #192 (Div. 1) B. Biridian Forest 暴力bfs的更多相关文章

  1. [Codeforces Round #192 (Div. 2)] D. Biridian Forest

    D. Biridian Forest time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #192 (Div. 1) C. Graph Reconstruction 随机化

    C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/3 ...

  3. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  4. Codeforces Round #461 (Div. 2) B. Magic Forest

    B. Magic Forest time limit per test 1 second memory limit per test 256 megabytes Problem Description ...

  5. Codeforces Round #192 (Div. 2) (330B) B.Road Construction

    题意: 要在N个城市之间修建道路,使得任意两个城市都可以到达,而且不超过两条路,还有,有些城市之间是不能修建道路的. 思路: 要将N个城市全部相连,刚开始以为是最小生成树的问题,其实就是一道简单的题目 ...

  6. Codeforces Round #192 (Div. 2) (330A) A. Cakeminator

    题意: 如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕. //cf 192 div2 #include <stdio.h> #include & ...

  7. Codeforces Round #192 (Div. 2)

    吐槽一下,这次的CF好简单啊. 可是我为什么这么粗心这么大意这么弱.把心沉下来,想想你到底想做什么! A 题意:O(-1) 思路:O(-1) #include <iostream> #in ...

  8. Codeforces Round #192 (Div. 2) A. Cakeminator

    #include <iostream> #include <vector> using namespace std; int main(){ int r,c; cin > ...

  9. Codeforces Round #192 (Div. 2) B. Road Construction

    #include <iostream> #include <vector> using namespace std; int main(){ int n,m; cin > ...

随机推荐

  1. liux之我用过的zip解压命令

    用途说明 zip文件是一种常用的压缩文件格式,WinZip.WinRar等压缩软件都支持zip文件格式,就连java的jar包也是zip格式 的,Firefox插件xpi文件也是zip格式的.Linu ...

  2. 【转】Android SwitchButton(滑动开关)

    原文网址:http://blog.csdn.net/wangjinyu501/article/details/27961303 版本:1.0 日期:2014.5.17 2014.6.1 版权:© 20 ...

  3. .NET/ASP.NET Routing路由(深入解析路由系统架构原理)http://wangqingpei557.blog.51cto.com/1009349/1312422

    阅读目录: 1.开篇介绍 2.ASP.NET Routing 路由对象模型的位置 3.ASP.NET Routing 路由对象模型的入口 4.ASP.NET Routing 路由对象模型的内部结构 4 ...

  4. UITextField限制字数的方法

    转:http://blog.csdn.net/marujunyy/article/details/9985411 在输入东西的时候,如果想限制最大字数,可以用下面方法: - (BOOL)textFie ...

  5. HDU 5387 Clock

    题意:给一个时间,求三个时针之间的夹角,分数表示. 解法:算算算.统一了一下分母. 代码: #include<stdio.h> #include<iostream> #incl ...

  6. HDU 5878 I Count Two Three

    I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. hdu 3336 count the string(KMP+dp)

    题意: 求给定字符串,包含的其前缀的数量. 分析: 就是求所有前缀在字符串出现的次数的和,可以用KMP的性质,以j结尾的串包含的串的数量,就是next[j]结尾串包含前缀的数量再加上自身是前缀,dp[ ...

  8. linux中的livecd、liveDVD和其他安装方式简介

    下载了几种不同格式的centos版本的iso文件,从而对比下各种iso文件的差别,下载的内容如下: 下载之后,分别在虚拟机中进行安装,从而查看有何区别: 1. 使用LiveCD进行安装 在选择安装介质 ...

  9. CTS FAIL(一)

    首先简单介绍下CTS:全称Compatibility Test Suite,通过CTS测试,来检测android apk与android系统的兼容性. 最近公司release一版新的Image,但在新 ...

  10. 恒天云技术分享系列5 – 虚拟化平台性能对比(KVM & VMware)

    恒天云技术分享系列:http://www.hengtianyun.com/download-show-id-14.html 概述 本性能测试报告将详细陈述各虚拟化平台基准性能测试的主要结论和详细结果. ...