自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(15)
  • 收藏
  • 关注

转载 15.5 动态规划

15.5.1 1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <string> 5 #include <vector> 6 #include <cassert> 7 #include &...

2013-10-10 15:53:00 99

转载 15.4 动态规划

。。 转载于:https://www.cnblogs.com/leiatpku/p/3361438.html

2013-10-10 15:52:00 79

转载 15.3 动态规划

. 转载于:https://www.cnblogs.com/leiatpku/p/3361434.html

2013-10-10 15:51:00 96

转载 15.2 动态规划

15.2.1 为了计算,实现了书中的代码。 1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <string> 5 #include <vector> 6 #include <cassert&gt...

2013-10-05 11:47:00 106

转载 15.1 动态规划

15.1.1 demo code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <string> 5 #include <vector> 6 #include <cassert> 7...

2013-10-04 22:06:00 63

转载 SOLDIERS(POJ 1723)

这个题和算法书上的2.22题类似,因此y轴只要求出中位数,然后所有的点都要移动到中位数。 x轴的情况有点不同, 想了好久终于想明白了。 首先将x升序排序(因为最终的相对位置是不变的),然后设首个元素的基准点为P,则|x[0] - (p+0)| + |x[1] - (p+1)| + |x[2] - (p+2)| + ... + |x[n-1] - (p+n-1)| = |x[0]-0-...

2013-10-04 13:29:00 118

转载 算法课作业2.7(判断并寻找主元素)

性质1: 如果存在主元素的话,主元素一定是中位数。 方法1: 使用快排O(nlogn)进行排序,找到中位数,然后判断首元素是否和中位数相等、以及尾元素是否和中位数相等。 如果有一个以上的相等,则存在主元素(中位数)。 方法2: 使用O(n)的选择算法找到中位数,然后再判断中位数是不是主元素。 方法3: 性质2:如果一个数组中有主元素,则同时删除两个不相等的值,这个主元素不会改...

2013-10-03 19:14:00 269

转载 算法课作业2.5(寻找L<x<U在排好序的数组A中)

算法书的作业题: 2.5 设A是n个不同的数排好序的数组,给定L和U, L<U,设计一个算法找到A中满足L<x<U的所有的x。 利用分治的方法可以在O(lgn)的时间内找到起始下标和终止下标。 1 // 2 // main.cpp 3 // tests 4 // 5 // Created by zanglei on 13-9-...

2013-10-03 16:15:00 1338

转载 选择第k小的元素-O(n)的时间复杂度

实现了一下算法书上的例子, 在线性的时间内完成选择第k个元素。 1 /* 2 3 */ 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <string.h> 7 #include <math.h> 8 #define M...

2013-10-01 21:14:00 856

转载 quick sort实现

/*    */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int partition(int *a, int start, int end, int key) { int i = start,...

2013-10-01 18:46:00 73

转载 Quoit Design

hdu1007, 算法课的一个例子,计算几何和分治法。在hdu上ac了, zoj上死活过不了。 附代码: 1 /* 2 3 */ 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <string.h> 7 #include <mat...

2013-10-01 16:44:00 124

转载 Same Tree

1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val = x; } 8 * }...

2013-07-02 10:21:00 67

转载 Sqrt(x)

1 public class Solution { 2 public int sqrt(int x) { 3 // Start typing your Java solution below 4 // DO NOT write main() function 5 double result = x; 6 ...

2013-07-02 09:29:00 65

转载 pow(x, n)

1 public class Solution { 2 public double pow(double x, int n) { 3 // Start typing your Java solution below 4 // DO NOT write main() function 5 double resul...

2013-07-01 10:58:00 114

转载 Two Sum

1 public class Solution { 2 public int[] twoSum(int[] numbers, int target) { 3 // Start typing your Java solution below 4 // DO NOT write main() function 5 ...

2013-07-01 10:28:00 64

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除