
GREED(贪心)
Zeolim
这个作者很懒,什么都没留下…
展开
-
[MAP][排序]451. 根据字符出现频率排序
451. 根据字符出现频率排序难度中等290收藏分享切换为英文接收动态反馈给定一个字符串,请将字符串里的字符按照出现的频率降序排列。示例 1:输入:"tree"输出:"eert"解释:'e'出现两次,'r'和't'都只出现一次。因此'e'必须出现在'r'和't'之前。此外,"eetr"也是一个有效的答案。示例 2:输入:"cccaaa"输出:"cccaaa"解释:'c'和'a'都出现三次。此外,"aaaccc"也是有效的答案。注意"cacaca.原创 2021-07-03 11:29:22 · 244 阅读 · 0 评论 -
Educational Codeforces Round 54 (Rated for Div. 2) A. Minimizing the String
贪心因字典序位越靠前权越大 从初始位置枚举此位后一位向后与原串比较字典序若小则为最优输出结束/* Zeolim - An AC a day keeps the bug away*///pragma GCC optimize(2)#include <cstdio>#include <iostream>#include <cs...原创 2018-11-13 11:22:29 · 422 阅读 · 0 评论 -
Codeforces Round #521 (Div. 3) D. Cutting Out
D. Cutting Outtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array ss consisting of nn integers.You have to ...原创 2018-11-18 19:30:00 · 201 阅读 · 0 评论 -
[贪心][51nod] 最高的奖励
1163 最高的奖励有N个任务,每个任务有一个最晚结束时间以及一个对应的奖励。在结束时间之前完成该任务,就可以获得对应的奖励。完成每一个任务所需的时间都是1个单位时间。有时候完成所有任务是不可能的,因为时间上可能会有冲突,这需要你来取舍。求能够获得的最高奖励。输入第1行:一个数N,表示任务的数量(2 <= N <= 50000)第2 - N + 1行,每行2个数,中间用...原创 2019-03-27 13:42:57 · 409 阅读 · 0 评论 -
[DP] 简单的烦恼
此题是一个有条件限制的01背包解法1:首先 最大体积肯定是其次 易得大于体积 t 的状态只能由小于 t 的状态转移而来解法2:最大答案肯定是 t 体积以内的最大非 t 体积 + max val[i]所以对物品排序, 用t体积背前n - 1个物品, 然后加上max val[i]int main(){ ios::sync_with_stdio(fal...原创 2019-04-21 18:44:48 · 221 阅读 · 0 评论 -
[贪心] 二元组最小值最大
CCPC省赛的时候和队友讨论了多值同时贪心怎么最优, 没整出来, 今天就碰到这种题了。。。私以为贪心不是特别容易凭空构造出一种严谨/正确的贪心方案我这种铁牌选手只能多看多学吧,没什么别的方法题目:给定N个二元组(a1,b1),(a2,b2),…,(aN,bN),请你从中选出恰好K个,使得ai的最小值与bi的最小值之和最大。请输出ai的最小值与bi的最小值之和解法...原创 2019-04-14 19:04:23 · 425 阅读 · 0 评论 -
[构造]D. N Problems During K Days
Polycarp has to solve exactlynnproblems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start ink...原创 2019-05-08 20:23:11 · 348 阅读 · 0 评论 -
[构造] F. Maximum Balanced Circle
There arennpeople in a row. The height of theii-th person isaiai. You can chooseanysubset of these people and try to arrange them into abalanced circle.Abalanced circleis such an order of ...原创 2019-05-08 21:46:50 · 273 阅读 · 0 评论 -
[权值线段树] 1163B2 Cat Party (Hard Edition)
题意: 给一序列串求最大x 有 x前删除一个值后每个值出现次数相同解法: B1是小范围版, 只要枚举数字就行B2用权值线段树记录最大最小出现次数, 出现n次的数有几个, 结合B1的规律(在代码里↓)写即可代码/* Zeolim - An AC a day keeps the bug away*///pragma GCC optimize(2)#includ...原创 2019-05-10 21:28:59 · 376 阅读 · 0 评论 -
19多校(十) Hilbert Sort
希尔伯特曲线如图所示观察易得为分形暴力分形过程很容易,但是时间爆炸逆向思考,对于任意点,可以递归求得分型过程(设 左上角为第1进入块左下2块 右下3块 右上4块)且左上为原图形左旋, 下边两个都是原图形, 右上是原图形关于x = y对称将以上分形过程做唯一映射并排序输出即可有点卡常, vector string超时, 用5进制映射比较好/* Zeolim...原创 2019-08-20 13:04:18 · 899 阅读 · 0 评论 -
Comet OJ - Contest #9 & X Round 3 【XR-3】核心城市
题意: 给定一颗无向无根树,求一大小为K的联通子图使得非子图最远点距离子图距离最小树, 且联通考虑平均砍去部分子树使得答案最优即可所以从叶子入手一层一层往里砍, 砍几层答案是几那么需要记录信息 p[y] 为以 y 为根的子树最大深度为多少所以要找个根,当树的中心为根时 p[y]最平均所以两遍dfs求树中心即可用树中心树上dp子树最大深度,按深度遍历累加 当累加树...原创 2019-08-31 18:45:42 · 281 阅读 · 0 评论 -
[洛谷] P1209 修理牛棚
问题化简了就是在找间断点用贪心差值越大越优//#pragma GCC optimize(2)#include <cstdio>#include <iostream>#include <cstdlib>#include <cmath>#include <cctype>#include <string&g...原创 2018-10-18 09:55:43 · 343 阅读 · 0 评论 -
[洛谷] P2677 超级书架2
贪心 DP 背包//#pragma GCC optimize(2)#include <cstdio>#include <iostream>#include <cstdlib>#include <cmath>#include <cctype>#include <string>#include <cs...原创 2018-09-24 10:55:55 · 418 阅读 · 0 评论 -
[洛谷] P2689 东南西北
求个曼哈顿距离然后贪心//#pragma GCC optimize(2)#include <cstdio>#include <iostream>#include <cstdlib>#include <cmath>#include <cctype>#include <string>#include <...原创 2018-09-24 10:54:30 · 567 阅读 · 0 评论 -
[贪心] [洛谷] P1803 凌乱的yyy / 线段覆盖
经典排序贪心开始时间从小到大为第一关键字结束时间从大到小为第二关键字从尾至头连一遍输出结果#include <iostream>#include <algorithm>using namespace std;const int MAXN = 1e6 + 10;struct ctst{ int beg, end;}arr[MAXN...原创 2018-07-12 17:09:08 · 726 阅读 · 0 评论 -
[贪心][51nod] 1133 不重叠的线段
1133 不重叠的线段 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注X轴上有N条线段,每条线段有1个起点S和终点E。最多能够选出多少条互不重叠的线段。(注:起点或终点重叠,不算重叠)。例如:[1 5][2 3][3 6],可以选[2 3][3 6],这2条线段互不重叠。Input第1行:1个数N,线段的数量(2 ...原创 2018-05-08 17:07:58 · 166 阅读 · 0 评论 -
[贪心] 51nod 1428 活动安排问题
1428 活动安排问题 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注有若干个活动,第i个开始时间和结束时间是[Si,fi),同一个教室安排的活动之间不能交叠,求要安排所有活动,最少需要几个教室? Input第一行一个正整数n (n <= 10000)代表活动的个数。第二行到第(n + 1)行包含n个开始时间和...原创 2018-05-06 14:41:27 · 218 阅读 · 0 评论 -
[贪心] [洛谷] P1233 木棍加工
基础贪心和安排教室一个思路多线程往下安排即可 #include <iostream>#include <algorithm>using namespace std;const int MAXN = 1e5 + 10;struct bn{ int beg, end;}arr[MAXN];struct sstat{...原创 2018-08-04 12:17:25 · 428 阅读 · 0 评论 -
[Greed] [洛谷] P1080 国王游戏
都TM 8102年了还在写大数#include <bits/stdc++.h>using namespace std;typedef long long ll;const int MAXN = 1e5 + 10;string prefix[MAXN];int aa[10010] = {0}, bb[10010] = {0}, ans[2 * 10010]...原创 2018-08-08 12:09:28 · 248 阅读 · 0 评论 -
[贪心 + 化学] 多校赛-开学觉醒赛 B
溶液混合浓度 = C1 V1 + C2 V2 / V1 + V2题目所给数据不足 无法精确计算溶液混合体积只能将体积相加由公式推导贪心即可#include <cstdio>#include <iostream>#include <cstdlib>#include <cmath>#include <cctype>...原创 2018-08-22 09:57:52 · 191 阅读 · 0 评论 -
[模拟] P1167 刷题
日期模拟好像一直很弱敲了好久bool ly(int x) //leapyear{ return ( (x % 4 == 0 && x % 100 != 0) || x % 400 == 0);} if(ly(ya)) //leapyear month month[2] = 29; else ...原创 2018-08-24 16:30:10 · 473 阅读 · 0 评论 -
[二分答案] P2920 Time Management
推导贪心条件排序二分输出 //#pragma GCC optimize(2)#include <cstdio>#include <iostream>#include <cstdlib>#include <cmath>#include <cctype>#include <string>...原创 2018-08-25 23:01:00 · 175 阅读 · 0 评论 -
[洛谷] P1204 挤牛奶
贪心 线段重合求最大重叠段长度和最大间距//#pragma GCC optimize(2)#include <cstdio>#include <iostream>#include <cstdlib>#include <cmath>#include <cctype>#include <string>...原创 2018-09-05 19:02:40 · 449 阅读 · 0 评论 -
牛客小白月赛7
A.送分题 题目描述做水题就是在浪费时间,但是一场比赛要是没有送分的签到题,大家的比赛体验就会很差。为了优化你的比赛体验又不浪费你的读题时间,我并不打算给你很复杂的故事背景,你只需要复制下面的代码并选择正确的语言提交即可通过此题。 #include<iostream>using namespace std;long long f(long long n){ ...原创 2018-09-19 09:08:03 · 215 阅读 · 0 评论 -
[贪心] [STL] [51nod] 做任务三
按左点排序能干就干 干不了加人但这次数据非常大 手动模拟超时需要用到优先队列 或 mutilset队列能解决的set 都可以解决set支持性更佳 所以个人更倾向于set#include <iostream>#include <algorithm>#include <set>using namespace std;const...原创 2018-07-24 17:00:51 · 282 阅读 · 0 评论