B. Chamber of Secrets
来源:互联网 发布:教学视频的软件 编辑:程序博客网 时间:2024/05/16 17:27
题目大意:一个二维数组存在镜子,遇到镜子可以发生折射,否则一直走,要求你从左上角到右下角,是否可以到达,至少要几个镜子
解题思路:这道题最短路二维数组用的是BFS,但是因为他有折射,也就是说我要把一个格子当作两个格子去处理,彼此之间双连通,然后从终点往回bfs求即可
#include<iostream> #include<cstdio>#include<stdio.h>#include<cstring> #include<cstdio> #include<climits> #include<cmath> #include<vector>#include <bitset>#include<algorithm> #include <queue>#include<map>using namespace std;vector<int> tu[20005];bool vis[20005];int n, m;char a[10005][10005];int lu[10005];void bfs(){int i, x, y;queue<int> qua;vis[n] = true;qua.push(n);while (!qua.empty()){x=qua.front();qua.pop();for (i = 0; i < tu[x].size(); i++){y = tu[x][i];if (vis[y] != true){vis[y] = true;qua.push(y);lu[y] = lu[x] + 1;}}}}int main(){int i, j;cin >> n >> m;memset(vis, false, sizeof(vis));memset(lu, 0, sizeof(lu));for (i = 1; i <= n; i++){for (j = 1; j <= m; j++){cin >> a[i][j];if (a[i][j] == '#'){tu[i].push_back(j + n);tu[j + n].push_back(i);}}}bfs();if (lu[1] != 0){cout << lu[1] << endl;}else{cout << -1 << endl;}}
0 0
- B. Chamber of Secrets
- Codeforces 173B Chamber of Secrets 题解
- CF 173B Chamber of Secrets 最短路
- CodeForces 173B Chamber of Secrets(最短路)
- Harry Potter and the Chamber of Secrets
- CF173B:Chamber of Secrets(最短路)
- Secrets of Great Architects
- Secrets of Firefox 1.0
- Secrets of dispatch_once
- Reversing - Secrets of Reverse Engineering
- Reversing: Secrets of Reverse Engineering
- Secrets of a Super Hacker
- Reversing Secrets of Reverse Engineering
- Secrets of the Game Business
- Secrets of the PlayStation Portable
- 21 Success Secrets of Self-Made Millionaires
- Decrypted Secrets: Methods and Maxims of Cryptology
- Secrets of RSS (Visual QuickStart Guide)
- 火遍大江南北的前端面试题[JavaScript]
- 多线程_线程调度及获取和设置线程优先级
- SDUT 3779 小Hao的播放器
- Android自定义控件之扫描动画UI
- Linux之shell脚本学习(1)简介和变量
- B. Chamber of Secrets
- 【计算机视觉】基于Shading Model(对光照变化一定不变性)的运动目标检测算法
- 在绝望中寻找希望-下篇 写给生活
- nyoj860 01背包变形-好题
- 新一代reduxUtils源码分析
- 《Head First JAVA》学习笔记(二)
- 欢迎使用CSDN-markdown编辑器
- js和jq(jquery)方法区别区分3(共三篇,详见我csdn)
- Extjs中grid前端分页使用PagingMemoryProxy【二】