[LintCode] Copy Books 复印书籍

Given an array A of integer with size of n( means n books and number of pages of each book) and k people to copy the book. You must distribute the continuous id books to one people to copy. (You can give book A[1],A[2] to one people, but you cannot give book A[1], A[3] to one people, because book A[1] and A[3] is not continuous.) Each person have can copy one page per minute. Return the number of smallest minutes need to copy all the books.

Have you met this question in a real interview?

Yes

Example

Given array A = [3,2,4], k = 2.

Return 5( First person spends 5 minutes to copy book 1 and book 2 and second person spends 4 minutes to copy book 3. )

Challenge

Could you do this in O(n*k) time ?

时间: 2024-10-18 13:00:11

[LintCode] Copy Books 复印书籍的相关文章

LintCode - Copy List with Random Pointer

LintCode - Copy List with Random Pointer LintCode - Copy List with Random Pointer Web Link Description Code - C Tips Web Link http://www.lintcode.com/en/problem/copy-list-with-random-pointer/ Description A linked list is given such that each node con

Copy Books

Description Given n books and the i-th book has pages[i] pages. There are k persons to copy these books. These books list in a row and each person can claim a continous range of books. For example, one copier can copy the books from i-th to j-th cont

Copy Books II

Description Given n books and each book has the same number of pages. There are k persons to copy these books and the i-th person needs times[i] minutes to copy a book. Each person can copy any number of books and they start copying at the same time.

算法-书籍复印(二分法)

今天在lintCode又做了一道关于非常规二分法的使用,觉得还是有必要记录下来. 题意: 给出一个数组A包含n个元素,表示n本书以及各自的页数.现在有个k个人复印 书籍,每个人只能复印连续一段编号的书,比如A[1],A[2]由第一个人复印,但 是不能A[1],A[3]由第一个人复印,求最少需要的时间复印所有书. 样例: A = [3,2,4],k = 2 返回5,第一个人复印前两本书 这个题看上去感觉好难的样子,但是实际上,这个题非常的简单,就是一个二分法定区间的题.这种题在这之前,我也写了两篇

XML文件解析---SAX方法

XML文件如下: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <books> <book name="book1" num="1" >  出版于1991年 </book> <book name="book2" num="2" >  出版于199

动态规划4 划分型动态规划

题目1:LintCode 108 Palindrome Partitioning II 题目2:LintCode 108 Palindrome Partitioning II Input: "aab" Output: 1 Explanation: Split "aab" once, into "aa" and "b", both palindrome. 将字符串每一段划分成字符串最少划分几次      划分最少,也就是回文串最

HTML5 表单相关的拓展

1 下拉框 <!DOCTYPE html> <html> <head lang="en"> <title></title> <meta charset="utf-8"> </head> <body> <form> 单选 <select> <option>1</option> <option>2</optio

postgresql备份恢复数据库和批量导入导出数据到文件方法

备份数据库:pg_dump -h localhost -U root demo02 > /home/arno/dumps/demo02.bak 恢复数据库:psql -h localhost -U root -d demo <  demo.bak 备份表:pg_dump -h localhost -U root demo02 -t books > /home/arno/dumps/books.bak 恢复表:psql -h localhost -U root -d demo -t boo

【XML】详解XML

目录结构: contents structure [-] 什么是XML 解析XML 解析XML的两种方式 使用dom4j解析xml dom4j的部分API 打印一个XML文件的全部内容 在dom4j中应用XPath解析XML 相关的部分API XPath的路径表达式 通配符 谓语 使用java写一个XMl文件 将一个带有书籍信息的List集合解析为XML文件 1 什么是XML XML(eXtensible  markup language) 是一种可扩展的标记语言 ,即使可以自定义标签的语言.