
贪心
Bread Sir
记录算法之路
展开
-
贪心——区间覆盖问题之区间完全覆盖最小区间数
问题:区间完全覆盖问题问题描述:给定一个长度为m的区间,再给出n个区间的起点和终点,求最少使用多少个区间可以将整个区间完全覆盖。方法:先将n个区间按照起点进行递增排序。令s表示已经覆盖到的区域。再剩下的区间中找出所有左端点小于等于当前已经覆盖到的区域的s并且右端点大于等于s的区间,取右端点最大的区间加入,直到已经覆盖全部的区域。举例:m为10 N = 7:[1,5]、[1,6]、[3,6]、原创 2017-04-28 10:14:52 · 13187 阅读 · 4 评论 -
贪心——区间覆盖问题之最大不相交覆盖问题
最大不相交覆盖问题:问题描述: 给定一个长度为m的区间,再给出n条区间的起点和终点,问题是从中选取尽量多的区间,使得每个区间都是独立的,即不和其它任何区间相交。方法先将n个区间按照右端点进行递增排序。令e为覆盖的右端点,初始化e为-1,然后对之后的区间进行判断选择,如果剩下区间的左端点大于e,那么就把此区间添加进去。经典问题:会场安排问题 问题描述 学校的小礼堂每天都会有许多活动原创 2017-04-28 10:48:43 · 2543 阅读 · 0 评论 -
POJ - 1328 Radar Installation(贪心/最大不相交覆盖)
问题描述 Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on原创 2017-04-28 13:16:33 · 577 阅读 · 0 评论 -
POJ - 3617 Best Cow Line(贪心)
《挑战程序设计》里的一题。 问题描述FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual”Farmer of the Year” competition. In this contest every farmer arranges his cows in a line and herds them past the judges.原创 2017-04-24 23:55:49 · 783 阅读 · 0 评论 -
POJ - 3253 Fence Repair(贪心)
问题描述 Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1原创 2017-04-26 00:36:07 · 318 阅读 · 0 评论 -
POJ - 3069 Saruman's Army(贪心)
问题描述Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep track of his forces, Saruman distributes seeing stones, known as palantirs, among the troops. Each p原创 2017-04-26 00:32:24 · 287 阅读 · 0 评论 -
POJ - 1018 Communication System(贪心)
问题描述We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we are free to choose from several manufacture原创 2017-04-25 23:00:19 · 383 阅读 · 0 评论 -
POJ - 2376 Cleaning Shifts(区间覆盖/贪心)
问题描述 Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things up and has divided the day in原创 2017-04-27 21:27:31 · 306 阅读 · 0 评论