SRM 492 div1level1

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. Definition Class: TimeTravellingGardenerMethod: determineUsageParameters: int[], int[]Returns: intMethod signature: int determineUsage(int[] distance, int[] height)(be sure your method is public) Notes- Two or more points are collinear if they lie on a single straight line. Constraints- 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. Examples0) {2,2}{1,3,10}Returns: 11) {3,3}{3,1,3}Returns: 22) {1,3}{4,4,4}Returns: 03) {4,2}{9,8,5}Returns: 14) {476,465,260,484}{39,13,8,72,80}Returns: 35) {173,36,668,79,26,544}{488,743,203,446,444,91,453}Returns: 56) {2,4,2,2,4,2,4,2,2,4}{2,2,10,10,10,16,16,22,22,28,28}Returns: 6【题解】还是挺简单的。两种情况:1 存在有一颗树高度不变,则需要其他N-1颗树全变化,答案为N-12 否则就有两颗树高度不变,则N^2枚举
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值