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 ...
随机推荐
- Jquery中select使用
select获取当前选中的value $('#DDLDEP').change(function () { var depId = $(this).children('option:selected') ...
- 短连接、长连接、轮询、长轮询、WebSocket
短连接 建立连接——数据传输——关闭连接...建立连接——数据传输——关闭连接 定义:短连接是指通讯双方有数据交互时,就建立一个连接,数据发送完成后,则断开此连接,即每次连接只完成一项业务的发送. 应 ...
- day11迭代器 and 闭包
函数名的使⽤以及第一类对象 函数名是一个变量, 但它是一个特殊的变量, 与括号配合可以执行函数的变量. 函数名就是变量名, 函数名存储的是函数的内存地址 函数名可以赋值给其他变量 函数名可以当做容器类 ...
- STM32 SIM800C SIM868 连接OneNet 以及远程控制流程详解
Onenet控制继电器教程 本文基于STM32物联网开发版:https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.29e71debNLqzW ...
- 《C语言程序设计基础1》第二学期第一周学习总结
**<C语言程序设计基础1>第二学期第一周学习总结 一. 本周学习内容总结 一维数组,了解了一维数组的定义(定义一个数组,需要明确数组变量名,数组元素的类型和数组大小,即数组中元素的数量) ...
- 面试和工作中的map
map是C++ STL中的关联容器,存储的是键值对(key-value),可以通过key快速索引到value.map容器中的数据是自动排序的,其排序方式是严格的弱排序(stick weak order ...
- 5.18-笨办法学python-习题17(文件拷贝)
from sys import argv from os.path import exists #又import了一个命令exists,这个命令将文件名字符串作为参数,如果文件存在返回TRUE,否则返 ...
- Oracle入门第六天(下)——高级子查询
一.概述 主要内容: 二.子查询介绍 1.简单子查询(WHERE子查询) SELECT last_name FROM employees WHERE salary > (SELECT salar ...
- Hello World 和 模块分解
Hello World 和 模块分解 在命令行中编译运行HelloWorld public class HelloWorld { public static void main(String[] ar ...
- VirtualBox上LInux命令初步学习
大二的寒假已经接近了尾声,寒假期间我初步使用了VirtualBox虚拟机软件,并安装了ubuntu的操作系统进行了Linux语言的学习.然而寒假期间的学习没有太多的计划,纯粹是为了完成作业而应付性的学 ...