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

【题意】

题意

【题解】

找到出口到每个点的最短距离。
设你到出口的最短距离为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. Qt下存储读写应用程序设置的三种方法

    一.简介 用户对应用程序经常有这样的要求:要求它能记住它的settings,比如窗口大小.位置和密码等等.有三种方法可以实现: 使用注册表: 使用配置文件(.ini): 使用自定义文件(例如.txt) ...

  2. [ZJOI2011]道馆之战

    Description 口袋妖怪(又名神奇宝贝或宠物小精灵)红/蓝/绿宝石中的水系道馆需要经过三个冰地才能到达馆主的面前,冰地中的每一个冰块都只能经过一次.当一个冰地上的所有冰块都被经过之后,到下一个 ...

  3. [SPOJ375]Qtree

    Description You are given a tree (an acyclic undirected connected graph) with N nodes, and edges num ...

  4. [POI2009]SLO

    Description 对于一个1-N的排列(ai),每次你可以交换两个数ax与ay(x<>y),代价为W(ax)+W(ay) 若干次交换的代价为每次交换的代价之和.请问将(ai)变为(b ...

  5. _bzoj3223 Tyvj 1729 文艺平衡树【Splay】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3223 裸的,打个标记. #include <cstdio> #include & ...

  6. 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest

    题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...

  7. spring入门笔记-(一)、spring boot HelloWorld

    什么是spring boot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员 ...

  8. VS2012出现加载失败时的解决办法 win7同样适用

    今天更新了WIN8系统补丁,然后就出现了大量的问题,特别是经常用的软件像VS2012 老是加载失败,还说是缺少什么包一类的,弄了好长段时间终于解决了,现在将经验分享下 工具/原料 VS2012+WIN ...

  9. Oracle数据库的SQL语句之完整性约束——基础篇

    SELECT * FROM tb_clazz;SELECT * FROM tb_student; INSERT INTO tb_clazz(code,NAME,bzr) VALUES('1401',' ...

  10. 鸢尾花数据集-iris.data

    iris.data 5.1,3.5,1.4,0.2,Iris-setosa 4.9,3.0,1.4,0.2,Iris-setosa 4.7,3.2,1.3,0.2,Iris-setosa 4.6,3. ...