hdu 5191(思路题)
Building Blocks
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2209    Accepted Submission(s): 509
LeLe has already built n 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.
The first line of input contains three integers n,W,H(1≤n,W,H≤50000).n indicate n piles blocks.
For the next line ,there are n integers A1,A2,A3,……,An indicate the height of each piles. (1≤Ai≤50000)
The height of a block is 1.
If there is no solution, output "-1" (without quotes).
1 2 3 5
4 4 4
1 2 3 4
-1
In first case, LeLe move one block from third pile to first pile.
,然后我们的区间右移到[2,W+1],这时我们要把1删除,然后将w+1添加进去,这样的话对 s,t进行加减,然后取个大值就行了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
const int N = ;
LL n,w,h;
LL high[N];
int main()
{
while(scanf("%lld%lld%lld",&n,&w,&h)!=EOF){
LL sum = ;
memset(high,,sizeof(high));
for(int i=;i<w+;i++){
high[i]-=h;
}
for(int i=w+;i<w++n;i++){
scanf("%lld",&high[i]);
sum+=high[i];
high[i]-=h;
}
for(int i=w++n;i<=w+w+n;i++){
high[i]-=h;
}
if(sum<h*w){
printf("-1\n");
continue;
}
LL s=w*h,t=,ans = w*h; ///s维护将高的拿走,t维护将矮的补上,最开始[1,w]要补w*h进去,所以ans初始化w*h
for(int i=w+;i<=w+w+n;i++){
if(high[i-w]>) t-=high[i-w]; ///删除第 i-w 块
else s+=high[i-w];
if(high[i]>) t+=high[i]; ///添加第 i 块
else s-=high[i];
ans = min(ans,max(t,s));
}
printf("%lld\n",ans);
}
return ;
}
hdu 5191(思路题)的更多相关文章
- hdu 4908(思路题)
		
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
 - Proud Merchants HDU - 3466 (思路题--有排序的01背包)
		
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
 - hdu 5101(思路题)
		
Select Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
 - hdu 5063(思路题-反向操作数组)
		
Operation the Sequence Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
 - hdu 4859(思路题)
		
Goffi and Squary Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
 - hdu 4956(思路题)
		
Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
 - hdu 5400(思路题)
		
Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
 - HDU 1173  思路题
		
题目大意 有n个地点(坐标为实数)需要挖矿,让选择一个地点,使得在这个地方建造基地,到n个地点的距离和最短,输出基地的坐标. 题解+代码: 1 /* 2 把这个二维分开看(即把所有点投影到x轴上,再把 ...
 - 51nod  P1305 Pairwise Sum and Divide ——思路题
		
久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...
 
随机推荐
- 【翻译】ASP.NET Core 文档目录
			
微软官方CORE 2.0正式版中文文档已经出来了,地址:https://docs.microsoft.com/zh-cn/aspnet/core/ 简介 入门 创建一个Web应用程序 创建一个Web ...
 - 关于<!DOCTYPE html>的学习(转)
			
DOCTYPE是对Document type的缩写,说明用XHTML或者HTML是什么版本的.必须出现在<html>标签的前面,不需要关闭标签. <!DOCTYPE>声明不是标 ...
 - Java 中的异常和处理详解(转载)
			
原文出处: 代码钢琴家 简介 程序运行时,发生的不被期望的事件,它阻止了程序按照程序员的预期正常执行,这就是异常.异常发生时,是任程序自生自灭,立刻退出终止,还是输出错误给用户?或者用C语言风格:用函 ...
 - ArcGIS Server中创建的两个账户有什么区别
			
新手常常有这样的疑问: 在安装ArcGIS Server的时候创建的账户和在ArcGIS Server Manager上面创建的账户有什么区别? 解答:前者是是为ArcGIS Server创建的操作系 ...
 - Centos7安装GUI桌面
			
2018-03-02 21:37:48 Centos7-1708成功 yum -y groupinstall "GNOME Desktop"
 - 算法(13)Contiguous Array
			
题目:找出数组的一个子数组,要求这个子数组中0和1的数量相等,找出最大长度的这样的数组! 思路:也是受网上算法的启发吧,用一个 语言:如何初始化一个unordered_map<int,int&g ...
 - 【Python】Python学习----第一模块笔记
			
1.python是什么? python是动态解释型的强类型定义语言. python官方版本的解释器是CPython.该解释器使用C语言开发. 当前主要使用3.x版本的python. 2.第一个pyth ...
 - 使用锚点在HTML页面中快速移动
			
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
 - 【转】Visio画用例模型图竟然没有include关系
			
转自:http://blog.csdn.net/shuixin536/article/details/8289746 由于电脑上没有安装Rose,因此决定用visio来画UML中的用例模型图,在绘制的 ...
 - Python之利用reduce函数求序列的最值及排序
			
在一般将Python的reduce函数的例子中,通常都是拿列表求和来作为例子.那么,是否还有其他例子呢? 本次分享将讲述如何利用Python中的reduce函数对序列求最值以及排序. 我们用r ...