Knowee
Questions
Features
Study Tools

Drawing BookProblemSubmissionsLeaderboardDiscussionsA teacher asks the class to open their books to a page number. A student can either start turning pages from the front of the book or from the back of the book. They always turn pages one at a time. When they open the book, page is always on the right side:When they flip page , they see pages and . Each page except the last page will always be printed on both sides. The last page may only be printed on the front, given the length of the book. If the book is pages long, and a student wants to turn to page , what is the minimum number of pages to turn? They can start at the beginning or the end of the book.Given and , find and print the minimum number of pages that must be turned in order to arrive at page .ExampleUsing the diagram above, if the student wants to get to page , they open the book to page , flip page and they are on the correct page. If they open the book to the last page, page , they turn page and are at the correct page. Return .Function DescriptionComplete the pageCount function in the editor below.pageCount has the following parameter(s):int n: the number of pages in the bookint p: the page number to turn toReturnsint: the minimum number of pages to turnInput FormatThe first line contains an integer , the number of pages in the book.The second line contains an integer, , the page to turn to.ConstraintsSample Input 062Sample Output 01Explanation 0If the student starts turning from page , they only need to turn page:If a student starts turning from page , they need to turn pages:Return the minimum value, .Sample Input 154Sample Output 10

Question

Drawing BookProblemSubmissionsLeaderboardDiscussionsA teacher asks the class to open their books to a page number. A student can either start turning pages from the front of the book or from the back of the book. They always turn pages one at a time. When they open the book, page is always on the right side:When they flip page , they see pages and . Each page except the last page will always be printed on both sides. The last page may only be printed on the front, given the length of the book. If the book is pages long, and a student wants to turn to page , what is the minimum number of pages to turn? They can start at the beginning or the end of the book.Given and , find and print the minimum number of pages that must be turned in order to arrive at page .ExampleUsing the diagram above, if the student wants to get to page , they open the book to page , flip page and they are on the correct page. If they open the book to the last page, page , they turn page and are at the correct page. Return .Function DescriptionComplete the pageCount function in the editor below.pageCount has the following parameter(s):int n: the number of pages in the bookint p: the page number to turn toReturnsint: the minimum number of pages to turnInput FormatThe first line contains an integer , the number of pages in the book.The second line contains an integer, , the page to turn to.ConstraintsSample Input 062Sample Output 01Explanation 0If the student starts turning from page , they only need to turn page:If a student starts turning from page , they need to turn pages:Return the minimum value, .Sample Input 154Sample Output 10

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

To solve this problem, we need to find the minimum number of pages that must be turned in order to arrive at a specific page in a book. The book has a total of n pages and the student wants to turn to page p.

We can approach this problem by considering two scenarios: starting from the front of the book and starting from the back of the book.

  1. Starting from the front: If the student starts turning pages from the front, they will turn one page at a time until they reach the desired page. In this scenario, the number of pages turned will be p/2.

  2. Starting from the back: If the student starts turning pages from the back, they will turn one page at a time until they reach the desired page. In this scenario, the number of pages turned will be (n-p)/2 if n is even, or (n-p+1)/2 if n is odd.

To find the minimum number of pages turned, we can compare the results from both scenarios and return the smaller value.

Here is the step-by-step solution:

  1. Read the values of n and p from the input.
  2. Calculate the number of pages turned when starting from the front: front_turns = p/2.
  3. Calculate the number of pages turned when starting from the back:
    • If n is even, back_turns = (n-p)/2.
    • If n is odd, back_turns = (n-p+1)/2.
  4. Compare front_turns and back_turns.
  5. Return the smaller value as the minimum number of pages turned.

I hope this helps!

This problem has been solved

Similar Questions

A teacher asks the class to open their books to a page number. A student can either start turning pages from the front of the book or from the back of the book. They always turn pages one at a time. When they open the book, page is always on the right side:When they flip page , they see pages and . Each page except the last page will always be printed on both sides. The last page may only be printed on the front, given the length of the book. If the book is pages long, and a student wants to turn to page , what is the minimum number of pages to turn? They can start at the beginning or the end of the book.Given and , find and print the minimum number of pages that must be turned in order to arrive at page .ExampleUsing the diagram above, if the student wants to get to page , they open the book to page , flip page and they are on the correct page. If they open the book to the last page, page , they turn page and are at the correct page. Return .Function DescriptionComplete the pageCount function in the editor below.pageCount has the following parameter(s):int n: the number of pages in the bookint p: the page number to turn toReturnsint: the minimum number of pages to turnInput FormatThe first line contains an integer , the number of pages in the book.The second line contains an integer, , the page to turn to.ConstraintsSample Input 062Sample Output 01Explanation 0If the student starts turning from page , they only need to turn page:If a student starts turning from page , they need to turn pages:Return the minimum value, .Sample Input 154Sample Output 10Explanation 1If the student starts turning from page , they need to turn pages:If they start turning from page , they do not need to turn any pages:Return the minimum value, .

The students in Mrs. Reed's English class are reading the same -page novel. Three friends, Alice, Bob and Chandra, are in the class. Alice reads a page in seconds, Bob reads a page in seconds and Chandra reads a page in seconds. Chandra and Bob, who each have a copy of the book, decide that they can save time by `team reading' the novel. In this scheme, Chandra will read from page to a certain page and Bob will read from the next page through page finishing the book. When they are through they will tell each other about the part they read. What is the last page that Chandra should read so that she and Bob spend the same amount of time reading the novel?

In a book, the page numbers are given in form a, b, b, c, c, c,….find the alphabet written on the 100th page of the book. N

Edward is making a book. He writes the page number on each page, starting with page number 1 (1, 2, 3, 4, ...). He will stop as soon as he writes a total of 999 digits. What will be the last page number he writes?

orrect answerRANI gave her project assignment to a shopkeeper for binding. There were 19 pages including a cover page, 12 pages of theory and 6 pages of drawings. She told the shopkeeper that the theory pages are in a particular order and the drawing pages can be arranged anywhere provided they are together. If the cover page is always kept first what is the probability that rest of the pages are arranged as per requirement?Options12𝐶1×6!/18!13×40/17!13𝐶1×6!/19!13!×6!/18!

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.