
贪心
文章平均质量分 68
xuanweiace
一个热爱算法竞赛的弱校ACMer路过。青大本,浙大硕,方向后端开发,菜鸡一枚,奋斗ing...
展开
-
【CodeForces - 746E】Numbers Exchange(贪心构造)
题干:Eugeny hasncards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of...原创 2019-10-25 13:34:51 · 394 阅读 · 0 评论 -
【CodeForces - 628C】Bear and String Distance(贪心,构造)
Description定义两个小写字母之间的距离为这两个字母在字母表中的距离,如dis(a,z)=25,dis(a,c)=2,两个长度相同串的距离为这两个串对应位置字母距离之和。现给出一个长度为n的串s和一个距离k,问是否存在一个长度为n的串ss,使得dis(s,ss)=k,如果存在任意输出一解,如果不存在则输出-1Input第一行为两个整数n,k(1<=n<=10^5,1...原创 2019-10-11 22:02:40 · 249 阅读 · 0 评论 -
【CodeForces - 999D】Equalize the Remainders(思维,贪心)
题干:You are given an array consisting ofnnintegersa1,a2,…,ana1,a2,…,an, and a positive integermm. It is guaranteed thatmmis a divisor ofnn.In a single move, you can choose any positioniibe...原创 2019-10-11 20:25:36 · 286 阅读 · 0 评论 -
NYOJ-14 会场安排问题(经典贪心,区间完全不覆盖模板)
题干:会场安排问题时间限制:3000 ms | 内存限制:65535 KB难度:4描述学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办。小刘的工作就是安排学校小礼堂的活动,每个时间最多安排一个活动。现在小刘有一些活动计划的时间表,他想尽可能的安排更多的活动,请问他该如何安排。输入第一行是一个整型数m(m<100)表示共有m组测试数据。每组测试数据...原创 2018-07-12 12:29:12 · 428 阅读 · 0 评论 -
[sicily]【1001】 会议安排(田忌赛马类贪心)
题干:N个会议要同时举行,参会人数分别为A[0], A[1], ...,A[N-1]. 现有M个会议室,会议室可容纳人数分别为B[0], B[1], ...,B[M-1]. 当A[i]<=B[j]时,可以把会议i安排在会议室j,每间会议室最多安排一个会议,每个会议最多只能安排一个会议室. 求最多安排多少个会议.1<= N, M <= 100000, 每个会议的参会人数和每间会议室...原创 2018-07-11 17:41:41 · 398 阅读 · 0 评论 -
cf#401(Div. 2)B. Game of Credit Card(田忌赛马类贪心)
题干:After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.Rules of this...原创 2018-07-12 12:19:01 · 380 阅读 · 0 评论 -
可以使用田忌赛马类贪心问题的前提(或说 如何判断题目符合田忌赛马类贪心问题)
前提就是A和B这两个数组的个数是相同的。 两个题目链接: https://blog.youkuaiyun.com/qq_41289920/article/details/81003946 另一个暂未发表、、、...原创 2018-07-12 13:36:40 · 795 阅读 · 0 评论 -
【nyist】6 喷水装置(一) (简单的贪心)
喷水装置(一)时间限制:3000 ms | 内存限制:65535 KB难度:3描述现有一块草坪,长为20米,宽为2米,要在横中心线上放置半径为Ri的喷水装置,每个喷水装置的效果都会让以它为中心的半径为实数Ri(0<Ri<15)的圆被湿润,这有充足的喷水装置i(1<i<600)个,并且一定能把草坪全部湿润,你要做的是:选择尽量少的喷水装置,把整个草坪的全部湿润。输入第一行...原创 2018-07-14 22:49:51 · 226 阅读 · 0 评论 -
贪心策略--16经典问题总结!
贪心算法编号题目1货郎担问题:货郎担问题:假定有五个城市,已知费用矩阵如下,分别从五个城市出发,然后选取一条费用最小的线路,验证这种算法不能得到最优解。贪心选择:每次选择之前没有走过的费用最少的路关键:1) 每次选择费用最小的路径走,到达后再次做出选择,相当于一个规模小一点的TSP子问题。2) 每次做出选择的时候并没有考虑以后的情况,即并没有考虑最优子结构问题。时间复杂度:O(n^2)空间复杂度:...转载 2018-07-14 22:49:41 · 1108 阅读 · 0 评论 -
区间覆盖全部类型及部分精选习题汇总详解(贪心策略)
1)区间完全覆盖问题问题描述:给定一个长度为m的区间,再给出n条线段的起点和终点(注意这里是闭区间),求最少使用多少条线段可以将整个区间完全覆盖样例:区间长度8,可选的覆盖线段[2,6],[1,4],[3,6],[3,7],[6,8],[2,4],[3,5]解题过程:1将每一个区间按照左端点递增顺序排列,拍完序后为[1,4],[2,4],[2,6],[3,5],[3,6],[3,7],[6,8]2...转载 2018-07-12 18:24:07 · 1349 阅读 · 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 t...原创 2018-07-12 23:05:01 · 294 阅读 · 0 评论 -
**【HDU - 1052】 田忌赛马(田忌赛马类贪心或双端队列)(或dp)
U - Tian Ji -- The Horse RacingHere is a famous story in Chinese history."That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse ...转载 2018-07-14 23:01:27 · 325 阅读 · 0 评论 -
【HDU - 4509】湫湫系列故事——减肥记II(合并区间模板 or 离散化标记 or 线段树)
题干:虽然制定了减肥食谱,但是湫湫显然克制不住吃货的本能,根本没有按照食谱行动! 于是,结果显而易见… 但是没有什么能难倒高智商美女湫湫的,她决定另寻对策——吃没关系,咱吃进去再运动运动消耗掉不就好了? 湫湫在内心咆哮:“我真是天才啊~\(≧▽≦)/~” 可是,大家要知道,过年回家多忙啊——帮忙家里做大扫除,看电影,看小说,高中同学聚餐,初中同学聚餐,小学同学聚餐,吃东西,睡觉,吃东西...原创 2018-07-14 15:59:52 · 255 阅读 · 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 ...原创 2018-07-26 01:18:11 · 272 阅读 · 0 评论 -
【51Nod-1100】 斜率最大(贪心)☆双排序
题干:平面上有N个点,任意2个点确定一条直线,求出所有这些直线中,斜率最大的那条直线所通过的两个点。(点的编号为1-N,如果有多条直线斜率相等,则输出所有结果,按照点的X轴坐标排序,正序输出。数据中所有点的X轴坐标均不相等,且点坐标为随机。)Input第1行,一个数N,N为点的数量。(2 <= N <= 10000) 第2 - N + 1行:具体N个点的坐标,X Y均...原创 2018-08-01 22:15:09 · 243 阅读 · 0 评论 -
【POJ - 3253】Fence Repair(贪心,时光倒流)
题干:DescriptionFarmer 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 ...原创 2018-10-27 00:55:16 · 442 阅读 · 0 评论 -
【HDU - 2546】饭卡 (dp,0-1背包,贪心思想)
电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。 Input多组数据。对于每组数据: 第一行为正整数n...原创 2018-11-03 13:00:12 · 353 阅读 · 0 评论 -
【CodeForces - 155C】Hometask (字符串,思维,贪心,熟悉句式)(总结)
题干:Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be re...原创 2018-10-03 18:03:19 · 467 阅读 · 0 评论 -
【EOJ Monthly 2018.10 - B】 莫干山奇遇 (思维构造,数学,数组,贪心)(总结)
题干:Time limit per test: 2.0 secondsMemory limit: 512 megabytes出题人当然是希望出的题目有关 oxx,于是想方设法给题目配上一些有关 oxx 的背景故事,使得它看起来不那么无趣。但有的时候却无法引入合适的小姐姐,使得 oxx 显得非常可怜。所以出题人删除了故事,只留下一个枯燥乏味的数学问题。【故事已删除】给一个长度为 ...原创 2018-11-02 16:40:31 · 278 阅读 · 0 评论 -
【HDU - 1257】最少拦截系统 (标解dp,贪心可过,最长上升子序列类问题)
题干:某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少...原创 2018-10-06 00:08:02 · 241 阅读 · 0 评论 -
【CodeForces - 1038C】Gambling (博弈问题,优先队列模拟,贪心)
题干:Two players A and B have a list of nn integers each. They both want to maximize the subtraction between their score and their opponent's score.In one turn, a player can either add to his score ...原创 2018-10-13 21:16:13 · 385 阅读 · 0 评论 -
【CodeForces-1041C】Coffee Break(贪心,STL,set二分维护,题意难,有坑,SJ题,构造)(知识点总结)
题干:Recently Monocarp got a job. His working day lasts exactly mm minutes. During work, Monocarp wants to drink coffee at certain moments: there are nn minutes a1,a2,…,ana1,a2,…,an, when he is able a...原创 2018-10-07 23:27:11 · 1136 阅读 · 0 评论 -
【HDU - 1009 】FatMouse' Trade (贪心)
题干:FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room contains J[i] pounds ...原创 2018-10-19 00:57:06 · 250 阅读 · 0 评论 -
【51Nod - 1163】最高的奖励 (贪心+优先队列 或 妙用并查集)
题干:有N个任务,每个任务有一个最晚结束时间以及一个对应的奖励。在结束时间之前完成该任务,就可以获得对应的奖励。完成每一个任务所需的时间都是1个单位时间。有时候完成所有任务是不可能的,因为时间上可能会有冲突,这需要你来取舍。求能够获得的最高奖励。Input第1行:一个数N,表示任务的数量(2 <= N <= 50000)第2 - N + 1行,每行2个数,中间用空格分隔...原创 2018-10-17 19:41:19 · 380 阅读 · 0 评论 -
【CodeForces - 985D】Sand Fortress (二分,贪心,思维构造,技巧,有坑)
题干:You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spo...原创 2018-10-20 22:53:39 · 682 阅读 · 0 评论 -
贪心算法 -- 最小延迟调度
转自:https://blog.youkuaiyun.com/bqw18744018044/article/details/80285414总结: 首先,证明贪心的时候交换论证是万能的!其次,这一点如果要满足,也就是,如果你要用交换论证法,那么首先要保证交换逆序后,对其他的没有影响!如果有影响,那就只能像【POJ - 3253】Fence Repair 这道题一样,用优先队列...转载 2018-10-31 13:25:34 · 12879 阅读 · 0 评论 -
【51Nod - 1117 】聪明的木匠 (贪心,哈夫曼树,时光倒流)
题干:一位老木匠需要将一根长的木棒切成N段。每段的长度分别为L1,L2,......,LN(1 <= L1,L2,…,LN <= 1000,且均为整数)个长度单位。我们认为切割时仅在整数点处切且没有木材损失。木匠发现,每一次切割花费的体力与该木棒的长度成正比,不妨设切割长度为1的木棒花费1单位体力。例如:若N=3,L1 = 3,L2 = 4,L3 = 5,则木棒原长为12,木匠...原创 2018-10-25 00:51:58 · 399 阅读 · 0 评论 -
【CodeForces - 589F】Gourmet and Banquet (贪心,思维,二分)
题干:A gourmet came into the banquet hall, where the cooks suggested n dishes for guests. The gourmet knows the schedule: when each of the dishes will be served.For i-th of the dishes he knows two i...原创 2018-10-30 21:58:47 · 297 阅读 · 0 评论 -
【CodeForces - 349B】Color the Fence (贪心,填数)
题干:Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to wi...原创 2018-11-04 17:02:03 · 345 阅读 · 0 评论 -
【NOIP2013积木大赛,NOIP2018铺设道路】积木大赛(思维,贪心)
题干:题目描述春春幼儿园举办了一年一度的“积木大赛”。今年比赛的内容是搭建一座宽度为nn的大厦,大厦可以看成由n块宽度为1的积木组成,第i块积木的最终高度需要是h_ihi。在搭建开始之前,没有任何积木(可以看成nn块高度为00的积木)。接下来每次操作,小朋友们可以选择一段连续区间[l, r][l,r],然后将第第LL块到第 RR 块之间(含第LL 块和第 RR块)所有积木的高度分别增...原创 2018-11-10 14:02:32 · 555 阅读 · 0 评论 -
【51Nod - 1182】完美字符串(贪心,字符串)
题干:约翰认为字符串的完美度等于它里面所有字母的完美度之和。每个字母的完美度可以由你来分配,不同字母的完美度不同,分别对应一个1-26之间的整数。约翰不在乎字母大小写(也就是说字母A和a的完美度相同)。给定一个字符串,输出它的最大可能的完美度。例如:dad,你可以将26分配给d,25分配给a,这样整个字符串完美度为77。Input输入一个字符串S(S的长度 <= 10000)...原创 2018-11-11 21:19:45 · 262 阅读 · 0 评论 -
【51Nod - 1133】不重叠的线段 (贪心)
题干:X轴上有N条线段,每条线段有1个起点S和终点E。最多能够选出多少条互不重叠的线段。(注:起点或终点重叠,不算重叠)。例如:151523233636,可以选23233636,这2条线段互不重叠。Input第1行:1个数N,线段的数量(2 <= N <= 10000) 第2 - N + 1行:每行2个数,线段的起点和终点(-10^9 <= S,E <= ...原创 2018-11-11 21:21:47 · 337 阅读 · 0 评论 -
【CodeForces - 245C 】Game with Coins (思维,贪心)
题干:Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has aicoins.Polycarpus and Vasil...原创 2018-11-08 16:51:54 · 501 阅读 · 0 评论 -
【CodeForces - 266C】Below the Diagonal (递归,子问题,贪心模拟)
题干:You are given a square matrix consisting of n rows and n columns. We assume that the rows are numbered from 1 to n from top to bottom and the columns are numbered from 1to n from left to right. S...原创 2018-11-15 22:09:02 · 521 阅读 · 0 评论 -
【51Nod - 1432】独木舟 (贪心,思维,好题)
题干:n个人,已知每个人体重。独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人。显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟? Input第一行包含两个正整数n (0 接下来n行,每行一个正整数,表示每个人的体重。体重不超过1000000000,并且每个人的体重不超过m。Output一行一个整数表示最少需要的独木舟数。...原创 2018-11-12 19:38:50 · 303 阅读 · 0 评论 -
【CodeForces - 289E 】Polo the Penguin and XOR operation (数学,异或,贪心)
题干:Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive.For permutation p = p0, p1, ..., pn, Polo has defined its beauty — number .Exp...原创 2018-11-28 14:57:10 · 312 阅读 · 0 评论 -
【CodeForces - 1082B】Vova and Trophies (贪心模拟,暴力)
题干:Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row.The beauty of the arrangement is the length of the longest subsegm...原创 2018-11-30 09:49:55 · 336 阅读 · 0 评论 -
【CodeForces - 798D】Mike and distribution (思维构造,贪心,黑科技)
题干:Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences o...原创 2018-12-01 10:47:19 · 334 阅读 · 0 评论 -
【UVA - 10020 】Minimal coverage (贪心,区间覆盖问题)
题干:(Uva题不给题干了) t组样例,每组首先给出一个M,然后给出一些线段(0 0结束),然后问怎么取能使得最少的线段覆盖区间[0, M]。Sample Input21-1 0-5 -32 50 01-1 00 10 0Sample Output010 1 解题报告: 就是个贪心啊AC代码:#include<cstdi...原创 2018-11-29 22:27:54 · 302 阅读 · 0 评论 -
【CodeForces - 140C】New Year Snowmen (贪心)
题干:As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey...原创 2018-12-08 10:30:59 · 496 阅读 · 0 评论