HDU 5191 Building Blocks
来源:互联网 发布:便携式数据采集器pt800 编辑:程序博客网 时间:2024/05/16 23:59
Problem Description
After enjoying the movie,LeLe went home alone. LeLe decided to build blocks.
LeLe has already builtn piles. He wants to move some blocks to make W consecutive piles with exactly the same height H .
LeLe already put all of his blocks in these piles, which means he can not add any blocks into them. Besides, he can move a block from one pile to another or a new one,but not the position betweens two piles already exists.For instance,after one move,"3 2 3" can become "2 2 4" or "3 2 2 1",but not "3 1 1 3".
You are request to calculate the minimum blocks should LeLe move.
LeLe has already built
LeLe already put all of his blocks in these piles, which means he can not add any blocks into them. Besides, he can move a block from one pile to another or a new one,but not the position betweens two piles already exists.For instance,after one move,"3 2 3" can become "2 2 4" or "3 2 2 1",but not "3 1 1 3".
You are request to calculate the minimum blocks should LeLe move.
Input
There are multiple test cases, about 100 cases.
The first line of input contains three integersn,W,H(1≤n,W,H≤50000) .n indicate n piles blocks.
For the next line ,there aren integers A1,A2,A3,……,An indicate the height of each piles. (1≤Ai≤50000)
The height of a block is 1.
The first line of input contains three integers
For the next line ,there are
The height of a block is 1.
Output
Output the minimum number of blocks should LeLe move.
If there is no solution, output "-1" (without quotes).
If there is no solution, output "-1" (without quotes).
Sample Input
4 3 21 2 3 54 4 41 2 3 4
Sample Output
1-1
前后补上w,然后扫描一遍即可。
#include<stdio.h>#include<cstring>#include<vector>#include<algorithm>#include<iostream>using namespace std;const int maxn = 150005;int n, W, H, a[maxn], f[maxn][2];long long sum, ans;int main(){ while (~scanf("%d%d%d", &n, &W, &H)) { f[0][0] = f[0][1] = sum = 0; for (int i = 1; i <= W + n + W; i++) { if (W < i && i <= n + W) scanf("%d", &a[i]); else a[i] = 0; sum += a[i]; f[i][0] = f[i - 1][0]; f[i][1] = f[i - 1][1]; if (a[i] < H) f[i][0] +=H - a[i]; else f[i][1]+= a[i] - H; } if ((long long)W*H > sum) printf("-1\n"); else { ans = 0x7FFFFFFF; for (int i = W; i <= n + W + W; i++) ans = min(ans, (long long)max(f[i][0] - f[i - W][0], f[i][1] - f[i - W][1])); cout << ans << endl; } }}
0 0
- HDU 5191 Building Blocks
- hdu 5191 Building Blocks
- hdu 5191 Building Blocks
- hdu 5191-Building Blocks
- HDU 5191 Building Blocks
- Building Blocks (hdu 5191)
- hdu 5191 Building Blocks (汗!)
- HDU 5191 Building Blocks (模拟)
- hdu 5191 Building Blocks(前缀和)
- HDU 5191 Building Blocks(枚举)
- hdu 5191 Building Blocks(模拟,思路)
- Hdu 5192 Building Blocks Ⅱ
- HDOJ 5191 Building Blocks
- BC#34 1002 hdu 5192 Building Blocks
- HDU—— 5159 Building Blocks
- Building Blocks
- HDU - 5190 - Go to movies && 5191 - Building Blocks (BC#34 A,B)
- HDU 5192 Building Blocks Ⅱ(树状数组)
- JVM和DVM区别
- AssetManager查看asset文件中的图片
- nginx基础概念-request
- kuangbinOJ B Lucky Sequence (hash大发)
- Oracle 备份、恢复概念的总结
- HDU 5191 Building Blocks
- mongoDB入门
- memcpy
- 3Sum
- c和c++的一些训练题(11)(二分查找法和顺序查找法)
- php5.4.22 php_memcache.dll
- jq之google地图
- STL中的bitset
- 黑马程序员——IOS基础---Mac OS X