Biridian Forest CodeForces
来源:互联网 发布:ubuntu打开共享文件夹 编辑:程序博客网 时间:2024/05/16 14:00
题目链接:点我
题意:
实际上就是问有多少人可以在开始位置S之前到达终点.
思路:
逆向bfs,记录从终点开始到每个点的距离,然后找出所有的距离比起点离终点小的点,把他们的人数加起来即可.
代码:
#include<cstdio>#include<cstring>#include<cmath>#include<iostream>using namespace std;const int maxn = 1000+5;char w[maxn][maxn];bool vis[maxn][maxn];int d[maxn][maxn];struct ss{ int x, y;}q[maxn * 1000];int sx, sy, tx, ty ,ans, n, m;int dx[]={1,-1,0,0};int dy[]={0,0,1,-1};bool judge(int x,int y){ if(x > 0 && y > 0 && x <= n && y <= m &&!vis[x][y]) return true; return false;}int bfs(){ int head=0,tail =1; vis[tx][ty] = true; q[0].x = tx; q[0].y = ty; d[tx][ty] = 0; while(head<tail){ ss p = q[head++]; int step = d[p.x][p.y] + 1; for(int i = 0; i < 4; ++i){ int x = p.x + dx[i]; int y = p.y + dy[i]; if(judge(x, y)){ q[tail].x = x; q[tail++].y = y; vis[x][y] = true; d[x][y] = step; } } } return 0;}int main(){ memset(vis,false,sizeof(vis)); memset(d,127,sizeof(d)); scanf("%d %d", &n, &m); for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j){ scanf(" %c", &w[i][j]); if(w[i][j] == 'E') tx = i, ty = j; if(w[i][j] == 'S') sx = i, sy = j; if(w[i][j] == 'T') vis[i][j] = true; }ans =0; bfs(); for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) if(d[i][j] <= d[sx][sy] && w[i][j] >='0' && w[i][j] <= '9') ans += w[i][j]- '0'; printf("%d\n",ans); return 0;}
阅读全文
0 0
- codeforces Biridian Forest
- Biridian Forest CodeForces
- CodeForces - 329B 《Biridian Forest》 【反向BFS】
- Codeforces 329B Biridian Forest(BFS)
- Codeforces--192.div2.D Biridian Forest bfs
- Codeforces 330D Biridian Forest【思维+Bfs】
- Biridian Forest
- codeforces 329B B. Biridian Forest 精巧的bfs
- Codeforces Round #192 (Div. 1) B. Biridian Forest(BFS)
- codeforce 329B Biridian Forest
- Codeforces Round #192 (Div. 2) D. Biridian Forest (水bfs)
- codeforce 329B Biridian Forest(bfs)
- Codeforce ---392B Biridian Forest (BFS)
- CF 329B(Biridian Forest-贪心-非二分)
- Misha and Forest CodeForces
- Codeforces 195E Building Forest
- CodeForces 755CPolandBall and Forest
- Codeforces Round #192 (Div. 2) DBiridian Forest
- call()/apply()/bind()/FD/FE/无函数重载/基本值/引用值
- pip 相关命令的应用
- MySQL 存储过程参数用法 in, out, inout
- Centos 通过 Nginx 和 vsftpd 构建图片服务器
- API学习Random类随机数生成
- Biridian Forest CodeForces
- ActiveMQ在商城案例中的使用
- Balanced Number [数位DP]
- Word里面的大括号怎么打出来?
- 机器学习绘图(numpy和matplotlib库)
- 以此作为我博客的开始
- uva 11572 Unique Snowflakes (唯一的雪花)
- CSS 字体效果
- Tomcat启动提示(8080等)端口号被占用,(不重启电脑)解决办法