原题地址:https://oj.leetcode.com/problems/jump-game/题意:Given
an array of non-negative integers, you are initially positioned at the first
index of the arr...
分类:
编程语言 时间:
2014-06-12 18:04:54
阅读次数:
540
本题的树状数组稍微有点特点,就是需要所谓的离散化一下,开始听这个名称好像很神秘的,不过其实很简单。
就是把一个数组arr的值,其中的值是不连续的,变成一组连续的值,因为这样他们的顺序是不变的,所以,不影响结果。
例如:9 1 0 5 4 ->变为:5 2 1 4 3看出他们的相对位置不变的。
9和5为最大值在第一个位置,1和2为第二大的值在第二个位置,0和1在第一个位置等,看出对应顺序了吗?...
分类:
其他好文 时间:
2014-06-10 16:01:28
阅读次数:
257
计数排序条件:要排序的数组的元素必须是在一定范围的,比方是1~100。在排序之前我们必须知道数组元素的范围。思路:顾名思义:就是用一个数组来计数的。步骤:1、用一个数组来计数count[
],将要排序的数组arr[ ]的元素记为数组count[ ]数组的下标,假设数组arr[]中有两个数同样就在co...
分类:
其他好文 时间:
2014-06-10 12:56:30
阅读次数:
170
// 归并排序
void Merge1(int arr[], int p, int mid, int r)
{
int n1 = mid - p + 1;
int n2 = r - mid;
int *pLeft = new int[n1]();
int *pRight = new int[n2]();
for (int i = 0; i < n1; ++i)
{...
分类:
其他好文 时间:
2014-06-08 18:08:59
阅读次数:
190
堆排序
// 测试堆排序
// @start:调整的起点
// @end:调整的终点,在堆排序的过程中,不断地减小调整区间,end参数起作用
void SiftDown(int arr[], int start, int end)
{
int i = start;
int j = 2*i + 1; // j记录的是i结点的左孩子
int temp = arr[i];
...
分类:
其他好文 时间:
2014-06-08 16:19:45
阅读次数:
187
本题有两个考点:
1 求逆序数的性质
计算逆序数的公式, 一个数arr[i]从前面放到后面,必然会有n-arr[i]-1个数比这个大,那么就有n-arr[i]-1个逆序数增加,同时因为前面少了个arr[i]数,那么就必然有arr[i]个(加上零)数比起小的数失去一个逆序数,总共失去arr[i]个逆序数,所以新的逆序数为增加了n-arr[i]-1-arr[i]个逆序数(当然有可能是减小了,视ar...
分类:
其他好文 时间:
2014-06-08 15:52:20
阅读次数:
275
1.多项式的系数存放在数组中
# include
# include
# define max(x,y) ((x)>(y)?(x):(y))
using namespace std;
const int N=100;
struct poly
{
int arr[N];
int mexp;
};
void add(poly &a,poly &b,poly &c)
{
memset(c.ar...
分类:
其他好文 时间:
2014-06-08 02:17:57
阅读次数:
264
题目描述:从上往下打印出二叉树的每个节点,同层节点从左至右打印。输入:输入可能包含多个测试样例,输入以EOF结束。对于每个测试案例,输入的第一行一个整数n(1arr[j].num;
} if(a->arr[j].lchild != 0){ Quene[end_q++] = ...
分类:
其他好文 时间:
2014-06-07 21:56:39
阅读次数:
225
插入排序
直接插入排序
// 直接插入排序
void DirectInsertSort(int arr[], int lhs, int rhs)
{
int temp;
for (int i = lhs+1; i = 0 && temp < arr[j]...
分类:
其他好文 时间:
2014-06-07 14:31:54
阅读次数:
274
关于结构体的一个特殊用法
//写法一
struct array {
int count;
char *buf;
}
//写法二
struct array {
int count;
char buf[0];
}
如果一个buf用作一个buffer的话,这时候如果malloc一块内存,
用方法一,buf是指针的话,指向这块申请出的内存的话,这里arr...
分类:
其他好文 时间:
2014-06-07 12:13:20
阅读次数:
273