码迷,mamicode.com
首页 > 其他好文 > 详细

6.14 BFS

时间:2018-06-15 22:40:09      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:路径   pac   ipa   rap   tor   代码   一个   work   component   

  1. Making A Large Island
    Input: A 2D Integer grid
    Output: the largest island when you change one 0 to 1
    Limit: can only change one 0 to 1

如何确定largest island?

暴力搜:每一个点都改一次

优化的方向: 找到较大的两个Component 之间的链接通路
被1包围的0 ? 求最值类的问题模板?

跳过

  1. Open the Lock
    起点0000, 终点target, 中间的路径有死路
    Limit: deadends + 一次变换一个数字

问题:每变一个数字就查一次deadends?
可以变的数组与实际变的数字, 最短路径问题

九章参考答案梳理:
Hashset 存所有的deadends 字符串,同时check当前start是否是deadend
声明一个queue结构和另一个新的hashset结构,向队列和hashset当中分别添加start
单独声明set是为了防止重复,优化代码的效率?
两个while循环,一个while是对所有的queue,内部的while是对于当前层的字符做遍历,

  1. Network Delay Time
    模板题目
    times[i] = (u, v, w), u是起点,v是终点,w是发送的时间
    single source all destinations shortest path
    Dijkstra‘s algorithm
    Bellman-Ford
    Floyd-Warshall

对于Comparator的理解
PriorityQueue需要声明类型 PriorityQueue

  1. Is Graph Bipartite
    Bipartite graphs
    A bipartite graph consists of sets of vertices X and Y

  2. Pacific Atlantic Water Flow

6.14 BFS

标签:路径   pac   ipa   rap   tor   代码   一个   work   component   

原文地址:https://www.cnblogs.com/kong-xy/p/9189077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!