Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7862179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:01:35+00:00 2026-06-02T23:01:35+00:00

Here is a very interesting java problem I’ve found: Before book printing was found

  • 0

Here is a very interesting java problem I’ve found:

Before book printing was found the books were copied by certain people called “writers”.
The bookkeeper has a stack of N books that need to be copied.For that purpose he has K writers. Each book can have a different number of pages and every writer can only take books from the top of the stack (if he takes book 1 then he can take book 2 but not book 4 or book 5). The bookkeeper knows the number of pages each book has and he needs to share the books between the writers in order for the maximum number of pages a writer has to copy to be the minimum possible.The pages of course can’t be split for example you can’t have a 30 page book split into 15 and 15.

For example if we have 7 books with 3 writers and the books pages accordingly: 30 50 5 60 90 5 80 then the optimal solution would be for the first writer to take the first 4 books, the second writer the next book and the 3rd the last two books so we would have:

1st = 145 pages
2nd = 90 pages
3rd = 85 pages

So the program is to write an algorithm which finds the optimal solution for sharing the pages between the writers. So in the end of the program you have to show how many pages each one got.

This was in a programming contest years ago and I wanted to give it a try and what I’ve found so far is that if you take the total number of pages of all the books and divide them by the number of writers you get in the example 106.66 pages and then you try to give to each writer the continuous books from the stack that are closest to that number, but that doesn’t work well at all for large page numbers especially if the number of pages a book has exceeds the total number of pages divided by the number of writers

So share your opinion and give tips and hints if you’d like, mathematical or whatever, this is a very interesting algorithm to be found!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:01:36+00:00Added an answer on June 2, 2026 at 11:01 pm

    I’ve come up with a straight forward solution, perhaps not very efficient, but the logic works. Basically you start with the number of writers being the same number as that of the number of books and reduce until you have your number of writers.

    To show with an example. Suppose you start with your seven values, 30 50 5 60 90 5 80. For each step you reduce it by one by summing up the “lowest pair”. The values in bold are the pair being carried on to the next iteration.

    7
    30 50 5 60 90 5 80
    6
    30 55 60 90 5 80
    5
    30 55 60 90 85
    4
    85 60 90 85
    3
    145 90 85

    With some pseudo programming, this example shows how it could be implemented

    main(books: { 30 50 5 60 90 5 80 }, K: 3)
    
    define main(books, K)
      writers = books
      while writers.length > K do
        reduceMinimalPair(writers)
      endwhile
    end
    
    define reduceMinimalPair(items)
      index = 0
      minvalue = items[0] + items[1]
      for i in 1..items.length-1 do
        if items[i] + items[i + 1] < minvalue then
          index = i
          minvalue = items[i] + items[i + 1]
        endif
      endfor
      items.removeat(index)
      items.removeat(index + 1)
      items.insertat(index, minvalue)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is one very interesting problem. I am using SQL Server 2008. I have
Here's a very quick example for my problem: http://img19.imageshack.us/img19/3575/workertool.png (I'm not allowed to post
I've seen a very interesting post on Fabio Maulo's blog. Here's the code and
I am having a very interesting problem. The script I wrote below works, but
I am not very well in Java Script and i didn't found a solution
Recently scalaz caught my eye. It looks very interesting, but I have not found
I found this question very interesting : Programmatic Bot Detection I have a very
I have a very interesting problem. I have a table where I have data,
I have a very interesting challenge here for my Flex project development. I now
I have came across a very interesting problem. I have a UILabel and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.