本文索引目录: 一.贪心算法的基本思想以及个人理解 二.汽车加油问题的贪心选择性质 三.一道贪心算法题点拨升华贪心思想 四.结对编程情况 一.贪心算法的基本思想以及个人理解: 1.1 基本概念: 首先我们从课本中仔细品读基本的贪心概念,顾名思义,贪心算法总是作出在当前看来最好的选择.也就是说贪心算法并不从整体最优考虑,它所作出的选择只是在某种意义上的局部最优选择.当然,希望贪心算法得到的最终结果也是整体最优的.虽然贪心算法不能对所有问题都得到整体最优解,但对许多问题它能产生整体最优解.如单源最短…
Description   Most financial institutions had become insolvent during financial crisis and went bankrupt or were bought by larger institutions, usually by banks. By the end of financial crisis of all the financial institutions only two banks still co…
原题poj 2299:http://poj.org/problem?id=2299 题意,给你一个数组,去统计它们的逆序数,由于题目中说道数组最长可达五十万,那么O(n^2)的排序算法就不要再想了,归并排序~~~ 这里列出归并的解法: #include"iostream" using namespace std; const int maxn=500000+10; int T[maxn]; int a[maxn]; long long sum; void merge_sort(int…
Description   There are N<tex2html_verbatim_mark> marbles, which are labeled 1, 2,..., N<tex2html_verbatim_mark> . The N<tex2html_verbatim_mark> marbles are put in a circular track in an arbitrary order. In the top part of the track ther…
A permutation on the integers from 1 to n is, simply put, a particular rearrangement of these integers. Your task is to generate a given permutation from the initial arrangement 1, 2, 3, . . . , n using only two simple operations. •  Operation 1: You…
原题:poj3061 题意:给你一个数s,再给出一个数组,要求你从中选出m个连续的数,m越小越好,且这m个数之和不小于s 这是一个二分查找优化题,那么区间是什么呢?当然是从1到数组长度了.比如数组长度为10,你先找5,去枚举每一个区间为5的连续的数,发现存在这样的数,那么就可以继续往左找,反之则往右找,直到左右区间重合,即为正确答案,(有可能是右区间小于左区间,所以每次都应该求区间中点值) #include"iostream" #include"set" #incl…
原题:UVA11078 题意:给你一个数组,设a[],求一个m=a[i]-a[j],m越大越好,而且i必须小于j 怎么求?排序?要求i小于j呢.枚举?只能说超时无上限.所以遍历一遍数组,设第一个被减数为a[0],之后遇到比a[0]大的数就更新它,再拿这个被减数去减数组中的每一个元素,同时也要不断地更新这个m值. #include"iostream" #include"set" #include"cstring" #include"cst…
UVA 11572 唯一的雪花 题意:给你从1到n的数组,要求求得其中的最长连续不重复子序列,经典的滑窗问题,方法是维护一个窗口,设置左框和右框,然后不断的进行维护和更新 方法一: #include"iostream" #include"set" #include"cstring" #include"cstdio" #include"algorithm" using namespace std; const…
Description Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is ei…
UVA10382 :http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21419 只能说这道题和D题是一模一样的,不过要进行转化,这道题有一道坑,方法一需要使用scanf()输入,还需判断输入的正确性,即scanf()==3..... 方法一: #include"iostream" #include"cstdio" #include"algorithm" #include&qu…