贪心算法
ナナ色のブランク
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Educational Codeforces Round 91 (Rated for Div. 2) D. Berserk And Fireball
题目链接 题目大意:有一个长度为n的数组a和一个长度为m的数组b。你可以执行两种操作,花费x消除a中连续k个数,或者花费y消除a中连续两个数中较小的那个数。问最少花费多少能从a中得到b。不能则输出-1. 思路:因为最近训练的缘故,思路很快就有了。 首先只有三种情况:1.都用方案1,有剩余则对剩余的使用方案二。 2.都用方案2. 3.在2的基础上可能会出现区间内最大值大于两个端点。所以我们可以用方案一消除那些最大值,最终也能消除掉区间内的所有数字。当然这个前提是这个区间长度大于等于k。 求最大值直接O(n).原创 2020-07-13 15:55:36 · 432 阅读 · 0 评论 -
洛谷P1182 数列分段(二分+贪心)
题目描述 对于给定的一个长度为N的正整数数列 A_{1\sim N}A 1∼N ,现要将其分成 MM(M\leq NM≤N)段,并要求每段连续,且每段和的最大值最小。 关于最大值最小: 例如一数列 4\ 2\ 4\ 5\ 14 2 4 5 1 要分成 33 段。 将其如下分段: [4\ 2][4\ 5][1] [4 2][4 5][1] 第一段和为 66,第 22 段和为 99,第 33 段...原创 2020-03-07 15:54:38 · 414 阅读 · 0 评论 -
New Year and Ascent Sequence
A sequence a=[a1,a2,…,al] of length l has an ascent if there exists a pair of indices (i,j) such that 1≤i<j≤l and ai<aj. For example, the sequence [0,2,0,2,0] has an ascent because of the pair (...原创 2020-03-06 13:23:55 · 264 阅读 · 0 评论 -
Party Lemonade(贪心)
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade ...原创 2020-03-05 14:38:09 · 407 阅读 · 0 评论 -
Alternative Thinking(区间交集,贪心)
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin’s string represents Kevin’s sc...原创 2020-03-04 12:13:00 · 314 阅读 · 0 评论 -
Sweets Eating(贪心+前缀和)
Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described by an integer ai. Yui loves sweets, but she can eat ...原创 2020-03-02 13:49:04 · 1342 阅读 · 1 评论 -
Vasya and String(尺取法)
High school student Vasya got a string of length n as a birthday present. This string consists of letters ‘a’ and ‘b’ only. Vasya denotes beauty of the string as the maximum length of a substring (con...原创 2020-02-27 12:53:28 · 558 阅读 · 1 评论 -
1232:Crossing River(贪心)
【题目描述】 几个人过河,每次过两人一人回,速度由慢者决定,问过河所需最短时间。 【输入】 输入t组数据,每组数据第1行输入n,第2行输入n个数,表示每个人过河的时间。 【输出】 输出t行数据,每行1个数,表示每组过河最少时间。 【输入样例】 1 4 1 2 5 10 【输出样例】 17 题目分析: 这种过河问题求最少时间就本着能者多劳的原则去想就行。从一个人过河开始想,想到n个人就结束了。而这个...原创 2020-02-02 19:26:25 · 3274 阅读 · 2 评论 -
1227:Ride to Office(贪心)
【题目描述】 起点与终点相隔4500米。现Charley需要从起点骑车到终点。但是,他有个习惯,沿途需要有人陪伴,即以相同的速度,与另外一个人一起骑。而当他遇到以更快的速度骑车的人时,他会以相应的速度跟上这个更快的人。先给定所有与Charley同路的人各自的速度与出发时间,问Charley以这种方式跟人,骑完4500米需要多少时间。得出的结果若是小数,则向上取整。 【输入】 输入若干组数据,每组数...原创 2020-02-01 20:39:34 · 3785 阅读 · 2 评论 -
排座椅(贪心+模拟)
题目描述 上课的时候总会有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情。不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的 DD 对同学上课时会交头接耳。 同学们在教室中坐成了 MM 行 NN 列,坐在第 ii 行第 jj 列的同学的位置是 (i,j)(i,j),为了方便同学们进出,在教室中设置了 KK 条横向的通道,LL 条纵向的通道。 于是,聪明...原创 2020-01-29 22:27:00 · 454 阅读 · 0 评论
分享