![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
贪心
Dejavu1z
做题,总结,不断的学习
展开
-
codeforces 1374E1(贪心+优先队列)
题意描述Easy and hard versions are actually different problems, so read statements of both problems completely and carefully.Summer vacation has started so Alice and Bob want to play and joy, but… Their mom doesn’t think so. She says that they have to read s原创 2020-09-22 20:04:03 · 161 阅读 · 0 评论 -
codeforces 1213D2(贪心+思维)
题意可以对每个数进行除2的操作,求最少需要操作多少次,使得数组中有k个相同的数思路题目中说答案始终存在,因为每个数都可以变成0,但很明显,让数字变成0的情况是不存在的,每个数字不停的除2肯定可以变成1,如果变成0,肯定不是最优解。我们可以使用一个cntcntcnt数组来记录每个数字出现的次数,使用tottottot数组来记录变成该数需要的次数,因为数据范围最大是2∗1052*10^52∗105,每个数字除2不超过20次就可以变成1,我们遍历一遍数组即可得到答案。AC代码#include<bi原创 2020-09-19 08:17:33 · 189 阅读 · 0 评论 -
codeforces 1203D2(贪心)
题意描述t是s的子串,求能够删除的最大区间,使得t仍是s的子串思路我们可以从左向右求出t的第i个字母在哪个位置 1=<i<=t1=<i<=t1=<i<=t,然后再同理从右向左求出right数组。最后遍历一遍,取right和left对应字母之间的最大值即可。AC代码#include<bits/stdc++.h>#define x first#define y second#define PB push_back#define mst(x,a)原创 2020-09-18 17:54:30 · 104 阅读 · 0 评论 -
codeforces 1283D(BFS)
题意描述有n个人,要求找到m个圣诞树,使n个人到m个圣诞树之间的距离之和最小思路使用bfs来做,贪心的考虑,我们先找与n个点距离为1的圣诞树,然后再找距离为2的圣诞树,依次类推。AC代码#include<bits/stdc++.h>#define x first#define y second#define PB push_back#define mst(x,a) memset(x,a,sizeof(x))#define all(a) begin(a),end(a)#def原创 2020-09-17 08:12:11 · 195 阅读 · 0 评论 -
codeforces 1296D(贪心)
题意描述有n个怪物,a和b轮流对怪物造成a和b伤害,有k次超能力,超能力可以跳过对方的回合,如果a击败了怪物,则a获得一分,反之亦然。求a能够获得的最大点数思路要想获得最大的点数,那么要最大限度的使用k次超能力。使怪物的血量对(a+b)(a+b)(a+b)求余,使怪物的血量在1~a+b之间,如果求余后为0,则使血量回滚到之前的状态。然后计算每个血量使用的k的次数,容易想到次数为⌈h/a⌉−1\left \lceil h/a \right \rceil-1⌈h/a⌉−1,最后排序后计算答案即可。AC代原创 2020-09-12 21:59:20 · 174 阅读 · 0 评论 -
codeforces 1256D(优先队列+贪心)
题意描述You are given a binary string of length n (i. e. a string consisting of n characters ‘0’ and ‘1’).In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given one原创 2020-09-08 20:46:48 · 189 阅读 · 0 评论 -
codeforces 1256C (贪心+构造)
题意描述There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n+1 (more formally, the river can be represented as a sequence of n+2 cells numbered from 0 to n+1). There are also m wooden platforms on a river, the i-th pl原创 2020-09-05 17:46:12 · 287 阅读 · 0 评论 -
codeforces 940B(贪心)
题意描述Right now she actually isn’t. But she will be, if you don’t solve this problem.You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations:Subtract 1 from x. This opera原创 2020-07-23 15:12:08 · 155 阅读 · 0 评论 -
codeforces 545C(贪心)
题意描述小灵每天睡觉都要听故事。今天是关于伐木工的一个故事。故事有点无聊,于是她开始神游,想象着伐木工伐木的过程。一条路上有 n 棵树,1棵树占据1个坐标点 x1, x2, …, xn。每棵树有不同的高度 hi。伐木工砍到树后可以让树往右倒或者往左倒,倒下的树就会占据一个路段区间 [xi - hi, xi] 或者 [xi;xi + hi]。没有被砍的树就只占据一个坐标点 xi。被砍倒的树占据的路段区间内不能包含另一棵树的坐标点。伐木工希望尽可能多地砍倒树,请帮小灵计算一下伐木工最多能砍倒多少棵树。思路原创 2020-07-23 15:06:31 · 301 阅读 · 0 评论 -
codeforces 349B(贪心)
题意描述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 win Tanya’s heart he has.Unfortunately, Igor could only g原创 2020-07-21 15:31:20 · 176 阅读 · 0 评论 -
codeforces1369C(贪心)
题意描述Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought n integers, now it’s time to distribute them between his friends rationally…Lee has n integers a1,a2,…,an in his backpack and he has k friends. Lee原创 2020-07-16 19:02:56 · 207 阅读 · 0 评论 -
codeforces 1066B(贪心)
题意描述Vova’s house is an array consisting of n elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The i-th element of the array is 1 if there is a heater in the position i原创 2020-07-14 15:38:12 · 230 阅读 · 0 评论 -
B. Ternary String(贪心)
题意描述You are given a string s such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of s such that it contains each of these three characters at least once.A contiguous substring of string s is a string th原创 2020-05-17 22:27:16 · 294 阅读 · 0 评论 -
B. Minimize the Permutation (贪心)
题意描述You are given a permutation of length n. Recall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [...原创 2020-04-11 10:47:56 · 384 阅读 · 0 评论 -
B. Taxi (贪心)
原题链接158B题目描述After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and...原创 2020-04-03 21:03:46 · 403 阅读 · 0 评论 -
HDOJ 1009(贪心)
题意描述Problem DescriptionFatMouse 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 co...原创 2020-03-15 09:57:21 · 198 阅读 · 0 评论