bc.34.B.Building Blocks(贪心)
Building Blocks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 751 Accepted Submission(s): 164
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.
1 #include<stdio.h>
2 #include<string.h>
3 #include<math.h>
4 #include<algorithm>
5 using namespace std;
6 typedef long long ll ;
7 const int inf = 0x3f3f3f3f ;
8 int n , w , h ;
9
10 ll a[50010 * 3] ;
11
12 int main ()
13 {
14 //freopen ("a.txt" , "r" , stdin ) ;
15 while (~ scanf ("%d%d%d" , &n , &w , &h) ) {
16 int sum = 0 ;
17 memset (a , 0 , sizeof(a)) ;
18 for (int i = w + 1; i <= n + w ; i++) {
19 scanf ("%d" , &a[i]) ;
20 sum += a[i] ;
21 }
22 int blog = w * h ;
23 if (sum < blog ) {
24 puts ("-1") ;
25 continue ;
26 }
27 int minn = inf ;
28 ll l = 0 , r = 0 ;
29 for (int i = 1 ; i <= n + w + w ; i++ ) {
30 a[i] - h < 0 ? l += a[i] - h : r += a[i] - h ;
31
32 if (i >= w) {
33 l = -l ;
34 int temp = max (l , r) ;
35 if (minn > temp ) {
36 minn = temp ;
37 }
38 l = -l ;
39 a[i - w + 1] - h < 0 ? l -= a[i - w + 1] - h : r -= a[i - w + 1] - h ;
40 }
41 }
42
43 // printf ("index = %d\n" , index) ;
44 printf ("%d\n" , minn ) ;
45 }
46 return 0 ;
47 }
bc.34.B.Building Blocks(贪心)的更多相关文章
- [翻译]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 ...
- 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 ...
- 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—— 5159 Building Blocks
Problem Description After enjoying the movie,LeLe went home alone. LeLe decided to build blocks. LeL ...
- 四、Implementation: The Building Blocks 实现:构件
四.Implementation: The Building Blocks 实现:构件 This is the essential part of this guide. We will introd ...
- 2.3 Core Building Blocks 核心构件
Core Building Blocks 核心构件 DDD mostly focuses on the Domain & Application Layers and ignores the ...
- HDU 5191 Building Blocks
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5191 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
随机推荐
- unitty导出工程嵌入iOS原生工程中出现黑屏,但是模型还是可以扫。
一般上出现这个问题,其实就是因为两个注意点没有搞清楚.我们分析一下,如果我们的模型或者视屏能够出来但是屏幕还是黑屏的.说明我们的unity的组件其实已经加载出来了.但是供我们交互的那个Layer类并没 ...
- C#中无边框窗体移动
拖动无边框窗体Form至桌面任何位置 首先建一个Windows应用程序将Form1的 FormBorderStyle属性设置为Noe Point mouseOff;//鼠标移动位置变量 bool le ...
- 我的权限系统设计实现MVC4 + WebAPI + EasyUI + Knockout(四)授权代码维护
一.前言 权限系统设计中,授权代码是用来控制数据访问权限的.授权代码说白了只是一树型结构的数据,没有什么其它的业务意义.那么这个页面的功能也就非常简单授权代码维护:新增.修改.删除授权代码数据. 二. ...
- .NET MVC框架中控制器接收参数的四种方式
1.通过路由中的配置的参数名字直接接收(要求:两者同名) routes.MapRoute( name: "Default", ...
- unity3d NGUI制作角色展示框
最近在搞赛车漂移,所以一直没有更新博客 现在已经实现圈数检测.复位点检测.反向检测等功能 本来准备写成三篇文章的,太忙了,等过段时间不忙了在写吧 今天有朋友问我3D角色怎么给他固定在一个框里面 这个功 ...
- 【JVM】模板解释器--字节码的resolve过程
1.背景 上文探讨了:[JVM]模板解释器--如何根据字节码生成汇编码? 本篇,我们来关注下字节码的resolve过程. 2.问题及准备工作 上文虽然探讨了字节码到汇编码的过程,但是: mov %ra ...
- 『开源』仿SQLServer山寨一个 跨数据库客户端
002 Laura.SqlForever项目简单介绍 相关文章 <『练手』001 Laura.SqlForever架构基础(Laura.XtraFramework 的变迁)> <『练 ...
- 【niubi-job——一个分布式的任务调度框架】----如何开发一个niubi-job的定时任务
引言 上篇文章LZ主要讲解了niubi-job如何安装,如果看过上一篇文章的话,大家应该知道,niubi-job执行的任务是需要用户自己上传jar包的. 那么问题来了,这个jar包如何产生?有没有要求 ...
- ORACLE建表练习
1,学生表 -- Create table create table T_HQ_XS ( xueh ) not null, xingm ) not null, xingb ) ', nianl NUM ...
- 【CodeForces 489A】SwapSort
题 Description In this problem your goal is to sort an array consisting of n integers in at most n sw ...