HDU 5191 Building Blocks
题目链接:
hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5191
bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=572&pid=1002
题解:
要在原始的n堆前面扩展w个空堆,同时在原始n堆后面扩展w个空堆,然后对[0,w+n+w)这个区间考虑所有的长度为w的子区间,计算出需要移动的方块数,更新答案。
代码:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL; const int maxn = +; int n;
LL w, h;
int arr[maxn*]; void init() {
memset(arr, , sizeof(arr));
} int main() {
while (scanf("%d%lld%lld", &n, &w,&h) == && n) {
init();
LL sum = ;
for (int i = ; i < n; i++) {
scanf("%d", arr + i+w);
sum += arr[i+w];
}
if (sum < w*h) {
printf("-1\n");
continue;
}
//cntf:总共需要填入多少个方块,cntz:总共需要移出多少个方块,cnt保存连续w个的初始和
LL cntz = ,cntf=w*h, cnt = ;
LL ans = w*h;
for (int i = w; i < *w+n; i++) {
//计算新窗口的cntz,cntf,cnt;
if (arr[i - w] - h>) cntz -= (arr[i - w] - h);
else cntf -= (h - arr[i - w]);
cnt -= arr[i - w];
if (arr[i] - h > ) cntz += arr[i] - h;
else cntf += h - arr[i];
cnt += arr[i]; LL tmp;
if (w*h > cnt) tmp =cntf;
else tmp = cntz; ans = min(ans, tmp);
} printf("%lld\n", ans);
}
return ;
}
HDU 5191 Building Blocks的更多相关文章
- HDU—— 5159 Building Blocks
Problem Description After enjoying the movie,LeLe went home alone. LeLe decided to build blocks. LeL ...
- hdu 5190 Building Blocks
问题描述 看完电影后,乐乐回家玩起了积木. 他已经搭好了n堆积木,他想通过调整积木,使得其中有连续W堆积木具有相同的高度,同时他希望高度恰好为H. 乐乐的积木都这了,也就是说不能添加新的积木,只能移动 ...
- Intel® Threading Building Blocks (Intel® TBB) Developer Guide 中文 Parallelizing Data Flow and Dependence Graphs并行化data flow和依赖图
https://www.threadingbuildingblocks.org/docs/help/index.htm Parallelizing Data Flow and Dependency G ...
- bc.34.B.Building Blocks(贪心)
Building Blocks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- DTD - XML Building Blocks
The main building blocks of both XML and HTML documents are elements. The Building Blocks of XML Doc ...
- 企业架构研究总结(35)——TOGAF架构内容框架之构建块(Building Blocks)
之前忙于搬家移居,无暇顾及博客,今天终于得闲继续我的“政治课”了,希望之后至少能够补完TOGAF方面的内容.从前面文章可以看出,笔者并无太多能力和机会对TOGAF进行理论和实际的联系,仅可对标准的文本 ...
- TOGAF架构内容框架之构建块(Building Blocks)
TOGAF架构内容框架之构建块(Building Blocks) 之前忙于搬家移居,无暇顾及博客,今天终于得闲继续我的“政治课”了,希望之后至少能够补完TOGAF方面的内容.从前面文章可以看出,笔者并 ...
- HDU 5033 Building(单调栈)
HDU 5033 Building(单调栈) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5033 Description Once upon a ti ...
- [翻译]Review——How JavaScript works:The building blocks of Web Workers
原文地址:https://blog.sessionstack.com/how-javascript-works-the-building-blocks-of-web-workers-5-cases-w ...
随机推荐
- C# 操作word 模板 值 替换
1.引用 aspose.words dll 2.word 使用doc 3.给word 模板中添加要替换位置的 书签 .引用 aspose.words dll .word 使用doc .给word ...
- C# 系统应用之鼠标模拟技术及自动操作鼠标
游戏程序的操作不外乎两种——键盘输入控制和鼠标输入控制,几乎所有游戏中都使用鼠标来改变角色的位置和方向,本文主要是讲述如何使用C#调用Windows API函数实现鼠标模拟操作的功能.首先通过结合Fi ...
- 【ElasticSearch故障处理】OpenJDK 64-Bit Server VM warning
[故障描述] VM虚拟机安装ElasticSearch集群,有三台Linux,完成安装后,执行启动命令:bin/elasticsearch -d . 运行结果报错: OpenJDK 64-Bit Se ...
- go语言的cron包的简单使用
3.cron举例说明 每隔5秒执行一次:*/5 * * * * ? 每隔1分钟执行一次:0 */1 * * * ? 每天23点执行一次:0 0 ...
- PAT-A 1009. Product of Polynomials
参考:https://www.jianshu.com/p/e7a3ee0f82d9 #include<bits/stdc++.h> using namespace std; ; doubl ...
- 20155203 2016-2017-2 《Java程序设计》第2周学习总结
20155203 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 第三章的主要内容是使用Java语言设计程序的基础语法的学习 java语言中的计算:如果两个数 ...
- 20155210 2016-2017-2 《Java程序设计》第10周学习总结
20155210 2016-2017-2 <Java程序设计>第10周学习总结 教材学习内容总结 计算机网络概述 网络编程的实质就是两个(或多个)设备(例如计算机)之间的数据传输.按照计算 ...
- 20155214 2016-2017-2 《Java程序设计》第4周学习总结
20155214 2016-2017-2 <Java程序设计>第4周学习总结 教材学习内容总结 Chapter6 父类就是将多个类的相同代码提升(Pull Up) 子类继承父类会继承到pr ...
- WPF MVVM从入门到精通6:RadioButton等一对多控件的绑定
原文:WPF MVVM从入门到精通6:RadioButton等一对多控件的绑定 WPF MVVM从入门到精通1:MVVM模式简介 WPF MVVM从入门到精通2:实现一个登录窗口 WPF MVVM ...
- 北京Uber优步司机奖励政策(4月15日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...