随笔分类 -  算法基础—贪心

摘要:1414. 和为 K 的最少斐波那契数字数目 难度中等116 给你数字 k ,请你返回和为 k 的斐波那契数字的最少数目,其中,每个斐波那契数字都可以被使用多次。 斐波那契数字定义为: F1 = 1 F2 = 1 Fn = Fn-1 + Fn-2 , 其中 n > 2 。 数据保证对于给定的 k , 阅读全文
posted @ 2022-02-03 22:09 脂环 阅读(41) 评论(0) 推荐(0) 编辑
摘要:A. Equidistant Letters 直接对原字符串进行排序,这样能保证相同的字母相邻,间隔为0. #include <iostream> #include <vector> #include <algorithm> #define pii pair<int,int> #define fi 阅读全文
posted @ 2022-02-03 22:08 脂环 阅读(56) 评论(0) 推荐(0) 编辑
摘要:链接:https://ac.nowcoder.com/acm/contest/11185/C 来源:牛客网 题目描述 给出一个正整数序列 [a1…an][a1…an] 以及定值 kk,每次可以选择一个区间 [l,r] (r−l+1≥k)[l,r] (r−l+1≥k),把这个区间内的 aiai 除以二 阅读全文
posted @ 2022-01-21 23:26 脂环 阅读(93) 评论(1) 推荐(0) 编辑
摘要:Bob has given Alice a necklace as her birthday gift. That necklace has 𝑁N crystals, 𝑀M of which catches her fancy. Formally, crystals with labels of 阅读全文
posted @ 2021-11-20 21:34 脂环 阅读(967) 评论(2) 推荐(1) 编辑
摘要:题目描述 现给定 n 个数 {ai}{ai} 和 m 个关系。 第 i 个关系形如 (x, y)。请你重排 {ai}{ai},使得 ∑i=1m(axi−ayi)i=1∑m(axi−ayi) 最小。 你只需要输出这个最小值即可。 输入描述: 一行两个数 n,m(1≤n,m≤105)n,m(1≤n,m≤ 阅读全文
posted @ 2021-09-24 20:07 脂环 阅读(167) 评论(0) 推荐(0) 编辑
摘要:Recently, Petya learned about a new game "Slay the Dragon". As the name suggests, the player will have to fight with dragons. To defeat a dragon, you 阅读全文
posted @ 2021-09-22 11:03 脂环 阅读(119) 评论(0) 推荐(0) 编辑
摘要:链接:https://ac.nowcoder.com/acm/contest/11257/F 来源:牛客网 题目描述 Riko is ready to cook hamburger steaks. There are mm pans and nn hamburger steaks that need 阅读全文
posted @ 2021-08-02 23:14 脂环 阅读(100) 评论(0) 推荐(0) 编辑
摘要:A You are given 𝑛n integers 𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an. Find the maximum value of 𝑚𝑎𝑥(𝑎𝑙,𝑎𝑙+1,…,𝑎𝑟)⋅𝑚𝑖𝑛(𝑎𝑙,𝑎𝑙+1,…,𝑎𝑟)max(a 阅读全文
posted @ 2021-07-30 12:46 脂环 阅读(474) 评论(0) 推荐(0) 编辑
摘要:#include <bits/stdc++.h> using namespace std; int n; int x[200005], y[200005], xr[200005]; int main() { int t; cin >> t; while(t--) { cin >> n; for(in 阅读全文
posted @ 2021-07-11 15:02 脂环 阅读(67) 评论(0) 推荐(0) 编辑
摘要:链接:https://ac.nowcoder.com/acm/contest/11176/C 来源:牛客网 题目描述 某个国家的货币体系里有 nn 种面值不同的纸币,从小到大面值分别是 a1,a2,...,ana1,a2,...,an,a1=1a1=1。 当取款人去 ATMATM 机取款 cc 元的 阅读全文
posted @ 2021-07-10 11:33 脂环 阅读(74) 评论(0) 推荐(0) 编辑
摘要:You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of 阅读全文
posted @ 2021-05-06 19:02 脂环 阅读(254) 评论(0) 推荐(0) 编辑
摘要:Phoenix has n blocks of height h1,h2,…,hn, and all hi don't exceed some value x. He plans to stack all 𝑛n blocks into m separate towers. The height o 阅读全文
posted @ 2021-05-03 22:12 脂环 阅读(174) 评论(0) 推荐(0) 编辑
摘要:To satisfy his love of matching socks, Phoenix has brought his n socks (n is even) to the sock store. Each of his socks has a color ci and is either a 阅读全文
posted @ 2021-05-03 20:44 脂环 阅读(172) 评论(0) 推荐(0) 编辑
摘要:题目描述 对一个由(,),[,]括号组成的字符串,求出其中最长的括号匹配子串。具体来说,满足如下条件的字符串成为括号匹配的字符串: 1.(),[]是括号匹配的字符串。 2.若A是括号匹配的串,则(A),[A]是括号匹配的字符串。 3.若A,B是括号匹配的字符串,则AB也是括号匹配的字符串。 例如:( 阅读全文
posted @ 2021-04-24 10:24 脂环 阅读(172) 评论(0) 推荐(0) 编辑
摘要:Let's define the cost of a string 𝑠s as the number of index pairs i and j (1≤i<j<|s|) such that si=sj and si+1=sj+1. You are given two positive integ 阅读全文
posted @ 2021-04-14 09:18 脂环 阅读(98) 评论(0) 推荐(0) 编辑
摘要:A. 回文括号序列计数 坑比题...注意回文的定义,并不是括号序列对称。比如(())不是回文的而))是回文的。而合法括号列左右两端一定是(和),必然非回文,因此只有空串答案是1. #include <iostream> using namespace std; #define mod 9982443 阅读全文
posted @ 2021-02-24 20:38 脂环 阅读(88) 评论(0) 推荐(0) 编辑
摘要:链接:https://ac.nowcoder.com/acm/contest/9985/D 来源:牛客网 题目描述 叶妹妹很喜欢玩石头,于是这天泽鸽鸽给她出了一道石子游戏,规则是这样的:有n堆石子排成一行,其中第i堆石子有ai个,叶妹妹可以选择做无数次这种操作:每次操作把连续相邻的k个石子堆中的每堆 阅读全文
posted @ 2021-02-22 19:03 脂环 阅读(250) 评论(0) 推荐(0) 编辑
摘要:Boring Apartments 模拟 #include <iostream> using namespace std; int main() { //freopen("data.txt", "r", stdin); int t; cin >> t; while(t--) { int x; cin 阅读全文
posted @ 2020-10-21 20:05 脂环 阅读(193) 评论(0) 推荐(0) 编辑
摘要:题目描述 The kingdom of Lazyland is the home to n idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Laz 阅读全文
posted @ 2020-10-06 22:08 脂环 阅读(161) 评论(0) 推荐(0) 编辑
摘要:Cuber QQ has signed up for a gambling game, that challenges him to predict the stock price of Quber CC Limited, for the next following n days. He shal 阅读全文
posted @ 2020-08-13 17:43 脂环 阅读(281) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示
主题色彩