FlowerGarden
TCCC '04 Round 1 · 2004-02-23 · by schveiguy
Problem Statement
You are planting a flower garden with bulbs to give you joyous flowers throughout the year. However, you wish to plant the flowers such that they do not block other flowers while they are visible.
You will be given a
For example, if your garden of flowers has heights 1, 2, and 3, and the flowers of height 3 bloom and wilt with flowers of height 1, but neither conflicts with 2, your best arrangement would be 2,1,3. 1,3,2 would be possible, but then the first row of flowers is shorter, which is less desirable.
You should return a
Constraints
- height will have between 2 and 50 elements, inclusive.
- bloom will have the same number of elements as height
- wilt will have the same number of elements as height
- height will have no repeated elements.
- Each element of height will be between 1 and 1000, inclusive.
- Each element of bloom will be between 1 and 365, inclusive.
- Each element of wilt will be between 1 and 365, inclusive.
- For each element i of bloom and wilt, wilt[i] will be greater than bloom[i].
{5,4,3,2,1}
{1,1,1,1,1}
{365,365,365,365,365}
Returns: { 1, 2, 3, 4, 5 }
These flowers all bloom on January 1st and wilt on December 31st. Since they all may block each other, you must order them from shortest to tallest.
{5,4,3,2,1}
{1,5,10,15,20}
{4,9,14,19,24}
Returns: { 5, 4, 3, 2, 1 }
The same set of flowers now bloom all at separate times. Since they will never block each other, you can order them from tallest to shortest to get the tallest ones as far forward as possible.
{5,4,3,2,1}
{1,5,10,15,20}
{5,10,15,20,25}
Returns: { 1, 2, 3, 4, 5 }
Although each flower only blocks at most one other, they all must be ordered from shortest to tallest to prevent any blocking from occurring.
{5,4,3,2,1}
{1,5,10,15,20}
{5,10,14,20,25}
Returns: { 3, 4, 5, 1, 2 }
The difference here is that the third type of flower wilts one day earlier than the blooming of the fourth flower. Therefore, we can put the flowers of height 3 first, then the flowers of height 4, then height 5, and finally the flowers of height 1 and 2. Note that we could have also ordered them with height 1 first, but this does not result in the maximum possible height being first in the garden.
{1,2,3,4,5,6}
{1,3,1,3,1,3}
{2,4,2,4,2,4}
Returns: { 2, 4, 6, 1, 3, 5 }
Submissions are judged against all 60 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FlowerGarden with a public method vector<int> getOrdering(vector<int> height, vector<int> bloom, vector<int> wilt) · 60 test cases · 2 s / 256 MB per case