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

【题意】

题意

【题解】

找到出口到每个点的最短距离。
设你到出口的最短距离为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. poj 3281 Dining (最大网络流)

    题目链接: http://poj.org/problem?id=3281 题目大意: 有n头牛,f种食物,d种饮料,第i头牛喜欢fi种食物和di种饮料,每种食物或者饮料被一头牛选中后,就不能被其他的牛 ...

  2. 贪心 HDOJ 5385 The Path

    题目传送门 /* 题意:给一张图和一些有向边,问如何给边赋值使得d1 < d2 < .. < dx > ,,,< ddn 贪心:左边从2开始,右边从n开始,每次选择未标记 ...

  3. Java中的流(4)InputStream,InputStreamReader,BufferedReader关系

    InputStream是字节流,InputStreamReader将字节流转成字符流,BufferedReader将字符流转成字符缓冲,开始读字符. 1.InputStream.OutputStrea ...

  4. InputStream和OutputStream的一遍博客 分析非常到位

    http://www.cnblogs.com/springcsc/archive/2009/12/03/1616187.html

  5. mysql各个版本下载地址

    之所记录下来是因为我找了好久才找到:这下记着了:http://downloads.mysql.com/archives/community/ 希望对没有找到的朋友有帮助

  6. 枚举Enum通过int值或文本转为对应的枚举类型

    1.数值转枚举 如果枚举类型继承了数值类型,可以直接强制转换 public enum SourceType : byte { YC = , TS = , QK = , ZQ = } //转换方式 ; ...

  7. iOS 中集成海康威视 摄像视频

    本文原文地址  http://www.cnblogs.com/qianLL/p/6652104.html 一.要导入相关的库,注意 这里比较坑的是 要用和他一样的 如果开始的工程中用了AFN或者MJE ...

  8. java设计模式之代理模式 ,以及和java 回调机制的区别

    java 代理模式就是: 将自己要做的事交给别人去做(这个别人就是代理者,自己就是被代理者),为什么自己能做的要交给别人去做了?假如一个小学生小明,现在要写作业,但是又想玩游戏,他更想玩游戏,并且不想 ...

  9. SQL将查询出来的多列的值拼接成一个字符串

    -- 单列拼接,先查出一行,再加上逗号,接着拼接 查出的下一行 SELECT GROUP_CONCAT(user_id) FROM user; -- result 160,160,160,196 -- ...

  10. testlink 从1.8.5 升级到 1.9.8

    step1:备份原 1.8.5 的数据库.   step2:分别下载 1.9.0 / 1.9.3 / 1.9.8 的安装包.   step3:分别解压 1.9.0 / 1.9.3 / 1.9.8 成3 ...