题意: 给一排砖,每列的高度$a_i$,问是否可以放1*2的砖,使得n列高度一样,砖只能横着放 思路: 每两个相邻的高度相同的砖可以变成大于等于它的高度的任意高度 所以像这样的 123321 是不满足题意的,因为两边的相同的高度没法合在一起 只有像这样的 321123 才满足 所以,满足题意的墙应该像上述一样几个“凹”的高度的组合加上最多一列高度为h的墙 这个h应该满足h<=max(a),准确来说应该是等于 拿栈搞一搞就行了 代码: #include<iostream> #include…
传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vova's family is building the Great Vova Wall (named by Vo…
http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The cur…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. N…
l链接 [https://codeforces.com/contest/1092/problem/D2] 题意 和D1一样只是不能竖直放了 分析 水平放的话,就只可能是相邻等时才可以,而且你会发现 只有中间数字小于两边的才可以 比如551122是可以的,15522不可以,你用一个栈保存当前不能改变高度的位置 如果遇到相等的就出栈,具体看代码体会吧 代码 #include<bits/stdc++.h> using namespace std; int main(){ int n,h; //fre…
传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vova's family is building the Great Vova Wall (named by Vo…
http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The cur…
链接 [https://codeforces.com/contest/1092/problem/D1] 题意 给你n个位置墙的高度,现在你有2×1 砖块,你可以竖直或者水平放置 问你是否可以使得所有位置高度一样 思路 都在代码里,看了你就恍然大悟了...仔细想想 代码 #include<bits/stdc++.h> using namespace std; int main(){ int n,h; ios::sync_with_stdio(false); cin.tie(0); cout.ti…
D1. Great Vova Wall (Version 1): 题意:给定长度为N的墙,以及每个位置的一些高度,现在让你用1*2的砖和2*1的砖去铺,问最后能否铺到高度一样. 思路:分析其奇偶性,在一个位置加1*2的砖,其奇偶性不变.在相邻的而且高度相同的位置加2*1的砖,两个奇偶行都改变.那么我们不需要保存高度,因为高度我们可以加1*2的砖,使他们等效到奇偶性的高度:所以只需要保存奇偶,然后加入栈中,如果栈顶的两个元素相同,则可以消去,最后如果栈元素<=1,则ok. (如果最后栈为空,说明最…
D2. Optimal Subsequences (Hard Version) This is the harder version of the problem. In this version, 1≤n,m≤2⋅105. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a seque…