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 ... 
随机推荐
- swiper 仿淘宝详情页面 视频图片切换
			1.好兄弟,看一下是否是你需要的 2.废话不多说 直接上代码,复制粘贴一下 自己引用一下swiper.js和css 然后就可以开始玩儿了 <!DOCTYPE html> <html& ... 
- Python学习——编程语言介绍
			开发语言 高级语言:基于C/汇编等封装的语言,如Python.Java.C#.PHP.Go.ruby.C++……生成字节码让C/汇编去识别 低级语言:直接让计算机底层能识别成机器码的语言(计算机再将机 ... 
- U盘直接读写(今天用到了)
			#ifndef INVALID_SET_FILE_POINTER #define INVALID_SET_FILE_POINTER (DWORD)-1 #endif #define FILE_BEGI ... 
- windows系统下系统变量path误删恢复方法
			每台计算机安装程序不同,环境变量path会有不同,若误删了环境变量path,可以如下完美解决. Win+R 输入regedit打开注册表(开始-运行里输入regedit) 找到 HKEY_LOC ... 
- 《Java核心技术36讲》阅读笔记:Exception和Error有什么区别?
			1.Exception 和 Error有什么区别?运行时异常与一般异常有什么区别? Exception和Error都继承自java.lang.Throwable.在Java中只有Throwable的实 ... 
- 20155301 2016-2017-2 《Java程序设计》第3周学习总结
			20155301 2016-2017-2 <Java程序设计>第3周学习总结 教材学习内容总结 1.在clothes类中定义了两个变量,很像C语言中自定义变量,clothes属于非公开类. ... 
- 20155316 实验二《Java面向对象程序设计》实验报告
			实验1 实验内容 参考 博客 完成单元测试的学习 提交最后三个JUnit测试用例(正常情况,错误情况,边界情况)都通过的截图,截图上要有画图加水印,输入自己的学号 本提交点考查JUnit会不会使用,测 ... 
- 20155327李百乾  Exp3 免杀原理与实践
			20155327李百乾 Exp3 免杀原理与实践 实践guocheng 一.Msfvenom使用编码器 1.利用(virustota)[https://www.virustotal.com/]检测实验 ... 
- 20155334 实验二 Java面向对象程序设计
			实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验要求 完成实验.撰写 ... 
- mac生成ssh公私匙
			1. cd ~/.ssh/ 2.ssh-keygen 3.id_rsa.pub文件放入git 4.私匙放进jenkins 
