【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) = ...
随机推荐
- 《windows核心编程系列》十七谈谈dll
DLL全称dynamic linking library.即动态链接库.广泛应用与windows及其他系统中.因此对dll的深刻了解,对计算机软件开发专业人员来说非常重要. windows中所有API ...
- SEO:Yahoo 14条优化建议
腾讯前端设计的Leader推荐我背熟的.请大家都能好好学习,不要像我一样一扫而过,好好的记下来!不仅仅是晓得一些CSS xhtml就好了,深刻认识到很多的东西需要学习的.很早就用Firebug,但是却 ...
- [POJ2750]Potted Flower
Description The little cat takes over the management of a new park. There is a large circular statue ...
- 实现字符串的查找和替换 分类: c/c++ 2014-10-09 22:33 469人阅读 评论(0) 收藏
在字符串中查找目标字符串并将其替换为指定字符串,返回替换的次数.接口为 int find_str_replace(char *&str,const char *find_str,const c ...
- Android偏好设置(2)为应用定义一个偏好设置xml
1.Defining Preferences in XML Although you can instantiate new Preference objects at runtime, you sh ...
- poj2661Factstone Benchmark
链接 利用log函数来求解 n!<=2^k k会达到400+W 暴力就不要想了,不过可以利用log函数来做 log2(n!) = log2(1)+log2(2)+..log2(n)<=k ...
- Spring日期格式初始化
原文链接地址 一.初始化参数绑定[一种日期格式] 配置步骤: ①:在applicationcontext.xml中只需要配置一个包扫描器即可 1 2 <!-- 包扫描器 --> ...
- Angular jsonp 同源策略的问题
引用:http://www.cnblogs.com/dengzy/p/5388357.html 说到AJAX就会不可避免的面临两个问题,第一个是AJAX以何种格式来交换数据?第二个是跨域的需求如何解决 ...
- Jauery 中Ajax的几种异步请求
以下介绍Jquery中 Post Get Ajax几种异步请求的使用方法 <%@ Page Language="C#" AutoEventWireup=&q ...
- 从单机到2000万 QPS 并发的 Redis 高性能缓存实践之路
1.引言 知乎存储平台团队基于开源Redis 组件打造的知乎 Redis 平台,经过不断的研发迭代,目前已经形成了一整套完整自动化运维服务体系,提供很多强大的功能.本文作者陈鹏是该系统的负责人,本次文 ...