/*
现在有n项工作,知道每一项工作的开始时间和结束时间,问最多可以选择多少工作
算法设计:贪心算法,不断选择不冲突的那些结束时间最短的工作
*/
#include
#include
#define max_n 100001
using namespace std;
int N;
//first is the start of the job,and the secone is...
分类:
编程语言 时间:
2015-04-03 09:27:33
阅读次数:
142
/*
直线上有N个点,点x的位置是xi(距最左端),现在要加上标记
对于每个点,要求是在一个为R的圆的范围内需要一个点被标记
问最少需要标记多少个点
算法设计: 贪心算法设计
从左端第一点开始,距离其最远的不超过R的那个点加上标记,然后将那个
被标记的点当作第一个点,向后找那个距离其最远的不超过R的那个点,然后
加上标记,一直这样做下去直到覆盖...
分类:
其他好文 时间:
2015-04-03 00:22:30
阅读次数:
115
题目:leetcode
Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump...
分类:
编程语言 时间:
2015-04-01 17:50:59
阅读次数:
200
贪心法:贪?算法(又称贪婪算法)是指,在对问题求解时,总是做出在当前看来是最好的选择。也就是说,不从整体最优上加以考虑,他所做出的仅是在某种意义上的局部最优解。贪心算法不是对所有问题都能得到整体最优解,关键是贪?心策略的选择,选择的贪?策略必须具备?后效性,即某个状态以后的过程不会影响以前的状态,只...
分类:
编程语言 时间:
2015-03-31 22:11:10
阅读次数:
244
题目:leetcode
Longest Substring Without Repeating Characters
Given
a string, find the length of the longest substring without repeating characters. For example, the longest substring without repea...
分类:
编程语言 时间:
2015-03-29 18:08:07
阅读次数:
152
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789/*Doing Homework againTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O...
分类:
编程语言 时间:
2015-03-29 18:03:41
阅读次数:
214
转:http://blog.csdn.net/lcj_cjfykx/article/details/41691787分治算法一、基本概念 在计算机科学中,分治法是一种很重要的算法。字面上的解释是“分而治之”,就是把一个复杂的问题分成两个或更多的相同或相似的子问题,再把子问题分成更小的子问题……直到最...
分类:
编程语言 时间:
2015-03-22 01:40:13
阅读次数:
299
problem:
Given an array S of n integers, find three integers in S such that the sum is closest to a
given number, target. Return the sum of the three integers. You may assume that each input
would ...
分类:
其他好文 时间:
2015-03-19 10:12:45
阅读次数:
114
这是一个百度知道上的沙袋装箱问题。我解决这个问题的基本思路是使用贪心算法,也叫做贪婪算法。贪心算法的原则是找出当前看来是最优的解决方案。问题描述如下:有一堆沙袋,每个沙袋中都转有从1到100不等的沙子。现在要求把这堆沙袋装入容积为100的箱子中。问题是,如何用最少的箱子装这些沙袋?我的思路是这样的:...
分类:
编程语言 时间:
2015-03-17 12:21:26
阅读次数:
163
贪心算法正确性证明:1.证明贪心选择性质:经过贪心选择,可以获得最优解2.最优子结构:证明子问题最优解与贪心选择组合,结果依然是最优解?All we really need to do is argue that an optimal solution to the subproblem, comb...
分类:
编程语言 时间:
2015-03-14 16:46:02
阅读次数:
200