hdu 5191 Building Blocks(前缀和)
来源:互联网 发布:查看端口进程 编辑:程序博客网 时间:2024/04/28 07:16
Building Blocks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1227 Accepted Submission(s): 266
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-1HintIn first case, LeLe move one block from third pile to first pile.
Source
BestCoder Round #34
题意:有好多堆,可以将一堆中取出一个块放到别的堆,或者放到两端形成新的堆,问最少挪几次能形成连续的宽度为w高为h的一排堆
题目分析:记录两个前缀和,一个是需要取走的块数,一个是总的块数,枚举起点,然后对w区间进行处理即可
题目分析:记录两个前缀和,一个是需要取走的块数,一个是总的块数,枚举起点,然后对w区间进行处理即可
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#define MAX 400007using namespace std;typedef long long LL;LL n,w,h;int a;LL out[MAX];LL sum[MAX];int main ( ){ while ( ~scanf ( "%I64d%I64d%I64d" , &n , &w , &h ) ) { LL ans = 1234567891234; memset ( out , 0 ,sizeof ( out ) ); memset ( sum , 0 , sizeof ( sum ) ); for ( int i = w+1 ; i <= w+n; i++ ) { scanf ( "%d" , &a ); out[i] = out[i-1]; if ( a > h ) out[i] += a-h; sum[i] = sum[i-1] + a; } for ( int i = w+n+1 ; i <= n+2*w+2 ; i++ ) out[i] = out[i-1],sum[i] = sum[i-1]; if ( sum[n+2*w] < w*h ) { puts ( "-1" ); continue; } for ( int i = 1 ; i <= w+n ; i++ ) { LL sum1 = sum[i+w-1] - sum[i-1]; LL out1 = out[i+w-1] - out[i-1]; if ( sum1 >= w*h ) ans = min ( ans , out1 ); else ans = min ( ans , w*h - sum1 + out1 ); } printf ( "%I64d\n" , ans ); }}
0 0
- 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 5191 Building Blocks(枚举)
- hdu 5191 Building Blocks(模拟,思路)
- hdu 5191 Building Blocks (汗!)
- HDU 5191 Building Blocks (模拟)
- Hdu 5192 Building Blocks Ⅱ
- HDOJ 5191 Building Blocks
- HDU - 5190 - Go to movies && 5191 - Building Blocks (BC#34 A,B)
- HDU 5192 Building Blocks Ⅱ(树状数组)
- hdu 2818 Building Blocks (并查集)
- Codeforces 838 A Binary Blocks(前缀和)
- BC#34 1002 hdu 5192 Building Blocks
- [转载]理解泛函的概念和能量泛函的梯度下降流
- 链表相关题目
- UVALive 5135 - Mining Your Own Business(点双连通)
- linux下mysql的root密码忘记解决方
- 矩阵可逆的条件以及特征值、特征向量与可对角化条件
- hdu 5191 Building Blocks(前缀和)
- NB的一些算法
- 【三石jQuery视频教程】01.图片循环展示
- 使用atexit函数进行异常处理
- NEUQ 1236: 愚蠢的摄影师
- qgroup type in btrfs
- 多功能手杖的实现(一)前序
- Windows Store Apps note002 about TextBlock TextBox PasswordBox
- 图解OPNET项目的创建过程