![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
贪心
邵光亮
要为自己喜欢的事情不留余力
展开
-
Codeforces 1342 D. Multiple Testcases
题意:给定 nnn 个数 m[i]m[i]m[i],每个 mim_imi 都在 [1,k][1,k][1,k] 的范围内再给定 kkk 个数 cic_ici,要求将所有的 m[i]m[i]m[i] 进行分组, cic_ici 表示每组中大于等于 iii 的数不超过 cic_ici 个.求最少能分几组,并输出分组方案。首先要求出最小分组 ,求出数组 mmm 中大于等于 iii 的数字...原创 2020-04-27 17:22:35 · 138185 阅读 · 0 评论 -
Codeforces 1215 C. Swap Letters(贪心)
题意:给你两个字符串,问最少需要交换多少次可以使这两个字符串相等,并且输出交换方案。因为字符只有a,b两种;所以不相等的时候只有两种情况aba\\babbab\\aba首先每次交换当然要尽量一次交换就多两个相同的位置。优先把aba\\bab和aba\\bab交换优先把bab\\aba和bab\\aba交换AC代码:const int N = 200010;in...原创 2020-03-30 21:25:41 · 143744 阅读 · 0 评论 -
codeforces 1328 C. Ternary XOR(贪心)
题意:题意给出一个 xxx 的三进制数字,xxx 的第一个数字必须是 222,求出两个数 aaa 和 bbb ,使得a⨀b=xa⨀b=xa⨀b=x,和 max(a,b)max(a,b)max(a,b) 最小。要使得最小的话对于 000 就是两个位置都放置 000 ,对于 222 就是两个位置都放置 111,但是这样肯定不能保证 a,ba,ba,b 的最大值最小,所以只要保证第一次出现 111...原创 2020-03-27 16:18:39 · 140952 阅读 · 0 评论 -
Codeforces 1325 C. Ehab and Path-etic MEXs(贪心构造)
题意:给一颗树,有 nnn 个顶点,给这个树的边分别编号为 0 (n−2)0~(n-2)0 (n−2),问怎样编使得对于树上任意两点 u,vu,vu,v 的最大 mex(u,v)mex(u,v)mex(u,v) 值最小。mex(u,v)mex(u,v)mex(u,v) 表示由 uuu 到 vvv 点的简单路径的长度构成的集合中,没有出现的最小非负整数。很简单的一个贪心策...原创 2020-03-15 09:13:40 · 137397 阅读 · 0 评论 -
Codeforces 1322 B. Count Subrectangles(贪心)
题意:给出序列 aaa 和序列 bbb矩阵 ccc 是由 aaa 和 bbb 决定的 cij==aibjc_{ij}==a_ib_jcij==aibj问你可以从中截取多少个面积为 kkk 的子矩阵。显然可知的一个性质那就是当 aaa 序列 111 连续长度为 xxx,bbb 序列 111 连续长度为 yyy,x∗y==kx*y==kx∗y==k 时这个部分序列形成的矩阵肯定符合,...原创 2020-03-07 23:05:06 · 140906 阅读 · 0 评论 -
2020 CCPC Wannafly Winter Camp Day7 K 修炼
题意:一个游戏,规则如下:有六个值 v1,v2,a1,a2,b1,b2v_1,v_2,a_1,a_2,b_1,b_2v1,v2,a1,a2,b1,b2,开始时 v1=v2=0v_1=v_2=0v1=v2=0.每一天可选择让 a1=a1+1a_1=a_1+1a1=a1+1和a2=a2+1a_2=a_2+1a2=a2+1(这里是重点题意上说的是或者,其实是两个都得加),然...原创 2020-03-03 14:39:16 · 137973 阅读 · 0 评论 -
Codeforces 1321 C. Remove Adjacent(贪心枚举)
题意:字符串中某一字符的前一位或者后一位的字符在字典序中比它小一,那么就可以删除这个字符,问最多能删除多少个字符。要删最多,因为只有在相邻位置存在比它小1的时候才能删除,那么就要尽可能的不去破坏小的字符,因此要从最大开始删除。我们可以从z到b依次删除。然后删完一个字符,如果这个字符可以被删除我们就再遍历一遍看看删完的字符串是否还能继续被删除。AC代码:const int N = 4e5 ...原创 2020-03-02 14:54:09 · 137663 阅读 · 6 评论 -
Codeforces 1315 D. Recommendations(贪心+并查集)
Description:VK news recommendation system daily selects interesting publications of one of nnn disjoint categories for each user. Each publication belongs to exactly one category. For each category i...原创 2020-02-24 12:02:42 · 2916 阅读 · 1 评论 -
CTU Open Contest 2019 F. Beer Marathon(贪心)
题意:在一条直线上有 NNN 个啤酒摊, 这些啤酒摊的位置在直线上随机摆放, 题目要求是任何两个连续啤酒摊位之间的距离应完全相同, 并等于指定的特定值 KKK。 问每个啤酒摊最少移动多少米可以使他们之间的距离是 K 值(尽量减少所有啤酒摊位移动的总米数。先按照 a1,a1+k,a1+2k,a1+3k,....a1+(n−1)ka_1,a_1+k,a_1+2k,a_1+3k,....a_1...原创 2020-02-22 18:11:26 · 719 阅读 · 0 评论 -
2020 CCPC Wannafly Winter Camp Day1 B 密码学(字符串模拟)
题意很简单就是给出一个加密规则,然后用一个串加密另外一个串用得到的新串代替老串。因为是按顺序加密,所以倒着,模拟一遍就行。AC代码:#include <cstdio>#include <vector>#include <queue>#include <cstring>#include <cmath>#include &l...原创 2020-02-21 15:12:25 · 150 阅读 · 0 评论 -
Codeforces 1304 D. Shortest and Longest LIS(构造+贪心)
Description :Gildong recently learned how to find the longest increasing subsequence (LIS) in O(nlogn) time for a sequence of length n. He wants to test himself if he can implement it correctly, but ...原创 2020-02-16 19:22:01 · 563 阅读 · 1 评论 -
Codeforces 1301 C . Ayoub's function(容斥+贪心)
Description:Ayoub thinks that he is a very smart person, so he created a function f(s),f(s),f(s), where s is a binary string (a string which contains only symbols "0""0""0" and "1""1""1"). The functi...原创 2020-02-14 14:40:48 · 403 阅读 · 1 评论 -
Codeforces 1303 D. Fill The Bag(二进制贪心)
Description:You have a bag of size nnn. Also you have m boxes. The size of i−thi-thi−th box is aia_{i}ai, where each ai is an integer non-negative power of two.You can divide boxes into two parts o...原创 2020-02-13 18:15:38 · 355 阅读 · 3 评论 -
Codeforces 1303 C Perfect Keyboard (贪心)
Description:Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all 262626 lowercase Latin letters w...原创 2020-02-13 15:42:19 · 517 阅读 · 1 评论 -
CodeForces 1266 D. Decreasing Debts
题意: 给出 nnn 个人的债务关系,u,v,wu,v,wu,v,w 就是 vvv 欠 uuu www块钱,我们知道债务关系是可以转移的,所以求出所有的欠债钱数最少的债务关系。要想使得最后得债务关系最小,我们先统计每个人的净债务,那么我们就把赚钱的人给存起来,然后用负债的这些人的钱还给赚钱的就好了。AC代码:#include <cstdio>#include <ve...原创 2019-12-18 21:47:09 · 347 阅读 · 0 评论 -
CodeForces1265C
Description:\quadSo the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved pi p...原创 2019-12-06 16:36:03 · 241 阅读 · 0 评论 -
Codeforces1260 E Tournament(贪心)
Description:\quadYou are organizing a boxing tournament, where n boxers will participate (nnn is aaa power of 222), and your friend is one of them. All boxers have different strength from 1 to n, and...原创 2019-11-28 22:15:26 · 368 阅读 · 0 评论 -
codeforces1260D A Game with Traps(二分+贪心)
Description:\quadYou are playing aaa computer game, where you lead a party of m soldiers. Each soldier is characterised by his agility aia_{i}ai.\quadThe level you are trying to get through can be ...原创 2019-11-28 20:38:29 · 444 阅读 · 0 评论 -
Increasing Subsequence (hard version)(贪心)
\quadThe only difference between problems C1C1C1 and C2C2C2 is that all values in input of problem C1C1C1 are distinct (this condition may be false for problem C2C2C2).\quadYou are given a sequence a...原创 2019-11-21 22:05:06 · 183 阅读 · 0 评论 -
n个数可以组成的最大数
这道题是同学问我的,不难但是感觉挺有意思的是一种新类型,而且他还否定我的做法,所以记录一下。排序规则就是按照字典序排序,逐位比较,遇到不同的数字就让字典序大的再前面,然后如果一个串已经比较完了就递归重复短的串和长串后面的比较,因为占得长度一样前面相同的就不再考虑,肯定是大的排前面,331 33就是先33 再331,334 33就是先334再33。AC代码:#include <cs...原创 2019-11-19 21:44:16 · 822 阅读 · 2 评论 -
51nod1672 区间交(贪心+优先队列)
题目描述:小A有一个含有n个非负整数的数列与m个区间,每个区间可以表示为li,ri。它想选择其中k个区间, 使得这些区间的交的那些位置所对应的数的和最大。(是指k个区间共同的交,即每个区间都包含这一段,具体可以参照样例)在样例中,5个位置对应的值分别为1,2,3,4,6,那么选择[2,5]与[4,5]两个区间的区间交为[4,5],它的值的和为10。收起输入第一行三个数...原创 2019-10-19 18:46:50 · 167 阅读 · 0 评论 -
POJ 2431 Expedition(贪心+优先队列)
DescriptionA group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run over a rock and puncture the truck's f...原创 2019-03-20 22:48:55 · 534 阅读 · 0 评论 -
POJ - 3045 Cow Acrobats (贪心)
DescriptionFarmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofed feet prevent them from tightrope walking and swinging from the tra...原创 2019-03-23 16:53:23 · 792 阅读 · 0 评论 -
hdu 1050 Moving Tables (贪心)
DescriptionThe famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.The floor has 200 rooms each on the north side and south side al...原创 2019-03-15 23:25:04 · 635 阅读 · 0 评论 -
POJ1323 Game Prediction (贪心)
DescriptionSuppose there are M people, including you, playing a special card game. At the beginning, each player receives N cards. The pip of a card is a positive integer which is at most N*M. And t...原创 2019-03-15 17:46:44 · 669 阅读 · 0 评论 -
POJ1328 Radar Installation (贪心)
DescriptionAssume 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, loca...原创 2019-03-15 17:21:00 · 690 阅读 · 0 评论 -
POJ 3262 Protecting the Flowers(贪心)
DescriptionFarmer John went to cut some wood and leftN(2 ≤N≤ 100,000) cows eating the grass, as usual. When he returned, he found to his horror that the cluster of cows was in his garden eating ...原创 2019-03-19 22:54:10 · 455 阅读 · 0 评论 -
POJ2393 Yogurt factory (贪心)
DescriptionThe cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10,000) weeks, the price of milk and labor will fluctuate weekly such that ...原创 2019-03-18 20:38:14 · 666 阅读 · 0 评论 -
CodeForces - 804B Minimum number of steps(贪心)
DescriptionWe have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we ...原创 2019-05-25 17:42:16 · 690 阅读 · 0 评论 -
CF - 807B. T-Shirt Hunt (贪心+模拟)
DescriptionNot so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codefor...原创 2019-05-25 17:32:41 · 615 阅读 · 0 评论 -
洛谷 P1208 [USACO1.3]混合牛奶 Mixing Milk(贪心)
题目描述由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要。帮助Marry乳业找到最优的牛奶采购方案。Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是不同的。此外,就像每头奶牛每天只能挤出固定数量的奶,每位奶农每天能提供的牛奶数量是一定的。每天Marry乳业可以从奶农手中采购到小于或者等于奶农最大产量的整数数量的牛奶。给出Marry乳业每天...原创 2019-05-18 21:16:28 · 1165 阅读 · 0 评论 -
给树染色(贪心+树上操作)
题目描述:一颗树有 n 个节点,这些节点被标号为:1,2,3…n,每个节点 i 都有一个权值 A[i]。现在要把这棵树的节点全部染色,染色的规则是:根节点R可以随时被染色;对于其他节点,在被染色之前它的父亲节点必须已经染上了色。每次染色的代价为T*A[i],其中T代表当前是第几次染色。求把这棵树染色的最小总代价。输入格式第一行包含两个整数 n 和 R ,分别代表树的节点...原创 2019-07-26 16:06:55 · 3727 阅读 · 0 评论 -
POJ 1456 Supermarket (贪心or并查集)
DescriptionA supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from th...原创 2019-09-25 16:30:25 · 220 阅读 · 0 评论 -
POJ1862 Stripies题解
为什么要总结这道题,因为是今天刚刚做出来,然后也用到了贪心的思路,其实题不难就是来记录一下自己对贪心这种思维的运用。DescriptionOur chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian ...原创 2019-03-12 23:30:41 · 758 阅读 · 0 评论