【Codeforces 329B】Biridian Forest
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
找到出口到每个点的最短距离。
设你到出口的最短距离为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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 755C】PolandBall and Forest
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【25.64%】【codeforces 570E】Pig and Palindromes
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- Python3进行RSA2加密、解密、签名
1.python3的PyCryptodome库用于密码学,属于对PyCrypto库的扩展 Linux上安装: pip install pycryptodome Windows上安装: pip inst ...
- urllib的高级用法
Handler简介 我们可以把他理解为各种处理器,有专门处理登录验证的,有处理cookies的,有处理代理设置的.利用他们,我们几乎可以做到HTTP请求中的所有事情. 首先,介绍一下 urllib.r ...
- ACM_棋棋棋棋棋(规律题)
棋棋棋棋棋 Time Limit: 2000/1000ms (Java/Others) Problem Description: 在遥远的K次元空间,一年一度的GDUFE-GAME又开始了.每年的GD ...
- 对char类型的数组进行冒泡排序
package maopaopaixu; import java.util.Arrays; import java.util.Scanner; public class Demo02 { public ...
- 转 ORACLE-016:ora-01720 授权选项对于'xxxx'不存在
报错的情形如下, A用户:视图V_A B用户:视图V_B,并且用到了V_A C用户:需要用V_B, 授权过程, A用户下: grant select on V_A to B B用户下: grant s ...
- HBase简介(很好的梳理资料) 转
一. 简介 history started by chad walters and jim 2006.11 G release paper on BigTable 2007.2 inital HBas ...
- Elixir安装
参考:https://laravel.com/docs/5.2/elixir 1. 安装node 去这里下载 2.可以用淘宝的cnpm加速! npm install -g cnpm --registr ...
- Hibernate配置(外部配置文件方式)
配置Hibernate有2种方式,本文讲的是通过外部配置文件配置的方式 Hibernate核心配置文件 <?xml version='1.0' encoding='UTF-8'?> < ...
- C#特性的介绍及应用场景
1.特性的任务:特性就是为了支持对象添加一些自我描述的信息,不影响类封装的前提添加额外信息.如果你用这个信息,那特性就有用:如果你不需要这个信息,那么这个特性就没用. 2.特性的基类:Attribut ...
- 聊5块钱P2V
上一秒还在写代码,下一秒就跑机房干活. 这台机器产制石器时代,重启一次后再就启动不了了.这个故障处理的方式我们以后再谈. 今天聊聊啥是P2V,国人总喜欢弄些稀奇古怪的定义来证明自己技术很牛X,就跟当年 ...