Towers CodeForces - 229D】的更多相关文章

The city of D consists of n towers, built consecutively on a straight line. The height of the tower that goes i-th (from left to right) in the sequence equals hi. The city mayor decided to rebuild the city to make it beautiful. In a beautiful city al…
http://codeforces.com/problemset/problem/229/D 题意:有n(1<=n<=5,000)座塔排在一条直线上,从左到右每个塔的高度分别为hi(1<=hi<=100,000),每次操作你可以选择一座塔(假设是第i座),用吊车把它吊起来,然后放到与它相邻的一座塔上(可以是第i-1座也可以是第i+1座),这样,新塔的高度为两座塔的和,完成操作后,塔的总数减少一座.问最少需要多少次操作可以使得所有的塔从左到右形成一个非递减序列. 思路: 我们可以这样…
链接: https://vjudge.net/contest/202699#problem/B 题意: 给出一个序列,要支持区间加和操作 求其中最长的区间,该区间内的元素满足(ai<ai+1<...ak>ak+1>..>aj-1>aj) 要支持区间加值 题解: 是一个很经典的差分 对于相邻两项要判断大小只需看差分数组即可 而对于区间修改,只需对差分数组进行单点修改即可 接下来问题可以转化为,给出一个只有-1,0,1的数列,求最长的11111...-1-1-1-1...…
大意: 给定序列, 要求实现区间加, 询问整个序列最长的先增后减的区间. 线段树维护左右两端递增,递减,先增后减的长度即可, 要注意严格递增, 合并时要注意相等的情况, 要注意相加会爆int. #include <iostream> #include <random> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <…
C. Block Towers time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top…
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received a young builder's kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other…
题目链接:http://codeforces.com/problemset/problem/479/B 题目意思:有 n 座塔,第 i 座塔有 ai 个cubes在上面.规定每一次操作是从最多 cubes 的塔中取走一个cube,加去拥有最少 cubes 的塔上,那么显然,本来是最多cubes的塔的 cubes 数目会减少1,而拥有最少的 cubes 的塔的cubes数增加 1 .现在最多操作 k 次,使得最多 cubes 数 的塔的cubes数 减去 最少cubes数的塔的cubes 数最少(…
http://codeforces.com/problemset/problem/478/D 思路:dp:f[i][j]代表当前第i层,用了j个绿色方块的方案数,用滚动数组,还有,数组清零的时候一定要用memset,不然for的常数太大.. #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<iostream> ; ],f[][]; int…
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of ai cubes stacked one on top of the other. Petya defines the instability of a set of towers a…
Alyona and towers 这个题写起来真的要人命... 我们发现一个区间被加上一个d的时候, 内部的结构是不变的, 改变的只是左端点右端点的值, 这样就能区间合并了. 如果用差分的话会简单一些, 就变成了求前一段是负数,后一段是正数的最长段多长. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<…