link: http://codeforces.com/contest/330/problem/D

The discription looks so long, but the problem is simple if you can grasp the problem quickly.

  1. /*
  2. ID: zypz4571
  3. LANG: C++
  4. TASK: 192d.cpp
  5. */
  6.  
  7. #include <iostream>
  8. #include <cstdio>
  9. #include <cstdlib>
  10. #include <cstring>
  11. #include <cmath>
  12. #include <cctype>
  13. #include <algorithm>
  14. #include <queue>
  15. #include <deque>
  16. #include <queue>
  17. #include <list>
  18. #include <map>
  19. #include <set>
  20. #include <vector>
  21. #include <utility>
  22. #include <functional>
  23. #include <fstream>
  24. #include <iomanip>
  25. #include <sstream>
  26. #include <numeric>
  27. #include <cassert>
  28. #include <ctime>
  29.  
  30. #define INF 0x3f3f3f3f
  31. #define REP(i, n) for(int i=0;i<int(n);++i)
  32. #define FOR(i, a, b) for(int i=int(a);i<int(b);++i)
  33. #define DWN(i, b, a) for(int i=int(b-1);i>=int(a);--i)
  34. #define REP_1(i, n) for(int i=1;i<=int(n);++i)
  35. #define mid int m=(l+r)/2
  36. using namespace std;
  37. int dir[][] = {{,-}, {, }, {-, }, {, }};
  38. char mat[][];
  39. struct Node {
  40. int x, y, time;
  41. };
  42. Node start, end;
  43. int ans, matime[][], n, m;
  44. bool vis[][];
  45. void bfs(Node end) {
  46. queue<Node> q; q.push(end);
  47. while (!q.empty()) {
  48. Node tmp; tmp = q.front(); q.pop();
  49. REP (i, ) {
  50. int x, y;
  51. x = tmp.x + dir[i][]; y = tmp.y + dir[i][];
  52. if (x>= && x<n && y>= && y<m && mat[x][y] != 'T' && !vis[x][y]) {
  53. Node t; t.x = x; t.y = y; t.time = tmp.time + ; matime[x][y] = t.time;
  54. q.push(t); vis[x][y] = true;
  55. }
  56. }
  57. }
  58. }
  59. int main ( int argc, char *argv[] )
  60. {
  61. #ifndef ONLINE_JUDGE
  62. freopen("in.txt", "r", stdin);
  63. #endif
  64. cin>>n>>m;
  65. memset(vis, false, sizeof(vis));
  66. REP (i, n) {
  67. cin>>mat[i];
  68. REP (j, m) {
  69. if (mat[i][j] == 'E') {
  70. end.x = i, end.y = j; end.time = ;
  71. vis[i][j] = true;
  72. matime[i][j] = ;
  73. } else if (mat[i][j] == 'S') {
  74. start.x = i, start.y = j;
  75. matime[i][j] = INF;
  76. } else matime[i][j] = INF;
  77. }
  78. }
  79. bfs(end);
  80. int Time = matime[start.x][start.y], ans = ;
  81. REP (i, n) {
  82. REP (j, m) {
  83. if (isdigit(mat[i][j]) && matime[i][j] != INF) {
  84. if (Time >= matime[i][j]) ans += (mat[i][j]-'');
  85. }
  86. }
  87. }
  88. printf("%d\n", ans);
  89. return EXIT_SUCCESS;
  90. } /* ---------- end of function main ---------- */

standard dfs

codeforces 192 D的更多相关文章

  1. [Codeforces #192] Tutorial

    Link: Codeforces #192 传送门 前两天由于食物中毒现在还要每天挂一天的水 只好晚上回来随便找套题做做找找感觉了o(╯□╰)o A: 看到直接大力模拟了 但有一个更简便的方法,复杂度 ...

  2. codeforces 192 c

    link: http://codeforces.com/contest/330/problem/C broute force but you must be careful about some tr ...

  3. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

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

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

  5. Codeforces Round #192 (Div. 1) B. Biridian Forest 暴力bfs

    B. Biridian Forest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/pr ...

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

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

  7. [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 ...

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

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

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

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

随机推荐

  1. C++封装库

    1.新建项目 -> Win32项目    选择DLL , 勾选 空项目 , 点击完成. 2.本例程,使用一个CPP文件 , 及一个头文件. 其中头文件包含函数声明,CPP文件实现函数声明. 3. ...

  2. wsgi协议

    用来为server程序和app/framework程序做连接桥梁的,使server和app/framework各自发展,任意组合 上图是python3.4标准库里面,关于wsgiserver的实现.从 ...

  3. Java Bad version number in .class file

    错误信息: java.lang.UnsupportedClassVersionError: Bad version number in .class file at java.lang.ClassLo ...

  4. CCNA 6.5

    no sh (no shutdown : start the interface)   router rspf 1 network x.x.x.x x.x.x.x area 0 int (interf ...

  5. PDF创建及动态转换控件程序包ActivePDF Portfolio

    ActivePDF Portfolio是将4个activePDF最优秀的服务器产品捆绑成一个价格适中的控件程序包.它提供了开发一个完整的服务器端的PDF解决方案所需的一切. 具体功能: activeP ...

  6. greenDao 学习之坑 "java-gen" 目录下的类不能引用

    由于公司最近的项目需要频繁地操作数据库,所以选用greenDao. 网上搜了一 大堆教程,我卡在java工程运行后生成的几个类不能引用了. 看了一下区别,教程的java-gen 目录是蓝色的小框框 , ...

  7. 预写式日志WAL

    Chapter 25. 预写式日志(Write-Ahead Logging (WAL)) Table of Contents 25.1. WAL 的好处 25.2. WAL 配置 25.3. 内部 预 ...

  8. Nginx SSL配置过程

    1. 在godaddy购买了UCC SSL(最多5个域名)的SSL证书 2. 设置证书 -- 管理 -- 3. 需要制作证书申请CSR文件(在线工具制作或者openssl命令制作),保存CSR和key ...

  9. IOS 中 NSArray

    今天在做 cordova  关于处理未读条数的插件时,需要在js中传入 int 型.  但是发现所有插件 里面的参数信息都是封装在NSArry对象里面.  因此又突然想直接在NSArry获取信息的想法 ...

  10. HTML--5 JavaScript

    一.JavaScript简介 1.JavaScript是个什么东西? 它是个脚本语言,需要有宿主文件,它的宿主文件是HTML文件. 2.它与Java什么关系? 没有什么直接的联系,Java是Sun公司 ...