Thursday, August 31st
Water Taps Given the locations and ranges of water taps in a 1-dimensional garden, determine the minimum number of taps required to water the garden An irrigation sprinkler courtesy of Nevit Dilmen via Wikipedia . Distributed under the Creative Commons Attribution-Share Alike 3.0 Unported license. No changes made. This problem can be solved in a greedy manner by organizing taps based on their reach First create a vector to store the maximum reaches of taps int minTaps ( int n , vector < int > & ranges ) { vector< int > maxReach (n + 1 ); ... } Then for each tap, determine its left and rightmost reach, minding limits of the garden. Then, for each starting position, use the maxReach vector and the max() function to store the maximum reach of sprinklers beginning from the give start f or ( int i = 0 ; i < ranges . size (); i++) { int start = ...