【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

找到出口到每个点的最短距离。
设你到出口的最短距离为temp
那么如果某个人到终点的距离temp,那么他们肯定不可能在某个时刻和你遇到
因为如果可以在某个时刻与你遇到的话,那他可以接下来跟着你走,那么他到终点的距离肯定是和你到终点的距离是一样的。
而它到终点的距离又大于你到终点的距离
产生了矛盾,所以不可能。

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = 1000; int r,c;
int a[N+10][N+10],x0,y0;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
string s[N+10];
queue<pair<int,int> > dl;
int dis[N+10][N+10]; bool bfs(int X,int Y){
dl.push({X,Y});
dis[X][Y] = 1;
while (!dl.empty()){
int x = dl.front().first,y = dl.front().second;
dl.pop();
for (int i = 0;i < 4;i++){
int tx = x + dx[i];
int ty = y + dy[i];
if (tx>=1 && tx<=r && ty>=1 && ty<=c){
if (a[tx][ty]==0 && dis[tx][ty]==0){
dis[tx][ty] = dis[x][y] + 1;
dl.push({tx,ty});
}
}
}
}
} int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> r >> c;
int x1,y1;
for (int i = 1;i <= r;i++){
cin >> s[i];
for (int j = 0;j < c;j++)
if (s[i][j]=='E'){
x0 = i;y0 = j + 1;
}else if (s[i][j]=='T'){
a[i][j+1] = 1;
}else if (s[i][j]=='S'){
x1 = i;y1 = j+1;
}
}
bfs(x0,y0);
int temp = dis[x1][y1];
int ans = 0;
for (int i = 1;i <= r;i++)
for (int j = 0;j < c;j++)
if (s[i][j]>='1' && s[i][j]<='9'){
if (dis[i][j+1]>0 && dis[i][j+1]<=temp){
ans+=(s[i][j]-'0');
}
}
cout<<ans<<endl;
return 0;
}

【Codeforces 329B】Biridian Forest的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 755C】PolandBall and Forest

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【25.64%】【codeforces 570E】Pig and Palindromes

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. Python3中使用urllib的方法详解(header,代理,超时,认证,异常处理)_python

    我们可以利用urllib来抓取远程的数据进行保存哦,以下是python3 抓取网页资源的多种方法,有需要的可以参考借鉴. 1.最简单 import urllib.request response = ...

  2. 找规律 UVALive 6506 Padovan Sequence

    题目传送门 /* 找规律:看看前10项就能看出规律,打个表就行了.被lld坑了一次:( */ #include <cstdio> #include <algorithm> #i ...

  3. ACM_数数?诶?这么简单?

    数数?诶?这么简单? Time Limit: 2000/1000ms (Java/Others) Problem Description: 当看到GDUFE-GAME宣传海报上提到"场内人员 ...

  4. 解题报告:hdu 2073 无限的路

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2073 Problem Description 甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接 ...

  5. Multitenant best Practice clone pdb seed and Clone a Pluggable Database – 12c Edition

    1. 1.Tnsnames when connecting to either Container or Pluggable instance The tnsnames.ora should be c ...

  6. CentOS系统里如何正确取消或者延长屏幕保护自动锁屏功能(图文详解)

    不多说,直接上干货! 对于我这里想说的是,分别从CentOS6.X  和  CentOS7.X来谈及. 1. 问题:默认启动屏幕保护 问题描述: CentOS系统在用户闲置一段时间(默认为5分钟)后, ...

  7. Java开发笔记(九十三)深入理解字节缓存

    前面介绍了文件通道的读写操作,其中用到字节缓存ByteBuffer,它是位于通道内部的存储空间,也是通道唯一可用的存储形式.ByteBuffer有两种构建方式,一种是调用静态方法wrap,根据输入的字 ...

  8. 原型模式及php实现

    原型模式: 通过复制已经存在的实例来返回新的实例,而不是新建实例,并且原型(被复制的实例)是可定制的:原型模式多用于创建复杂的或耗时的实例,这种情况下,复制一个已经存在的实例是程序运行更高效无疑是一种 ...

  9. CF792C Divide by Three

    思路: dp. 实现: #include <iostream> #include <cstdio> #include <cstring> #include < ...

  10. VUE 全选

    <div id="vue_det"> <p>全选:</p> <input type="checkbox" id=&qu ...