正解:贪心+线段树/set库 解题报告: 算辣直接甩链接qwq 恩这题就贪心?从前往后从后往前各推一次然后找一遍哪个地方最大就欧克了,正确性很容易证明 (这里有个,很妙的想法,就是,从后往前推从前往后推可能会有相同的牌嘛,但是其实这个是没有个关系的! 因为,既然有相同的牌那么就必定有多了的牌,然后如果这个多了的牌比重了的牌大我们就放前面,比重了的小我们就放后面,这样就不会影响答案的正确性了…… 哇我觉得这个想法真是太神仙了像我这种菜鸡自己单独想的话是绝对想不到这个的我可能就直接放弃贪心了TT 但…
[BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<set> using na…
[题解][P3129 USACO15DEC]高低卡(白金)High Card Low Card (Platinum) 考虑贪心. 枚举在第几局改变规则,在改变规则之前,尽量出比它大的最小的牌,在改变规则之后,尽量出最大的比它小的牌.前面记录一个\(f(x)\)后面记录一个\(g(x)\) 此时,你会发现,可能方案选择重复了,怎么办?? 一般人都会放弃,但是这是正确的. 证明如下: 假设我们方案重复了\(1\)次,则必定也有一张多出来的牌.由于不存在相同的牌,则这张多出来的牌,必定比那张重复用的牌…
[题解]P1712 [NOI2016]区间(贪心+线段树) 一个observe是,对于一个合法的方案,将其线段长度按照从大到小排序后,他极差的来源是第一个和最后一个.或者说,读入的线段按照长度分类后,答案是一段子序列.所以我们考虑枚举右端点,尺取法取右边的线段,去到可以满足条件时将左边的这条线段删除.现在就是要维护一个数据结构可以得到是否存在一个点被覆盖了\(m\)次,直接线段树维护每个点被覆盖多少次即可.就是线段树支持区间加和求区间单点最值. 1A掉了很舒爽代码 //@winlere #inc…
Description Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of opposable thumbs. Unfortunately, none of the other cows in the herd are good opponents. They are so bad, in fact, that they always play in a complete…
巧妙的贪心 Description Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of opposable thumbs. Unfortunately, none of the other cows in the herd are good opponents. They are so bad, in fact, that they always play in a co…
---题面--- 题解: 观察到以决策点为分界线,以点数大的赢为比较方式的游戏都是它的前缀,反之以点数小的赢为比较方式的都是它的后缀,也就是答案是由两段答案拼凑起来的. 如果不考虑判断胜负的条件的变化,则有一个比较容易发现的贪心: 设f[i]为从1开始到i位, 比较方式为点数大的获胜,最多能赢几局. 那么为了使答案尽可能优,每次我们都会在剩余牌中找到点数大于对方的 最小的牌,然后出掉. 同理,设g[i]为从n开始到i位,比较方式为点数小的获胜,最多能赢几局, 则每次都在剩余牌中选择点数小于对方的…
Description Bessie the cow is a huge fan of card games, which is quite surprising, given her lack of opposable thumbs. Unfortunately, none of the other cows in the herd are good opponents. They are so bad, in fact, that they always play in a complete…
题目描述 Bessie the cow is a hu e fan of card games, which is quite surprising, given her lack of opposable thumbs. Unfortunately, none of the other cows in the herd are good opponents. They are so bad, in fact, that they always play in a completely pred…
题目大概说有n(<=10W)个车站,每个车站i卖到车站i+1...a[i]的票,p[i][j]表示从车站i到车站j所需买的最少车票数,求所有的p[i][j](i<j)的和. 好难,不会写.. dp[i]表示Σp[i][j](j>i) 转移是dp[i]=dp[k]+(n-i)-(a[i]-k),其中k是i能直接买到的站中能直接买到最远的站,即a[k]=max(a[i+1]...a[a[i]]),这个可以用线段树快速查询 为什么从k转移?因为i+1...a[i]中除了k外能直接买到的车站都是…