Processing math: 100%

随笔分类 -  技巧—贪心

摘要:构造、博弈是真的难思考,orz 阅读全文
posted @ 2020-07-08 13:15 天之道,利而不害 阅读(157) 评论(0) 推荐(0) 编辑
摘要:这些题都很nice,抓住关键点就能突破。 阅读全文
posted @ 2020-06-26 00:13 天之道,利而不害 阅读(139) 评论(0) 推荐(0) 编辑
摘要:n张卡牌,每张卡牌的正面是数字a ,背面是数字b。操作:交换相邻的两张卡牌,然后**翻转**。问最少需要多少次操作使得卡牌朝上的数字组成非递减数列? 阅读全文
posted @ 2020-05-31 19:52 天之道,利而不害 阅读(137) 评论(0) 推荐(0) 编辑
摘要:制作一个演示图(丑) 阅读全文
posted @ 2020-04-08 14:46 天之道,利而不害 阅读(234) 评论(0) 推荐(0) 编辑
摘要:题意 给n个位置染色,有k种颜色。每个位置有一个数字ai,注意: 数字相同 的位置的颜色不能相同,然后k种颜色都要用上。随便输出一种染色方案。 题解 排序,然后依次染色就行。 代码 ~~~c++ const int N = 100005; int n, k; int cnt[N], 阅读全文
posted @ 2019-01-10 21:47 天之道,利而不害 阅读(402) 评论(1) 推荐(0) 编辑
摘要:题解 贪心,从上向下,如果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 阅读全文
posted @ 2019-01-09 15:31 天之道,利而不害 阅读(310) 评论(0) 推荐(0) 编辑
摘要:idea 很容易看出是贪心,不过贪心的策略还是要仔细讨论的:① 优先取对子是较优的,② 由样例4可以看出有些情况优先取顺子较优,当有两张牌已经组成ii+1这种形式时,只需一张i+2就能组成顺子,并且i+2无论时偶数张或者奇数张都是一样的结果,但如果i+1有偶 阅读全文
posted @ 2018-10-16 22:41 天之道,利而不害 阅读(147) 评论(0) 推荐(0) 编辑
摘要:PS:贪心,先拿两个试一下,找到了。。。错误的排序方式,于是百度了两种做法。 (1)按照一个串的贡献进行排序,每次优先处理两个贡献大的串,然后用优先队列动态的对每次剩下的串排序。 //#include<bits/stdc++.h> #include<cstdio> #include<cstring> 阅读全文
posted @ 2018-07-26 19:58 天之道,利而不害 阅读(255) 评论(0) 推荐(0) 编辑
摘要:题解:贪心,先处理人数多的组,把符合条件(能装下整个队伍的地点)的丢到优先队列里(保证没有遗漏可能的解)。然后遍历每个组时取队列里的最小值就可以了。 阅读全文
posted @ 2018-05-12 23:32 天之道,利而不害 阅读(225) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2018-04-11 20:07 天之道,利而不害 阅读(263) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2017-10-25 23:31 天之道,利而不害 阅读(493) 评论(2) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2017-10-23 11:00 天之道,利而不害 阅读(330) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2017-10-15 19:16 天之道,利而不害 阅读(398) 评论(1) 推荐(1) 编辑
摘要: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 阅读全文
posted @ 2017-09-28 17:03 天之道,利而不害 阅读(878) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2017-08-04 22:47 天之道,利而不害 阅读(256) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2017-08-02 16:27 天之道,利而不害 阅读(216) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示