随笔分类 - 技巧—贪心
摘要:这些题都很nice,抓住关键点就能突破。
阅读全文
摘要:题意 给n个位置染色,有k种颜色。每个位置有一个数字ai,注意: 数字相同 的位置的颜色不能相同,然后k种颜色都要用上。随便输出一种染色方案。 题解 排序,然后依次染色就行。 代码 ~~~c++ const int N = 100005; int n, k; int cnt[N],
阅读全文
摘要:题解 贪心,从上向下,如果s[u]=1,则a[u]:=以u为根的子树中的最小s减去s[pa[u]]。否则,a[u]:=s[u]s[pa[u]]。 代码 ~~~c++ void DFS1(int u, int pa) { for (auto v : G[u]) if (v
阅读全文
摘要:idea 很容易看出是贪心,不过贪心的策略还是要仔细讨论的:① 优先取对子是较优的,② 由样例4可以看出有些情况优先取顺子较优,当有两张牌已经组成i,i+1这种形式时,只需一张i+2就能组成顺子,并且i+2无论时偶数张或者奇数张都是一样的结果,但如果i+1有偶
阅读全文
摘要:PS:贪心,先拿两个试一下,找到了。。。错误的排序方式,于是百度了两种做法。 (1)按照一个串的贡献进行排序,每次优先处理两个贡献大的串,然后用优先队列动态的对每次剩下的串排序。 //#include<bits/stdc++.h> #include<cstdio> #include<cstring>
阅读全文
摘要:题解:贪心,先处理人数多的组,把符合条件(能装下整个队伍的地点)的丢到优先队列里(保证没有遗漏可能的解)。然后遍历每个组时取队列里的最小值就可以了。
阅读全文
摘要:You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on arr
阅读全文
摘要:In the evening Polycarp decided to analyze his today's travel expenses on public transport. The bus system in the capital of Berland is arranged in su
阅读全文
摘要:A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is
阅读全文
摘要:A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation
阅读全文
摘要:Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 20
阅读全文
摘要:There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine
阅读全文
摘要:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the ho
阅读全文
![](https://images.cnblogs.com/cnblogs_com/zgglj-com/1682556/o_200327152908zg.jpg)