随笔分类 -  贪心 greedy

1
摘要:/* HDU 6000 - Wash [ 贪心 ] 题意: L 件衣服,N 个洗衣机,M 个烘干机,给出每个洗衣机洗一件衣服的时间和烘干机烘干一件衣服的时间,问需要的最少时间是多少 分析: 先求出L件衣服最优洗衣时间的数组,再求出最优烘干时间的数组 然后排序按最小值+最大值的思路贪心,取最大值 可以看成排序后两数组咬合 */ #include using namespace std; ... 阅读全文
posted @ 2017-09-08 19:44 nicetomeetu 阅读(241) 评论(0) 推荐(0)
摘要:/* HDU 6154 - CaoHaha's staff [ 构造,贪心 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 整点图,每条线只能连每个方格的边或者对角线 问面积大于n的图形最少要几条线 分析: 可以发现面积相同的情况下,每条线都连对角的菱形是最优的 再考虑如何将 面积为x^2的菱形,每次扩展一条边, 按最优扩展为面积为(x+1)^2的菱形 然后就可以... 阅读全文
posted @ 2017-08-21 17:16 nicetomeetu 阅读(218) 评论(0) 推荐(0)
摘要:思路来自 ICPCCamp 阅读全文
posted @ 2017-08-21 17:04 nicetomeetu 阅读(244) 评论(0) 推荐(0)
摘要:/* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #include using namespace std; const int N = 2e5+5; int a[N], b[N], c[N], n; int aa[N], bb[N]; bool cmp1... 阅读全文
posted @ 2017-08-20 14:47 nicetomeetu 阅读(353) 评论(0) 推荐(0)
摘要:血崩- - 阅读全文
posted @ 2017-08-13 14:38 nicetomeetu 阅读(196) 评论(0) 推荐(0)
摘要:/* HDU 6098 - Inversion [ 贪心,数论 ] | 2017 Multi-University Training Contest 6 题意: 求出所有B[i] = max(A[j]) [j % i != 0] 分析: 排个序从大到小找第一个不是它倍数的数. 至多扫倍数的个数,均摊复杂度O(nlogn) */ #include using namespace std... 阅读全文
posted @ 2017-08-11 13:33 nicetomeetu 阅读(124) 评论(0) 推荐(0)
摘要:/* HDU 6060 - RXD and dividing [ 分析,图论 ] | 2017 Multi-University Training Contest 3 题意: 给一个 n 个节点的树,要求将 2-n 号节点分成 k 部分,然后将每一部分加上节点 1, 每一个子树的 val 为最小斯坦纳树,求总的最大 val 分析: 考虑每条边下面所在的子树,大小为num 由于该子树至... 阅读全文
posted @ 2017-08-02 20:15 nicetomeetu 阅读(134) 评论(0) 推荐(0)
摘要:题意: 选择一个 m 位的二进制数字,总分为 n 个算式的答案之和。问得到最低分和最高分分别应该取哪个二进制数字 分析: 因为所有数字都是m位的,高位的权重大于低位 ,我们就从高到低考虑 ans 的每一位是取 0 还是取 1,统计该位的权重(即n个式子该位结果之和)即可。 阅读全文
posted @ 2017-03-05 15:04 nicetomeetu 阅读(399) 评论(0) 推荐(0)
摘要:题意: 给你不同的字符每个 ai 个,让你构造一些回文串,问你能达到这些回文串长度的最小值的最大值是多少 分析: 要么直接组成单链. 要么按落单的字符的数目将成对字符分摊取最短. 阅读全文
posted @ 2016-08-11 21:24 nicetomeetu 阅读(136) 评论(0) 推荐(0)
摘要:题意: 给出序列 a[] 的其中几项 ,已知序列满足非减,并且 0 <= ai <= 100, 问 (a1 + a2) / ( ∑ai)最大可能是多少 分析: 保证 a1,a2尽可能大, 其余尽可能小即可 阅读全文
posted @ 2016-08-09 19:51 nicetomeetu 阅读(185) 评论(0) 推荐(0)
摘要:题意: 给出一组数列a,问能够尽可能多的分成几段,让每一段的每一位的前缀和均 >= 0 分析: 从后往前扫,将第 i 位看作为某段最后一位 1. 若末位数字 >= 0 ,则自成一段 2. 若末位数字 < 0 ,则向前扫直到末位前缀和 >= 0 因为 末位的前缀和 >= 0, 则每一位的前缀和均 >= 阅读全文
posted @ 2016-08-08 15:37 nicetomeetu 阅读(194) 评论(0) 推荐(0)
摘要:排除所有不符合条件后根据当前位置上下界计算, 由于前面取的数肯定在之后的区间内,所以去掉已取的个数即可。 阅读全文
posted @ 2016-07-19 00:04 nicetomeetu 阅读(171) 评论(0) 推荐(0)
摘要:一棵树,结点树为n,根结点为r。每个结点都有一个权值ci,开始时间为0,每染色一个结点需要耗时1,每个结点的染色代价为ci*ti(ti为当前的时间),每个结点只有在父结点已经被染色的条件下才能被染色。求染完整棵树需要花费的最小代价。 找出当前最大子节点和其父节点合并成新的节点直到点集中只剩一个节点因 阅读全文
posted @ 2016-05-06 15:53 nicetomeetu 阅读(382) 评论(0) 推荐(0)
摘要:贪心吧 保证一维非递减的情况下,计算另一维上最少有几个非递减序列,就是答案 阅读全文
posted @ 2016-05-03 23:04 nicetomeetu 阅读(129) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-01-26 01:32 nicetomeetu 阅读(166) 评论(0) 推荐(0)
摘要:Problem Description某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的... 阅读全文
posted @ 2016-01-26 00:58 nicetomeetu 阅读(107) 评论(0) 推荐(0)
摘要:Problem DescriptionEzio Auditore is a great master as an assassin. Now he has prowled in the enemies’ base successfully. He finds that the only weapon... 阅读全文
posted @ 2016-01-26 00:36 nicetomeetu 阅读(296) 评论(0) 推荐(0)
摘要:Problem DescriptionIgnatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline o... 阅读全文
posted @ 2016-01-25 21:54 nicetomeetu 阅读(330) 评论(0) 推荐(0)
摘要:Problem Description Here is a famous story in Chinese history."That was about 2300 years ago. General Tian Ji was a high official in the country Qi. H 阅读全文
posted @ 2016-01-25 20:13 nicetomeetu 阅读(206) 评论(0) 推荐(0)
摘要:Problem DescriptionFatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.... 阅读全文
posted @ 2016-01-25 18:51 nicetomeetu 阅读(127) 评论(0) 推荐(0)

1