![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
贪心
龍木
若人生为棋,我愿为卒,漫漫征途,谁曾见我后退半步
展开
-
力扣训练——贪心
本篇参照大佬博客练习题顺序,代码都是自打的,有些可能不是最优解。455. 分发饼干class Solution {public: int findContentChildren(vector<int>& g, vector<int>& s) { sort(g.begin(),g.end()); sort(s.begin(),s.end()); int r=g.size()-1; int原创 2021-01-25 14:22:24 · 138 阅读 · 0 评论 -
C. Sequence Transformation
https://codeforces.ml/contest/1454/problem/CYou are given a sequenceaa, initially consisting ofnnintegers.You want to transform this sequence so that all elements in itare equal(i.e. it contains several occurrences of the same element).To achie...原创 2020-11-25 15:12:51 · 482 阅读 · 0 评论 -
C. ABBB
https://codeforces.ml/contest/1428/problem/CZookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a原创 2020-11-24 15:11:57 · 472 阅读 · 0 评论 -
C. String Equality
https://codeforces.com/contest/1451/problem/CAshish has two stringsaaandbb, each of lengthnn, and an integerkk. The strings only contain lowercase English letters.He wants to convert stringaainto stringbbby performing some (possibly zero) oper...原创 2020-11-22 14:37:39 · 329 阅读 · 1 评论 -
B. Sum of Medians
https://codeforces.ml/contest/1440/problem/BAmedianof an array of integers of lengthnnis the number standing on the⌈n2⌉⌈n2⌉(rounding up) position in the non-decreasing ordering of its elements. Positions are numbered starting with11. For example, ...原创 2020-11-18 14:12:58 · 335 阅读 · 0 评论 -
D. Extreme Subtraction
链接:https://codeforces.ml/contest/1443/problem/DYou are given an arrayaaofnnpositive integers.You can use the following operation as many times as you like: select any integer1≤k≤n1≤k≤nand do one of two things:decrement by onekkof the first el...原创 2020-11-05 13:48:27 · 189 阅读 · 0 评论 -
Mahjong Sorting
链接:https://zoj.pintia.cn/problem-sets/91827364500/problems/91827370268Time Limit: 1000 msMemory Limit: 65536 KBDreamGrid has just found a set of Mahjong withsuited tiles and a White Dragon tile in his pocket. Each suited tile has a suit (Character, B..原创 2020-10-14 16:26:46 · 205 阅读 · 0 评论 -
A. Arena of Greed
链接:https://codeforces.com/problemset/problem/1425/ALately, Mr. Chanek frequently plays the gameArena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia.The game is played.原创 2020-10-01 13:52:26 · 456 阅读 · 0 评论 -
E. Rock, Paper, Scissors
链接:https://codeforces.com/problemset/problem/1426/EAlice and Bob have decided to play the game "Rock, Paper, Scissors".The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following t原创 2020-09-30 12:46:43 · 491 阅读 · 0 评论 -
D. Decrease the Sum of Digits
链接:https://codeforces.ml/problemset/problem/1409/DYou are given a positive integernn. In one move, you can increasennby one (i.e. maken:=n+1n:=n+1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digi...原创 2020-09-27 15:24:03 · 161 阅读 · 0 评论 -
C. Killjoy
链接:https://codeforces.ml/problemset/problem/1419/CA new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described byan integer(it can possibly be negative or very large).Killjoy's accou..原创 2020-09-27 14:55:46 · 159 阅读 · 0 评论 -
A Equivalent Prefixes
链接:https://ac.nowcoder.com/acm/contest/6362/ATwo arrays u and v each with m distinct elements are called equivalent if and only if RMQ(u,l,r)=RMQ(v,l,r)\mathrm{RMQ}(u, l, r) = \mathrm{RMQ}(v, l, r)RMQ(u,l,r)=RMQ(v,l,r) for all 1≤l≤r≤m1 \leq l \leq r \leq原创 2020-07-11 17:40:50 · 185 阅读 · 0 评论 -
C. Palindromic Paths
链接:https://codeforces.com/contest/1366/problem/CYou are given a matrix withnnrows (numbered from11tonn) andmmcolumns (numbered from11tomm). A numberai,jai,jis written in the cell belonging to theii-th row and thejj-th column, each number is...原创 2020-07-10 19:31:59 · 248 阅读 · 0 评论 -
D. Grid-00100
链接:https://codeforces.ml/contest/1371/problem/DA mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integersn,kn,k. Construct a gridAAwith sizen×nn×nconsisting of integers00and11. The very important co...原创 2020-07-06 09:20:44 · 240 阅读 · 0 评论 -
D. Game With Array
链接:https://codeforces.com/contest/1355/problem/DPetya and Vasya are competing with each other in a new interesting game as they always do.At the beginning of the game Petya has to come up with an array ofNNpositive integers. Sum of all elements in hi..原创 2020-05-17 11:41:30 · 272 阅读 · 0 评论 -
F 排列计算
题目描述天才程序员菜哭武和石头组队参加一个叫做国际排列计算竞赛 (International Competition of Permutation Calculation, ICPC) 的比赛,这个比赛的规则是这样的:一个选手给出一个长度为 n 的排列,另一个选手给出 m 个询问,每次询问是一个形如 (l, r) 的数对,查询队友给出的排列中第 l 个数到第 r 个数的和,并将查询到的这个区间和加入总分,最后总分最高的队伍就能获胜。石头手速很快,在比赛一开始就给出了 m 个询问;菜哭武也很强..原创 2020-05-10 18:42:09 · 262 阅读 · 0 评论 -
A 张老师和菜哭武的游戏
题目描述天才程序员菜哭武和张老师有一天到一个城市旅游,旅途中菜哭武觉得无聊就想和张老师玩一个游戏。菜哭武有n个石子,每个石子都标有1到n之间到数,且各不相同,一开始他们会随机从这堆石子选一个石子放置到一个集合中,张老师选的数是a,菜哭武选的是b(a和b不相同)。接下来菜哭武和张老师轮流按照如下规则拿走一个石子:当石子x能被拿走时,当且仅当集合存在y和z,满足x等于y+z或者y-z,当x被拿走时,把它放到集合中。谁完成最后一轮操作时,谁获胜。张老师总是先手,于是张老师就好奇当决定好a和b时,他是否总是能.原创 2020-05-10 18:40:12 · 223 阅读 · 0 评论 -
C. Hilbert's Hotel
链接:https://codeforces.ml/contest/1345/problem/CHilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer,including zero and...原创 2020-05-07 09:18:26 · 1743 阅读 · 9 评论 -
A 像鱼
给你一个边长为 n 的用硬币摆成的实心三角形,请问把他倒过来最少需要多少步?例子:这是一个边长为3的硬币三角形只要移动边上的两个硬币,就可以把它到过来(注意是倒过来,不是旋转角度),变成这样:聪明的 Prev1ous秒切了这道题,于是他希望来考考你Prev1ous 经过计算后发现,由于答案实在是太大了,所以他只关心答案对23333333333333333取膜的结果,顺...原创 2020-05-03 12:34:59 · 276 阅读 · 0 评论 -
C. Nastya and Strange Generator
链接:https://codeforces.ml/contest/1341/problem/CBeing upset after this behavior of Nastya, Denis was very sad. Nothing could make the rejected guy happier. To at least somehow have fun, he decided to...原创 2020-04-24 07:50:47 · 387 阅读 · 0 评论 -
C2. Increasing Subsequence (hard version)
链接:https://codeforces.ml/contest/1157/problem/C2The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).Y...原创 2020-04-16 23:07:25 · 228 阅读 · 0 评论 -
C. Linova and Kingdom
链接:https://codeforces.ml/contest/1337/problem/CWriting light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light nov...原创 2020-04-16 09:38:25 · 595 阅读 · 0 评论 -
C. Dreamoon Likes Coloring
链接:https://codeforces.ml/contest/1330/problem/CDreamoon likes coloring cells very much.There is a row ofnncells. Initially, all cells are empty (don't contain any color). Cells are numbered from...原创 2020-04-04 14:41:46 · 602 阅读 · 0 评论 -
H 奇怪的背包问题增加了
链接:https://ac.nowcoder.com/acm/contest/4784/H有一个容量为2^{30}230的背包,和m件物品,第i件物品的体积为c_ici,你需要从中选出若干件,使得选出的物品的体积恰好等于背包容量。这些物品有一个奇怪的特性,那就是c_i = 2^{k_i}ci=2ki,其中0 \le k_i < 300≤ki<30,即所有c_ici都是2的...原创 2020-03-22 18:19:12 · 235 阅读 · 0 评论 -
D. Ehab the Xorcist
链接:https://codeforces.ml/contest/1325/problem/DGiven 2 integersuuandvv, find the shortest array such thatbitwise-xorof its elements isuu, and the sum of its elements isvv.InputThe only li...原创 2020-03-15 14:12:05 · 371 阅读 · 0 评论 -
C. Ehab and Path-etic MEXs
链接:https://codeforces.ml/contest/1325/problem/CYou are given a tree consisting ofnnnodes. You want to write some labels on the tree's edges such that the following conditions hold:Every label is...原创 2020-03-15 14:11:00 · 487 阅读 · 2 评论 -
D 取石子游戏
链接:https://ac.nowcoder.com/acm/contest/4743/D小灰灰和小乔在玩取石子游戏,一堆石子有{n}n个石子,小灰灰和小乔轮流操作,小灰灰先手,每次操作的人可以进行以下操作:假设当前石子数量为{k}k,如果{k>=2}k>=2,那么将石子分为{f(k)}f(k)和{k-f(k)}k−f(k)两堆,然后选择其中任意一堆石子取走。否...原创 2020-03-14 11:34:15 · 317 阅读 · 0 评论 -
C 装备合成
链接:https://ac.nowcoder.com/acm/contest/4743/C牛牛有{x}x件材料{a}a和{y}y件材料{b}b,用{2}2件材料{a}a和{3}3件材料{b}b可以合成一件装备,用{4}4件材料{a}a和{1}1件材料{b}b也可以合成一件装备。牛牛想要最大化合成的装备的数量,于是牛牛找来了你帮忙。输入描述:输入包含{t}t组数据第一行一个整数{t}...原创 2020-03-14 11:32:51 · 551 阅读 · 0 评论 -
C. Unusual Competitions
链接:https://codeforces.ml/contest/1323/problem/CA bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, se...原创 2020-03-08 12:12:22 · 400 阅读 · 0 评论 -
C. Playlist
链接:https://codeforces.ml/contest/1140/problem/CYou have a playlist consisting ofnnsongs. Theii-th song is characterized by two numberstitiandbibi— its length and beauty respectively. The plea...原创 2020-02-26 17:33:19 · 256 阅读 · 1 评论 -
C. Restoring Permutation
链接:https://codeforces.ml/contest/1315/problem/CYou are given a sequenceb1,b2,…,bnb1,b2,…,bn. Find the lexicographically minimal permutationa1,a2,…,a2na1,a2,…,a2nsuch thatbi=min(a2i−1,a2i)bi=min(...原创 2020-02-24 13:41:12 · 594 阅读 · 0 评论 -
C. Air Conditioner
链接:https://codeforces.com/contest/1304/problem/CGildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.Gildong trie...原创 2020-02-16 13:36:20 · 808 阅读 · 0 评论 -
D 牛牛与牛妹的约会
链接:https://ac.nowcoder.com/acm/contest/3006/D牛牛在辛苦的一天的比赛之后,要去找牛妹玩,其实牛妹那天也在比赛。他为了找到牛妹,要尽快的从自己的比赛地到她的比赛地。还记得吗,比赛地都是只在xx轴上的,所以两个人的坐标都满足y=0y=0。牛牛除了可以以11单位距离/单位时间的速度移动任意时间以外,还可以花费11单位时间进行闪现。每次闪现时,如果当前他...原创 2020-02-14 05:49:33 · 380 阅读 · 0 评论 -
C. Ayoub's function
链接:https://codeforces.ml/contest/1301/problem/CAyoub thinks that he is a very smart person, so he created a functionf(s)f(s), wheressis a binary string (a string which contains only symbols "0" a...原创 2020-02-14 05:34:42 · 702 阅读 · 2 评论 -
C. Anu Has a Function
链接:https://codeforces.com/contest/1300/problem/CAnu has created her own functionff:f(x,y)=(x|y)−yf(x,y)=(x|y)−ywhere||denotes thebitwise OR operation. For example,f(11,6)=(11|6)−6=15−6=9f(11,...原创 2020-02-10 12:30:04 · 647 阅读 · 0 评论 -
C. Platforms Jumping
链接:http://codeforces.com/contest/1256/problem/CThere is a river of widthnn. The left bank of the river is cell00and the right bank is celln+1n+1(more formally, the river can be represented as a...原创 2019-11-05 12:19:33 · 489 阅读 · 0 评论 -
F 拿物品
链接https://ac.nowcoder.com/acm/contest/3003/F牛牛和 牛可乐 面前有 n 个物品,这些物品编号为1,2,\dots,n1,2,…,n,每个物品有两个属性a_i, b_iai,bi。牛牛与 牛可乐会轮流从剩下物品中任意拿走一个, 牛牛先选取。设 牛牛选取的物品编号集合为 H,牛可乐选取的物品编号的集合为 T,取完之后,牛牛...原创 2020-02-06 22:29:09 · 366 阅读 · 0 评论 -
D. Fight with Monsters
链接:https://codeforces.com/contest/1296/problem/DThere arennmonsters standing in a row numbered from11tonn. Theii-th monster hashihihealth points (hp). You have your attack power equal toaa...原创 2020-02-05 14:49:39 · 810 阅读 · 0 评论 -
C. Mind Control
链接:https://codeforces.com/contest/1291/problem/CYou and yourn−1n−1friends have found an array of integersa1,a2,…,ana1,a2,…,an. You have decided to share it in the following way: Allnnof you sta...原创 2020-02-03 15:29:39 · 485 阅读 · 0 评论 -
C. New Year Ratings Change
链接:https://codeforces.com/contest/379/problem/COne very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all v...原创 2020-01-31 20:44:12 · 193 阅读 · 0 评论