Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 16.2, Problem 4E
Program Plan Intro
To provide an efficient method by which professor Gekko can determine which water stops he should make according to details mentioned in the question. Also, to prove the method provided as solution is optimal.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
3. Your college quadrangle is 85 meters long and 66 meters wide. When you are late for class, you can walk (well, run) at 7 miles per hour. You are at one corner of the quad, and your class is at the directly opposite corner. How much time can you save by cutting across the quad rather than walking around the edge?
5. A 1-kilogram mass has just been dropped from the roof of a building. I need to catch it after it has fallen exactly 100 meters. If I weigh 80 kilograms and start running at 7 meters per second as soon as the object is released, how far away can I stand and still catch the object?
A group of n tourists must cross a wide and deep river with no bridge in sight. They notice two 13-year-old boys playing in a rowboat by the shore. The boat is so tiny, however, that it can only hold two boys or one tourist. How can the tourists get across the river and leave the boys in joint possession of the boat? How many times need the boat pass from shore to shore?
Let l be a line in the x-yplane. If l is a vertical line, its equation is x = a for some real number a.
Suppose l is not a vertical line and its slope is m. Then the equation of l is y = mx + b, where b is the y-intercept.
If l passes through the point (x₀, y₀), the equation of l can be written as y - y₀ = m(x - x₀).
If (x₁, y₁) and (x₂, y₂) are two points in the x-y plane and x₁ ≠ x₂, the slope of line passing through these points is m = (y₂ - y₁)/(x₂ - x₁).
Instructions
Write a program that prompts the user for two points in the x-y plane. Input should be entered in the following order:
Input x₁
Input y₁
Input x₂
Chapter 16 Solutions
Introduction to Algorithms
Ch. 16.1 - Prob. 1ECh. 16.1 - Prob. 2ECh. 16.1 - Prob. 3ECh. 16.1 - Prob. 4ECh. 16.1 - Prob. 5ECh. 16.2 - Prob. 1ECh. 16.2 - Prob. 2ECh. 16.2 - Prob. 3ECh. 16.2 - Prob. 4ECh. 16.2 - Prob. 5E
Ch. 16.2 - Prob. 6ECh. 16.2 - Prob. 7ECh. 16.3 - Prob. 1ECh. 16.3 - Prob. 2ECh. 16.3 - Prob. 3ECh. 16.3 - Prob. 4ECh. 16.3 - Prob. 5ECh. 16.3 - Prob. 6ECh. 16.3 - Prob. 7ECh. 16.3 - Prob. 8ECh. 16.3 - Prob. 9ECh. 16.4 - Prob. 1ECh. 16.4 - Prob. 2ECh. 16.4 - Prob. 3ECh. 16.4 - Prob. 4ECh. 16.4 - Prob. 5ECh. 16.5 - Prob. 1ECh. 16.5 - Prob. 2ECh. 16 - Prob. 1PCh. 16 - Prob. 2PCh. 16 - Prob. 3PCh. 16 - Prob. 4PCh. 16 - Prob. 5P
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Recall Pigou’s example discussed in class, where there are two roads that connect a source, s, and destination, t. The roads have different travel costs. Fraction x1 of the traffic flow on route 1, and the remainder x2 on route 2. Here consider the following scenario. • The first road has “infinite” capacity but is slow and requires 1 hour travel time, T1 = 1. • The second road always requires at least 15 mins, which then increases as a function of traffic density, T2 = 0.25 + 0.75x2. If drivers act in a “selfish” manner – the user optimal scenario – all the traffic will flow on the second path, as one is never worse off. Worst case scenario for path 2, both paths take one hour. So no one is incentivized to change their behavior. 1. Assume user optimal behavior, and calculate τ the expected travel time per car. 2. If instead we could control the flows, we could minimize the expected travel time. Using the expression in part (a), calculate the optimal allocation of flows x¯1 and ¯x2…arrow_forwardYou are given some tasks of size xK, yK and zK respectively and there are at most 9 tasks each. Determine the best that you could achieve if you are to fill up a hole of size SK, for the following values of x, y, z and S, by maximizing the space used (up to S), i.e. minimizing the used space, if any. Show how many tasks of size x, how many tasks of size y and how many tasks of size z are used in each of the three cases. (g) Now if we relax the requirement so that there are no upper limits on the number of tasks for each type, determine the maximal space usage and the task mix. (h) If we tighten the requirement so that there are still at most 9 tasks of each size, but we also require that each type of tasks must be used at least once, determine maximal space usage and the task mix. Case 1 2 3 X 22 26 28 y 33 43 65 50 77 74 S 488 556 777 You could complete the following table. Fill in the number of tasks inside the brackets and the corresponding maximal usage. (At most 9 tasks each (g)…arrow_forwardThree prisoners have been sentenced to long terms in prison, but due to over crowed conditions, one prisoner must be released. The warden devises a scheme to determine which prisoner is to be released. He tells the prisoners that he will blindfold them and then paint a red dot or blue dot on each forehead. After he paints the dots, he will remove the blindfolds, and a prisoner should raise his hand if he sees at least one red dot on the other two prisoners. The first prisoner to identify the color of the dot on his own forehead will be release. Of course, the prisoners agree to this. (What do they have to lose?) The warden blindfolds the prisoners, as promised, and then paints a red dot on the foreheads of all three prisoners. He removes the blindfolds and, since each prisoner sees a red dot (in fact two red dots), each prisoner raises his hand. Some time passes when one of the prisoners exclaims, "I know what color my dot is! It's red!" This prisoner is then released. Your problem…arrow_forward
- You have a five-quart jug, a three-quart jug, and an unlimited supply of water (butno measuring cups). How would you come up with exactly four quarts of water? Note that the jugs are oddly shaped, such that filling up exactly "half" of the jug would be impossible.arrow_forwardI don't need a code for these questions. I just need them answered Nine steel specimens were submerged in seawater at various temperatures, and the corrosion rates were measured. The results are presented in the following table:Temperature (OC)Corrosion(mm/yr.)26.6 1.5826 1.4527.4 1.1321.7 0.9614.9 0.9911.3 1.0515 0.828.7 0.688.2 0.59a. Construct a scatterplot of corrosion (y) vs. temperature (x). Verify that a linear model is appropriate.b. What is the least-square line (trendline/regression line) for predicting corrosion from temperature?c. Two steel specimens whose temperatures differ by 10OC are submerged in seawater. By how much would you predict their corrosion rates differ?d. Predict the corrosion rate for steel submerged in seawater at a temperature of 20OC.e. Construct a table with predicted values from the original dataset.f. Compute the residuals. Which point has the residual with the largest magnitude?g. What is the correlation between temperature and corrosion rate? What…arrow_forward2. In Africa there is a very special species of bee. Every year, the female bees of such species give birth to one male bee, while the male bees give birth to one male bee and one female bee, and then they die! Now scientists have accidentally found one “magical female bee” of such special species to the effect that she is immortal, but still able to give birth once a year as all the other female bees. The scientists would like to know how many bees there will be after N years. Please write a program that helps them find the number of male bees and the total number of all bees after N years. Input Each line of input contains an integer N (≥ 0). Input ends with a case where N = −1. (This case should NOT be processed.) Output Each line of output should have two numbers, the first one being the number of male bees after N years, and the second one being the total number of bees after N years. (The two numbers will not exceed 232.) Sample Input 1 3 -1 Sample Output 1 2 4 7arrow_forward
- Let l be a line in the x-y plane. If l is a vertical line, its equation is x 5a for some real number a. Suppose l is not a vertical line and its slope is m. Then the equation of l is y 5mx 1b, where b is the y-intercept. If l passes through the point (x0, y0,), the equation of l can be written as y 2y0 5m(x 2x0 ). If (x1, y1) and (x2, y2) are two points in the x-y plane and x1 ≠ x2, the slope of line passing through these points is m 5(y2 2y1 )/(x2 2x1 ). Write a program that prompts the user two points in the x-y plane. The program outputs the equation of the line and uses if statements to determine and output whether the line is vertical, horizontal, increasing, or decreasing. If l is a non-vertical line, output its equation in the form y 5mx 1b.arrow_forwardIn the new post-apocalyptic world, the world queen is desperately concernedabout the birth rate. Therefore, she decrees that all families should ensure that they have one girl orelse they face massive fines. If all families abide by this policy-that is, they have continue to havechildren until they have one girl, at which point they immediately stop-what will the gender ratioof the new generation be? (Assume that the odds of someone having a boy or a girl on any givenpregnancy is equal.) Solve this out logically and then write a computer simulation of it.arrow_forwardA circus is planning a tower act in which individuals stand on top of one another's shoulders. Each individual must be both shorter and lighter than the person below him or her for practical and aesthetic reasons. Write a way to determine the maximum feasible number of people in such a tower given the heights and weights of each individual in the circus.arrow_forward
- With this exercise, we shall develop a solution to the following riddle. Two adults, their three children, and their dog are on a walk when they come upon a river. They have a boat, but it can only hold a maximum of one adult with either one child or the dog; or three chidren; or two children and the dog. Anyone (other than the dog) can row the boat; but it would be too much work for one child to row across by themself. How can they all get across the river? You are required to solve this riddle by modelling it using a labelled transition system (LTS). 1. What are the states of your LTS consist of? Make sure you consider all the aspects of the riddle. Justify your notion of state. 2. What are the actions of your LTS? List all the actions. Justify your choice of actions. 3. Drawing out the entire LTS may be a time consuming task as there could be very many states and transitions. However, drawing out only part of the LTS is doable. Draw part of the LTS, anywhere between 7 and 12…arrow_forwardA Norman window has the shape of a rectangle surmounted by a semicircle. Suppose the outer perimeter of such a window must be 600 cm. In this problem you will find the base length x which will maximize the area of such a window. Use calculus to find an exact answer. When the base length is zero, the area of the window will be zero. There is also a limb on how large x can her when x is large enough, the rectangular portion of the window shrinks down to zero height. What is the exact largest value of x when this occurs?arrow_forwardMajor Luna is sending military troops from his base (A) to the town of G. However, there is no direct route between A and G. Instead, the troops must pass through other places, namely: B, C, D, E, and F. The following routes are possible: A to B, A to C, B to F, C to D, C to E, D to G, E to G, and F to G. For some reason, such places can only accommodate a number of soldiers going through these places. B, C, D, E, and F has a capacity of 3, 3, 9, 6, and 4 soldiers. b. Solve the problem using the Ford-Fulkerson algorithm.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Operations Research : Applications and AlgorithmsComputer ScienceISBN:9780534380588Author:Wayne L. WinstonPublisher:Brooks Cole
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole