原题:UVA 1172 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3613动态规划问题。定义: dp[i] = 右岸前i个村庄(m岸)能够与左岸(n岸)...
分类:
其他好文 时间:
2014-07-07 17:13:26
阅读次数:
260
Problem Description:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without u...
分类:
其他好文 时间:
2014-07-07 17:00:35
阅读次数:
161
Problem Description:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.Solution: 递归。 1 public List>...
分类:
其他好文 时间:
2014-07-07 16:59:12
阅读次数:
169
Problem Description:Sort a linked list using insertion sort.Solution: 1 public class Solution { 2 public ListNode insertionSortList(ListNode head)...
分类:
其他好文 时间:
2014-07-07 16:57:55
阅读次数:
117
Problem Description:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Solution: 1 public int maxPoint.....
分类:
其他好文 时间:
2014-07-07 16:55:19
阅读次数:
281
Problem Description:Sort a linked list inO(nlogn) time using constant space complexity.Solution: 1 public ListNode sortList(ListNode head) { 2 ...
分类:
其他好文 时间:
2014-07-07 16:48:00
阅读次数:
238
Problem Description:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integ...
分类:
其他好文 时间:
2014-06-30 14:32:54
阅读次数:
151
题目
Follow up for N-Queens problem.
Now, instead outputting board configurations, return the total number of distinct solutions.
方法
和上题方法一样,使用回溯法,结构基本相同,只需要返回数量。
public i...
分类:
其他好文 时间:
2014-06-30 06:24:22
阅读次数:
273
题目
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-que...
分类:
其他好文 时间:
2014-06-30 00:34:18
阅读次数:
188
题目链接:http://poj.org/problem?id=2442
题目大意:给出一个m*n的矩阵,从每一行中取出一个数相加,能得到n^m个不同的结果,要求输出其中前n项。
建立一个以n元数组为底层数组的堆,在这里,利用stl中的make_heap,pop_heap,push_heap等函数解决。
1.将第一组数据输入arr1数组,升序排序。
2.将接下来的数据输入到arr2数组中,并...
分类:
其他好文 时间:
2014-06-29 23:25:31
阅读次数:
259