随笔分类 - 贪心
摘要:题目:戳这里 题意:给a个红色小方块和b个蓝色小方块,求其能组成的周长最小的矩形,要求红色或蓝色方块至少有一个也是矩形。 思路来源:戳这里 解题思路:遍历大矩形可能满足的所有周长,维护最小值即可。需要注意蓝色或红色只要有一种矩形能放进大矩形中,则这个大矩形一定满足条件,小矩形放左下角,另一个颜色补缺
阅读全文
摘要:题目:戳这里 学习博客:戳这里 题意:给一个树加最少的边,使得1到所有点的距离小于等于2. 解题思路:分析样例3可以看出,如果一个点到1的距离大于2,那么建立1到该点的父亲节点的边将比直接与该点建边更优。官方题解的做法是把所有与1距离大于2的点放到大顶堆里维护,每次取出最远的点,染色与该点父节点以及
阅读全文
摘要:D. Almost Arithmetic Progression time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output D. Almos
阅读全文
摘要:N个整数组成的序列a[1],a[2],a[3],…,a[n],从中选出一个子序列(a[i],a[i+1],…a[j]),使这个子序列的和>0,并且这个和是所有和>0的子序列中最小的。 例如:4,-1,5,-2,-1,2,6,-2。-1,5,-2,-1,序列和为1,是最小的。 Input 第1行:整数
阅读全文
摘要:C. Longest Regular Bracket Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output C. L
阅读全文
摘要:C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output C. Maximum splittin
阅读全文
摘要:D. Least Cost Bracket Sequence time limit per test 1 second memory limit per test 64 megabytes input standard input output standard output This is yet
阅读全文

浙公网安备 33010602011771号