- 博客(10)
- 资源 (11)
- 收藏
- 关注
原创 15道使用频率极高的基础算法题
1、合并排序,将两个已经排序的数组合并成一个数组,其中一个数组能容下两个数组的所有元素;合并排序一般的思路都是创建一个更大数组C,刚好容纳两个数组的元素,先是一个while循环比较,将其中一个数组A比较完成,将另一个数组B中所有的小于前一个数组A的数及A中所有的数按顺序存入C中,再将A中剩下的数存入C中,但这里是已经有一个数组能存下两个数组的全部元素,就不用在创建数组了,但只能从后往前面存,从
2015-05-26 18:59:39 1705
原创 [ACMcoder] Number Sequence
Problem Description A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n).Input The i
2015-05-26 18:58:25 1356
原创 [ACMcoder] Max Sum
Problem Description Given a sequence a[1],a[2],a[3]……a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 =
2015-05-26 18:51:48 1520
原创 [ACMcoder] Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges’ favorite time is guessing the most popular problem. When the contest i
2015-05-26 18:46:02 863
原创 [ACMcoder] Sum Problem
Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + … + n.Input The input will consist of a series o
2015-05-26 18:43:47 994
原创 [ACMcoder] A + B Problem II
Problem Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.Input The first line of the input contains an integer T(1Output F
2015-05-26 18:41:45 3980
原创 最大公约数和最小公倍数
求最小公倍数算法最小公倍数=两整数的乘积÷最大公约数求最大公约数算法辗转相除法有两整数a和b: ① a%b得余数c ② 若c=0,则b即为两数的最大公约数 ③ 若c≠0,则a=b,b=c,再回去执行①#include <iostream>#include <cmath>using namespace std;const float EPS = 0.00001;int bei(int a,
2015-05-26 18:37:34 1814
原创 [LeetCode] Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note: Given m, n satisfy the following co
2015-05-16 16:59:23 1172
原创 [LeetCode] Reverse Linked List(递归与非递归反转链表)
Reverse a singly linked list.解题思路对于非递归实现,思路是依次将从第二个结点到最后一个结点的后继设为头结点,然后将该节点设为头结点(需记住将原头结点的后继设为空)。 对于递归实现,首先反转从第二个结点到最后一个结点的链表,然后再将头结点放到已反转链表的最后,函数返回新链表的头结点。递归实现代码1//Runtime:10 msclass Solution {publ
2015-05-16 14:28:52 9791
原创 [LeetCode] Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume
2015-05-01 19:29:19 1180
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人