题目: http://acm.timus.ru/problem.aspx?space=1&num=1181 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#problem/A 1181. Cutting a Painted Polygon Time limit: 1.0 second Memory limit: 64 MB There is a convex polygon with vertices painted in…
经验tips: Recursion is the best friend of tree-related problems. 一是只要遇到字符串的子序列或配准问题首先考虑动态规划DP,二是只要遇到需要求出所有可能情况首先考虑用递归. 93 - restore IP address 注: A.在return条件之前先判断valid的条件 1, max bits per partition[size() - startIndex <= (4 - parts) * 3] 2, min bit per…
QuickSort 参考<算法导论>,<C程序设计语言> #include<stdio.h> void swap(int v[], int i, int j); void view(int v[]); //主元为A[r] //partition后,A[p..i]<=A[r] //A[i+1]=A[r] //A[i+2..r]>A[r] int partition(int A[], int p, int r) { int x = A[r]; ; for(int…
乘风破浪:LeetCode真题_004_Median of Two Sorted Arrays 一.前言 说到算法,最难的就是一些需要通过分析得到一些递推公式或者有用的结论,进而用来解决问题的方法了.这些东西一方面比较难以理解,另一方面都是有着严密的数学逻辑在里面的,并且需要通过程序来实现,无疑增加了求解的困难.就比如说这次的问题,在两个已经排好序的数组之中找到中间值.这里就涉及到两个数组总长度是奇数还是偶数,如何查找的问题了. 二.Median of Two Sorted Arrays 2.1…
Discription: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Subscribe to see which companies asked this question. 思路:其实就是归并排序的最后一步归并操作.思想是递归分治,先把一个大问题分成2个子问题,然后对2个子问题的解进行合并.经过一次遍历就能找出已经有序的序列.就算是题目中给…
Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 15548 Accepted: 5054 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an…
Description: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending from to…