![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
贪心算法
文章平均质量分 85
尽管放心去做就好
unique_pursuit
但行好事,莫问前程!
展开
-
Codeforces Round #702 (Div. 3) A~F题解
A. Dense Array解题思路我们将这个公式变化一下,实际上就是要求相邻两个数ai,ai+1a_i,a_{i+1}ai,ai+1满足ai≤2ai+1,ai+1≤2aia_i\leq 2a_{i+1},a_{i+1}\leq 2a_{i}ai≤2ai+1,ai+1≤2ai,所以我们维护这样的条件即可。AC代码/** *@filename:A *@author: pursuit *@csdn:unique_pursuit *@email: 2825841950@qq原创 2021-06-09 14:04:35 · 187 阅读 · 0 评论 -
Educational Codeforces Round 106 (Rated for Div. 2) A. Domino on Windowsill 贪心水题
原题链接测试样例input51 0 11 01 1 10 03 0 01 34 3 12 25 4 33 1outputNOYESNOYESYESNoteIn the first test case, n=1,k1=0n=1, k_1=0n=1,k1=0 and k2=1.k_2=1.k2=1. It means that 2×12×12×1 board has black cell (1,1)(1,1)(1,1) and white cel..原创 2021-03-19 11:22:48 · 317 阅读 · 0 评论 -
B. Repainting Street(枚举+贪心)Technocup 2021 - Elimination Round 2
原题链接: http://codeforces.com/contest/1415/problem/B测试样例input310 21 1 2 2 1 1 2 2 2 17 11 2 3 4 5 6 710 31 3 3 3 3 1 2 1 3 3output362题意: 给定一个长度为nnn的颜色序列aaa和一个限制常数kkk,你可以进行如下操作:选定一个区间[l,r][l,r][l,r],这个区间长度必须小于等于kkk。然后将这个区间中的颜色换成你想要的颜色。现在请你计算出原创 2020-11-30 20:10:06 · 415 阅读 · 0 评论 -
C. Knapsack(贪心+排序)Codeforces Round #683 (Div. 2, by Meet IT)
原题链接: http://codeforces.com/contest/1447/problem/C测试样例input31 336 219 8 19 69 9 47 121 1 1 17 1 1 1output11-161 2 3 5 6 7NoteIn the first test case, you can take the item of weight 3 and fill the knapsack just right.In the second te原创 2020-11-16 20:57:45 · 269 阅读 · 0 评论 -
B. Numbers Box(基础贪心题)Codeforces Round #683 (Div. 2, by Meet IT)
原题链接: http://codeforces.com/contest/1447/problem/B测试样例input22 2-1 11 13 40 -1 -2 -3-1 -2 -3 -4-2 -3 -4 -5output230NoteIn the first test case, there will always be at least one −1, so the answer is 2.In the second test case, we can use原创 2020-11-16 20:49:44 · 322 阅读 · 0 评论 -
C. The Delivery Dilemma(贪心+思维)Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)
原题链接: https://codeforces.com/contest/1443/problem/C测试样例input443 7 4 52 1 2 441 2 3 43 3 3 321 210 10210 101 2output5323题意: 你需要点nnn个不同的菜,你有两种方式可以选择,一种是点外卖,花费aia_iai时间,一种是自己拿,花费bib_ibi时间。你需要在最少的时间中弄完这nnn个菜。解题思路: 首先我们要清楚一点, 不管我们点了多少原创 2020-11-03 09:48:28 · 533 阅读 · 2 评论 -
A. Arena of Greed(博弈+贪心)2020 ICPC, COMPFEST 12, Indonesia Multi-Provincial Contest
原题链接: https://codeforces.com/problemset/problem/1425/A测试样例input256output24NoteFor the first case, the game is as follows:Mr. Chanek takes one coin.The opponent takes two coins.Mr. Chanek takes one coin.The opponent takes one coin.For原创 2020-10-24 15:45:19 · 2388 阅读 · 1 评论 -
B. Chess Cheater(排序+贪心)Codeforces Global Round 11
原题链接: https://codeforces.com/contest/1427/problem/B测试样例input85 2WLWLL6 5LLLWWL7 1LWLWLWL15 5WWWLLLWWWLLLWWW40 7LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL1 0L1 1L6 1WLLWLWoutput71162646016NoteExplanation of the first testcase原创 2020-10-11 20:46:40 · 870 阅读 · 0 评论 -
C. Numbers on Whiteboard(模拟+贪心) Educational Codeforces Round 96 (Rated for Div. 2)
原题链接: https://codeforces.com/contest/1430/problem/C测试样例input14output22 43 33 1题意: 给定一个111~nnn的序列,你每次需要选择两个数a,ba,ba,b删除,再将(a+b+1)/2(a+b+1)/2(a+b+1)/2这个数放回序列中。最后使得这个序列变成一个数,且这个数要尽可能小。输出这个最小数,以及你依次进行的操作选择数。解题思路: 我们要使得最后剩余的数最小,那么我们一定要知道,让选择大数和小数最原创 2020-10-11 19:34:39 · 551 阅读 · 0 评论 -
B. Barrels(思维+贪心) Educational Codeforces Round 96 (Rated for Div. 2)
原题链接: https://codeforces.com/contest/1430/problem/B测试样例input24 15 5 5 53 20 0 0output100题意: 给你nnn个桶的水量,现在你可以进行kkk次倒水操作,问经过这倒水操作之后,使得这最大水量与最小水量的差值最大。解题思路: 一道简单的思维贪心问题。我们想想,如果我们进行了倒水操作,那么最小水量一定是000。 所以我们关键是在于这最大水量,我们肯定想让这最大,那么要将这水量大的加在一起。所以我们对原创 2020-10-11 19:17:13 · 370 阅读 · 0 评论 -
A. Avoiding Zero(前缀和+贪心)Codeforces Global Round 11
原题链接: https://codeforces.com/contest/1427/problem/A测试样例input441 -2 3 -430 0 051 -1 1 -1 1640 -31 -9 0 13 -40outputYES1 -2 3 -4NOYES1 1 -1 1 -1YES-40 13 40 0 -9 -31题意: 给你一个长度为nnn的整数序列aaa,现在需要你对该序列进行重新排列使得前缀和不为000,若不存在这样的排列,则输出“NO“。解题原创 2020-10-11 08:16:12 · 511 阅读 · 1 评论 -
B. Nice Matrix(模拟+贪心)Codeforces Round #675 (Div. 2)
原题链接: https://codeforces.com/contest/1422/problem/B测试样例input24 24 22 44 22 43 41 2 3 45 6 7 89 10 11 18output842NoteIn the first test case we can, for example, obtain the following nice matrix in 8 operations:2 24 44 42 2In the原创 2020-10-05 08:52:06 · 1719 阅读 · 2 评论 -
B. Merge it!(思维+贪心) Codeforces Round #565 (Div. 3)
原题链接: https://codeforces.com/contest/1176/problem/B测试样例input253 1 2 3 171 1 1 1 1 2 2output33NoteNoteIn the first query of the example you can apply the following sequence of operations to obtain 3 elements divisible by 3: [3,1,2,3,1]→[3,3原创 2020-09-29 21:15:52 · 187 阅读 · 0 评论 -
A. Copy-paste(贪心算法)Codeforces Round #673 (Div. 2)
原题链接: https://codeforces.com/contest/1417/problems测试样例input32 21 13 51 2 33 73 2 2output154NoteIn the first test case we get either a=[1,2] or a=[2,1] after casting the spell for the first time, and it is impossible to cast it again.题意原创 2020-09-28 00:57:20 · 374 阅读 · 0 评论 -
C. Make It Equal(贪心算法)Educational Codeforces Round 52 (Rated for Div. 2)
原题链接: https://codeforces.com/problemset/problem/1065/C测试样例Sample In 15 53 1 2 2 4Sample Out 12Sample In 24 52 3 4 5Sample Out 22NoteIn the first example it’s optimal to make 2 slices. The first slice is on height 2 (its cost is 3), and the原创 2020-09-25 17:00:25 · 193 阅读 · 0 评论 -
D1.D2 Sage‘s Birthday (easy version and hard version)(构造+思维) Codeforces Round #671 (Div. 2)
D1原题链接: https://codeforces.com/contest/1419/problem/D1D1测试样例input51 2 3 4 5output23 1 4 2 5D1NoteIn the example it’s not possible to place ice spheres in any order so that Sage would buy 3 of them. If the ice spheres are placed like this (3,1,原创 2020-09-21 14:07:32 · 568 阅读 · 0 评论 -
B. Negative Prefixes(贪心+思维)Educational Codeforces Round 95 (Rated for Div. 2)
input531 3 20 0 042 -3 4 -11 1 1 17-8 4 -2 -6 4 7 11 0 0 0 1 1 050 1 -4 6 30 0 0 1 16-1 7 10 4 -8 -11 0 0 0 0 1output1 2 32 -3 4 -1-8 -6 1 4 4 7 -2-4 0 1 6 3-1 4 7 -8 10 -1题意: 给你一个数组,其中数组元素有的锁定了有的未锁定,你可以任意交换未锁定的元素。现在你需要使得前缀和pj<..原创 2020-09-15 00:57:15 · 234 阅读 · 0 评论 -
A. Buying Torches(贪心水题)Educational Codeforces Round 95 (Rated for Div. 2)
原题链接:http://codeforces.com/contest/1418/problems测试样例input52 1 542 13 2412 11 121000000000 1000000000 10000000002 1000000000 1000000000output14332520000000031000000001999999999题意: 你起初有一根木棒,你可以进行两种交易:你可以用一根木棒兑换xxx根木棒你可以用yyy根木棒兑换一个煤用一根木原创 2020-09-15 00:41:41 · 517 阅读 · 0 评论 -
B. Maximum Product(贪心+构造)Codeforces Round #670 (Div. 2)
原题链接: http://codeforces.com/contest/1406/problems测试样例input45-1 -2 -3 -4 -56-1 -2 -3 1 2 -16-1 0 0 0 -1 -16-9 -7 -5 -3 -2 1output-120120945NoteIn the first test case, choosing a1,a2,a3,a4,a5 is a best choice: (−1)⋅(−2)⋅(−3)⋅(−4)⋅(−5)=−原创 2020-09-14 20:54:02 · 241 阅读 · 3 评论 -
A. Subset Mex(贪心算法+构造)Codeforces Round #670 (Div. 2)
测试样例input460 2 1 5 0 130 1 240 2 0 161 2 3 4 5 6output5340NoteIn the first test case, A={0,1,2},B={0,1,5} is a possible choice.In the second test case, A={0,1,2},B=∅ is a possible choice.In the third test case, A={0,1,2},B={0} is.原创 2020-09-14 20:30:11 · 311 阅读 · 0 评论 -
B. Big Vova(暴力+贪心)Codeforces Round #669 (Div. 2)
原题链接: https://codeforces.com/contest/1407/problems测试样例input722 541 8 2 333 8 9564 25 75 100 50142696 128 88 80 52 752 4 8 16 17output5 28 2 1 39 3 8100 50 25 75 6442128 96 80 88 52 717 2 4 8 16NoteIn the first test case of th原创 2020-09-09 07:45:03 · 506 阅读 · 3 评论 -
B. Array Cancellation(思维+贪心)Codeforces Round #668 (Div. 2)
原题链接: https://codeforces.com/contest/1405/problems测试样例input74-3 5 -3 121 -14-3 2 -3 44-1 1 1 -17-5 7 -6 -4 17 -13 46-1000000000 -1000000000 -1000000000 1000000000 1000000000 100000000010output3041830000000000NotePossible stra原创 2020-09-07 00:11:53 · 1105 阅读 · 2 评论 -
C. Yet Another Array Restoration(贪心算法)Codeforces Round #667 (Div. 3)
原题链接: http://codeforces.com/contest/1409/problems测试样例input52 1 495 20 506 20 505 3 89 13 22output1 4920 40 30 50 1026 32 20 38 44 508 23 18 13 31 10 13 4 19 22 25 16 7题意: 给定数组元素的个数nnn和数组中的两个元素xxx和yyy,又知道这个数列排序之后为等差数列,要你找到使得max(a1⋅⋅⋅⋅an)ma原创 2020-09-05 01:30:15 · 890 阅读 · 3 评论 -
A. Yet Another Two Integers Problem(贪心水题)Codeforces Round #667 (Div. 3)
原题链接: http://codeforces.com/contest/1409/problems测试样例:input65 513 4218 41337 420123456789 1000000000100500 9000output03292876543229150Note:In the first test case of the example, you don’t need to do anything.In the second test case原创 2020-09-05 00:39:05 · 321 阅读 · 0 评论