
贪心
文章平均质量分 77
madaidao
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Codeforces Round #726 (Div. 2) E2. Erase and Extend (Hard Version) (贪心 or Z_Function)
题目链接:https://codeforces.com/contest/1537/problem/E2 题目大意: 有一个长度为n的初始字符串s,由小写字母组成,可以进行如下两种操作: 1,若s的字符数大于1,可删除s末尾的字符 2,在s的末尾加上自身, 可以进行无限次上述操作,我们需要得到一个长度为k的字符串,需要让该字符串的字典序最小。 题解: 个人的解法:贪心 1,若首字符为a,那么目标字符串一定为aaaa...原创 2021-06-24 11:21:58 · 191 阅读 · 0 评论 -
Codeforces Round #723 (Div. 2) C2. Potions (Hard Version) (贪心、dp、数据结构)
题目链接:https://codeforces.com/contest/1526/problem/C2 题目大意: 从左到右有杯酒,每杯酒有一个健康值,喝掉一杯酒后,人的健康值会加。初始的时候人的健康值为0,在最左边的酒,从左到右往后喝,对于一杯酒可以选择喝和不喝,人的健康值在整个过程不能小于0,求最多可以喝几杯酒? 题解: 方法1:dp 表示前杯酒喝了杯最大的健康值 这种方法复杂度 个人的解法:贪心 若当前酒健康值为-4且能喝,后面有杯健康值为-1,那么显然后面这杯健康值为-1的酒是.原创 2021-05-31 18:05:03 · 272 阅读 · 1 评论 -
leetcode LCP 32. 批量处理任务(贪心+二分)
题目链接 解题思路 容易想到贪心思路,按照区间右值从小到大,将任务排序。然后依次处理每个任务,每次优先选择区间最右边的时间来处理任务,这样可使选择的时间尽量的被后面的区间包含,使能多次利用的时间尽量的多,使总时间最少。 接下来看具体到每个任务的细节如何处理? 对于每一个任务,首先查看这个任务的区间内包含多少已使用的时间,如何计算这个值? 容易发现,前面选择使用的时间区间,一定是由某些不相交的时间段组成,我们可以维护前面选择的时间段,由于这些时间段一定是升序排列,所以我们可以二分查找当前的区间包含哪些已选原创 2021-04-07 15:37:58 · 492 阅读 · 0 评论 -
leetcode 第 234 场周赛解题报告
比赛链接 5713. 字符串中不同整数的数目 题解:暴力枚举把字符串中的数字筛选出来,用数据结构去重即可(set,map,hashmap)均可 代码如下: class Solution { public: int numDifferentIntegers(string word) { set<string> se; string cur=""; bool zero=false; for(int i=0;i<i原创 2021-03-28 21:11:31 · 162 阅读 · 0 评论 -
Codeforces Round #705 (Div. 2) C. K-beautiful Strings (贪心)
题目链接:https://codeforces.com/contest/1493/problem/C 题目大意:输入两个数,和一个长度为的字符串,只包含小写字母。 定义一个字符串为“好串”:字符串中每个字符出现的次数均为的整数倍。 求出一个长度为,只包含小写字母的字符串,这个字符串为一个好串,且字典序不小于字符串,且为所有满足上述条件的字符串中字典序最小的字符串。 题解:若不为的整数倍,则一定无解。 若字符串本身是一个好串,则答案就为字符串。 剩余的情况,我们求出答案字符串与字符串的最长相同前缀原创 2021-03-11 16:38:36 · 175 阅读 · 0 评论 -
Codeforces Global Round 13 D. Zookeeper and The Infinite Zoo
题目链接:https://codeforces.com/contest/1491/problem/D 题目大意:有无限个点,编号为,当且仅当,从点到点有一条有向边。 有次询问,每次询问两个数字,求从点开始,能否到达点。 题解:,那么二进制为1的位,二进制也一定为1,例如: 观察上例,从的二进制的进度看,观察操作结果,我们可以总结为两种操作: 1:若上一位为0,可把这位的1左移一位 2:二进制位连续的1,合并为一个1并左移1位 由于途中可以...原创 2021-03-01 19:35:46 · 191 阅读 · 0 评论 -
Codeforces Global Round 13 C. Pekora and Trampoline(贪心+数据结构)
题目链接:https://codeforces.com/contest/1491/problem/C 题目大意:有张蹦床从左到右排成一排,每张蹦床有个初始弹性,n张蹦床则有。 小明可以从任意一张蹦床开始跳,若小明跳上第张蹦床,则跳往下一个蹦床的位置为,若则跳到外面去了。当小明跳过这张蹦床后,蹦床弹性减少1,蹦床弹性最少为1不能低于1。也就是说跳过蹦床后弹性变为。 小明每次跳上蹦床后,就会一直跳直到跳出去。求,小明最少多少趟跳上蹦床,可把所有蹦床的弹性变为1。 题解:由于小明可以任意选择每次跳的.原创 2021-03-01 18:34:41 · 2095 阅读 · 0 评论 -
Codeforces Round #698 (Div. 1) C Nezzar and Nice Beatmap
题目链接:https://codeforces.com/contest/1477/problem/C C. Nezzar and Nice Beatmap time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Nezzar loves the game osu!. osu! is played on beatmaps, w原创 2021-02-28 16:35:38 · 184 阅读 · 0 评论 -
codeforces 219C Color Stripe(贪心)
题目链接 C. Color Stripe time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A colored stripe is represented b原创 2015-05-27 18:52:13 · 530 阅读 · 0 评论 -
codeforces 222D Olympiad(贪心)
题目链接 Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A boy named Vasya has taken part in an Ol原创 2015-01-13 20:46:00 · 621 阅读 · 0 评论 -
codeforces 491B New York Hotel(贪心,数学)
题目链接 New York Hotel time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Think of New York as a rectangular原创 2015-01-10 15:30:04 · 827 阅读 · 1 评论 -
ACdream oj 1212 New Year Bonus Grant(贪心+拓扑排序)
题目链接 New Year Bonus Grant Special JudgeTime Limit: 6000/3000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticNext Problem Problem Description All pr原创 2014-10-16 11:36:36 · 464 阅读 · 0 评论 -
URAL 2021 Scarily interesting!(贪心)
题目链接 2021. Scarily interesting! Time limit: 1.0 second Memory limit: 64 MB This year at Monsters University it is decided to arrange Scare Games. At the Games all campus gathers at the sta原创 2014-11-29 10:53:10 · 891 阅读 · 0 评论 -
codeforces 490E Restoring Increasing Sequence(贪心)
题目链接 E. Restoring Increasing Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Peter wrote on th原创 2014-11-29 11:25:24 · 707 阅读 · 0 评论 -
codeforces 478c Table Decorations
题目链接原创 2014-10-21 10:37:28 · 878 阅读 · 0 评论 -
codeforces 496E Distributing Parts(贪心)
题目链接 Distributing Parts time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are an assistant director in a new原创 2015-01-08 15:24:13 · 718 阅读 · 0 评论 -
codeforces 486C Palindrome Transformation(贪心)
题目链接 C. Palindrome Transformation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nam is playing with a string原创 2015-01-08 20:27:43 · 555 阅读 · 0 评论 -
Codeforces 444A DZY Loves Physics(贪心,数学)
题目链接 A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY loves Physics, and he enjoys calcul原创 2015-01-09 16:59:50 · 479 阅读 · 0 评论 -
codeforces 387C George and Number(贪心)
题目链接 George and Number time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output George is a cat, so he really likes to pla原创 2015-01-09 20:23:46 · 440 阅读 · 0 评论 -
UVALive 6424 Russian Dolls(贪心)
6424 Russian Dolls Maybe you know the famous russian souvenir Russian Dolls. It looks like a set of nested wooden dolls. A doll with a smaller size is placed inside a bigger one. Let's consider all原创 2014-10-31 21:23:34 · 722 阅读 · 0 评论