随笔分类 -  BFS

摘要:class Solution { public int[] findOrder(int numCourses, int[][] prerequisites) { int[] indegrees=new int[numCourses]; int[][] graph=new int[numCourses][numCourses]; ... 阅读全文
posted @ 2017-11-07 04:28 Weiyu Wang 阅读(147) 评论(0) 推荐(0)
摘要:class Solution { public boolean canFinish(int numCourses, int[][] prerequisites) { int[] indegrees=new int[numCourses]; int[][] graph=new int[numCourses][numCourses]; for(... 阅读全文
posted @ 2017-11-07 02:17 Weiyu Wang 阅读(144) 评论(0) 推荐(0)
摘要:public class Solution { public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) { if(node==null) return null; Map map=new HashMap(); Queue que=new Link... 阅读全文
posted @ 2017-10-07 04:47 Weiyu Wang 阅读(131) 评论(0) 推荐(0)
摘要:class Solution { public int ladderLength(String beginWord, String endWord, List wordList) { Set dict=new HashSet(wordList); if(!dict.contains(endWord)) return 0; ... 阅读全文
posted @ 2017-10-04 05:27 Weiyu Wang 阅读(147) 评论(0) 推荐(0)
摘要:class Solution { public List> findLadders(String beginWord, String endWord, List wordList) { List> res=new ArrayList>(); Set dict=new HashSet(wordList); if(!dict.contains(... 阅读全文
posted @ 2017-10-04 05:09 Weiyu Wang 阅读(173) 评论(0) 推荐(0)
摘要:class Solution { public int jump(int[] nums) { int steps=0; int max=0; int cur=0; for(int i=0;i<nums.length-1;i++) { cur=Math.max(cur, i+nums[i... 阅读全文
posted @ 2017-09-25 07:41 Weiyu Wang 阅读(99) 评论(0) 推荐(0)
摘要:public class Solution { public List letterCombinations(String digits) { LinkedList que=new LinkedList(); if(digits.length()==0) return que; String[] btns=new S... 阅读全文
posted @ 2017-09-23 01:11 Weiyu Wang 阅读(141) 评论(0) 推荐(0)
摘要:Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 2779Accepted: 1167Special JudgeDescriptionYou are given two pots, having the volume of A and B liters respectively. The following operations ca... 阅读全文
posted @ 2009-10-11 05:09 Weiyu Wang 阅读(663) 评论(0) 推荐(0)
摘要:Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 3134Accepted: 1911DescriptionThe ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would al... 阅读全文
posted @ 2009-10-11 03:45 Weiyu Wang 阅读(1499) 评论(0) 推荐(0)
摘要:Time Limit: 1000MSMemory Limit: 10000KTotal Submissions: 4446Accepted: 1908Special JudgeDescriptionGiven a positive integer n, write a program to find out a nonzero multiple m of n whose decimal repre... 阅读全文
posted @ 2009-10-11 00:54 Weiyu Wang 阅读(913) 评论(0) 推荐(0)
摘要:Time Limit: 2000MSMemory Limit: 65536KTotal Submissions: 13066Accepted: 3968DescriptionFarmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at ... 阅读全文
posted @ 2009-10-10 23:33 Weiyu Wang 阅读(991) 评论(0) 推荐(0)
摘要:Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 5685Accepted: 2256DescriptionYou are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which... 阅读全文
posted @ 2009-10-10 13:04 Weiyu Wang 阅读(663) 评论(0) 推荐(0)
摘要:Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 2934Accepted: 1418DescriptionThe cornfield maze is a popular Halloween treat. Visitors are shown the entrance and must wander through the maze ... 阅读全文
posted @ 2009-10-10 10:36 Weiyu Wang 阅读(946) 评论(0) 推荐(0)
摘要:Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 2598Accepted: 793DescriptionThe Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. The Borg collec... 阅读全文
posted @ 2009-10-01 10:00 Weiyu Wang 阅读(836) 评论(0) 推荐(0)
摘要:POJ 2965, The Pilots Brothers' refrigeratorPOJ 1753, Flip Game这两道题类似,可转化图论的最短路径问题:顶点(Vertex)数:65536边(Edge)数:65536 * 16 / 2边的权值(Weight):1对于给定两个点, 求最短路径:由于边的权值均为1, 所以适宜采用BFS + Mark Table, 时间复杂度为O(N), N为... 阅读全文
posted @ 2009-09-27 10:24 Weiyu Wang 阅读(592) 评论(0) 推荐(0)
摘要:POJ 2965, The Pilots Brothers' refrigeratorPOJ 1753, Flip Game这两道题类似,可转化图论的最短路径问题:顶点(Vertex)数:65536边(Edge)数:65536 * 16 / 2边的权值(Weight):1对于给定两个点, 求最短路径:由于边的权值均为1, 所以适宜采用BFS + Mark Table, 时间复杂度为O(N), N为... 阅读全文
posted @ 2009-09-26 13:11 Weiyu Wang 阅读(644) 评论(0) 推荐(1)