NEWTimeTravellingGardener
There are N trees arranged in a straight horizontal line. They are numbered 0 through N-1 from left to right. The distance between tree i and tree (i+1) is distance[i], and the initial vertical height of tree i is height[i]. Each tree is assumed to be a perfect vertical segment.
Your goal is to make the topmost points of all the trees collinear. To do this, you can choose any number of trees and have them travel back to a time when they were shorter. You can decrease the height of each chosen tree to any non-negative value (not necessarily an integer). You will operate on each tree individually, so the trees do not all have to decrease in height by the same amount. The trees that you do not choose will all remain at their original heights.
Return the minimum number of trees you must send back in time to achieve this goal.
Input contains multiple test cases. For each case, the first line contains one positive N where N is the total trees, the N-1 number in the second line represents each element of distance, and N number in third line represents each tree height.
- distance will contain between 1 and 49 elements, inclusive.
- Each element of distance will be between 1 and 1000, inclusive.
- The number of elements in height will be one plus the number of elements in distance.
- Each element of height will be between 1 and 1000, inclusive.
Print the minimum number of trees you must send back in time to achieve this goal per line.
3
2 2
1 3 10
3
3 3
3 1 3
3
1 3
4 4 4
3
4 2
9 8 5
1
2
0
1
Case1、Case2、Case3、Case4见下图:
精练的代码:
思想是任意两棵树顶点做两点式,去判断其他树与该直线的关系,统计后得出最少要砍几棵树。