贪心
不可知论大祭司
Know how to solve every problem that has been solved.
展开
-
【CF1478C】Nezzar and Symmetric Array
code#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <cstring>using namespace std;typedef long long ll;int n;void sol原创 2021-01-29 10:46:28 · 209 阅读 · 2 评论 -
【CF1462D】 Add to Neighbour and Remove
code#include <cstdio>#include <algorithm>#include <cstring>#include <cctype>#include <vector>#include <iostream>#include <map>using namespace std;inline int read(){ int x = 0, op = 1; char ch = getcha原创 2021-01-24 18:19:24 · 110 阅读 · 0 评论 -
【CF1470A】 - Strange Birthday Party
code#include <cstdio>#include <algorithm>#include <cstring>#include <cctype>#include <vector>using namespace std;inline int read(){ int x = 0, op = 1; char ch = getchar(); while (!isdigit(ch)){ if (ch =原创 2021-01-21 10:36:33 · 132 阅读 · 0 评论 -
【CF1468D】D. Firecrackers
链接传送门思路很简单,就是贪心,先扔鞭炮,再逃跑。扔鞭炮要在可以爆照的前提下尽量扔时间大的。code#include <cstdio>#include <algorithm>#include <cstring>#include <cctype>#include <vector>using namespace std;inline int read(){ int x = 0, op = 1; char ch = get原创 2021-01-21 09:09:13 · 301 阅读 · 0 评论 -
【CF467C】Sequence Transformation
链接代码#include <iostream>#include <algorithm>#include <map>using namespace std;const int N = 2e5 + 10;map<int, int> mp;void solve(){ mp.clear(); int n; int a[N] = {0}; cin >> n; for (int i = 1; i &.原创 2021-01-18 15:40:54 · 62 阅读 · 0 评论 -
CF1472 D. Even-Odd Game
链接传送门概述During their New Year holidays, Alice and Bob play the following game using an array ???? of ???? integers:Players take turns, Alice moves first.Each turn a player chooses any element and removes it from the array.If Alice chooses even value,原创 2021-01-15 13:46:16 · 286 阅读 · 0 评论 -
【CF1466B】Last minute enhancements
链接链接code直接贪心,和上一题一样,都用到了map#include <iostream>#include <algorithm>#include <map>#include <cctype>inline int read(){ int x = 0; char ch = getchar(); while (!isdigit(ch)){ch = getchar();} while (isdigit(ch)){x =原创 2020-12-31 11:17:56 · 269 阅读 · 0 评论 -
【CF1466D】13th Labour of Heracles 出度统计 + 贪心
链接传送门分析昨天(今天)coderforces Byebye2020上面的题目,起初的想法是dfs,结果直接超时,后来又模拟了一下过程,是出度统计。即一个节点最多被使用的次数等于它的出度(即与他相连的节点个数),我们把w[i]的和先求出来,得到sum,相当于每个节点都用了一次,然后在通过出度将剩下可以使用的节点记录下来,排序一下即可。code#include <algorithm>#include <cstring>#include <cctype>原创 2020-12-31 11:00:11 · 521 阅读 · 0 评论 -
Leetcode122买股票的最佳时机2
代码其实就是一个找极大值和极小值差的问题class Solution { public int maxProfit(int[] prices) { int min_buy = 100000; int ans = 0; for(int i = 0; i < prices.length; ++i){ if(prices[i] < min_buy){ min_buy = prices[i原创 2020-12-29 23:16:09 · 81 阅读 · 0 评论 -
【CF1428C】ABBB 字符串
链接传送门分析只有AB或BB能够删去,也就是说只要B前面还有字母,那么我们就可以删去,ans指的是已经遍历过的字符剩下的个数,这样做时间复杂度是O(n),满足题目所给的数据范围代码#include <cstdio>#include <cstring>using namespace std;const int N = 2e5 + 10;int t;char s[N];int main() { scanf("%d", &t); while原创 2020-12-27 11:57:03 · 225 阅读 · 0 评论 -
【CF545C】Woodcutters 贪心
Woodcutters题目大意题目链接分析代码题目大意Little Susie listens to fairy tales before bed every day. Today’s fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below原创 2020-12-08 13:46:16 · 247 阅读 · 0 评论