Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use java discrete structure book ( DStructureBook ) In the Discrete Structures classroom Mali's teacher told the students to open the book to page p
Use java
discrete structure book DStructureBook
In the Discrete Structures classroom Mali's teacher told the students to open the book to page p At that time, Mali might
The book is still open at page k so Mali can choose to open the book by starting at the first page, the last page, or starting at the next k page, but
You can open one page at a time until you reach the desired page. But if Mali opens the book and is stuck at page k if you have to flip to start at page or the last page, count the
Flip this time to add more time as well.
In the books that Mali's teachers let students use, page is always on the right side. And when Mali turns over page you will see pages and as shown in the picture.
The bottom and each sheet of a book are always printed on two sides, except for the last page, where the other side may be blank.
If a book has N pages and Mali's teacher tells her to open page p and the page Mali left open is page k find the number of times in
Minimum number of page flips up to page p Mali can choose to start at the first page, last page, or page k to get the number of flips.
Minimal page turns If Mali cannot open to page p that the teacher specified. Find the value for the least number of flips and enter the result as the value.
negative instead
input data
The input has lines.
The first line consists of one positive integer representing the total number of pages of the book pages, given that
where N is always the correct value.
The second line contains one positive integer representing the page number p that you want to open.
The third line contains one positive integer representing the number k that is left open. If k it means
The book is closed.
Export data
The output data is line. Print the result that is the minimum number of page turns.
Example
data input data output
Export data
If you open from the first page, you must flip times. But if you open from the last page, you must flip times. And if you open from page you will flip only
times, so the answer is
Example
If you open it from the first page, you have to flip it times. But if you open it from the last page, you have to flip it times. And if you open it from page you have to flip it times.
Likewise, so the answer is
Example
Because the book is closed If opening from the first page and opening from page to page it will be the same, meaning you will have to flip times. But if opening from page
In the end, it had to be flipped times, but because page couldn't be opened, a smaller number of times was chosen and a minus sign was put in front of the answer.
is
Example
Because the book is stuck on page which is the same page as the page you want to open. So there is no need to turn the page. But because page doesn't
can be opened because it exceeds the bounds of the book page So put a minus sign. The answer page is
input data
input data
Export data
input data
Export data
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started