Avatar

Organizations

5 results for 二分
  • Alice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens.

    You are given a 0-indexed integer array flowers of size n, where flowers[i] is the number of flowers already planted in the ith garden. Flowers that are already planted cannot be removed. You are then given another integer newFlowers, which is the maximum number of flowers that Alice can additionally plant. You are also given the integers target, full, and partial.

    A garden is considered complete if it has at least target flowers. The total beauty of the gardens is then determined as the sum of the following:

    • The number of complete gardens multiplied by full.
    • The minimum number of flowers in any of the incomplete gardens multiplied by partial. If there are no incomplete gardens, then this value will be 0.

    Return the maximum total beauty that Alice can obtain after planting at most newFlowers flowers.

    leetcode 困难 前缀和 贪心 二分 Created Sun, 10 Apr 2022 12:20:00 +0800
  • 给定一个浮点数 n,求它的三次方根。

    acwing 简单 二分 Created Thu, 07 Apr 2022 17:04:33 +0800
  • 在一个无限大的二维平面上有一个机器人。

    初始时,机器人位于点 (0,0)。

    机器人可以执行四种行动指令:

    • U — 从 (x,y)移动到 (x,y+1);

    • D — 从 (x,y)移动到 (x,y−1);

    • L — 从 (x,y)移动到 (x−1,y);

    • R — 从 (x,y)移动到 (x+1,y)。

    给定一个长度为 n 的指令序列,指令编号 1∼n,机器人将按顺序依次执行序列中的每个行动指令。

    我们希望机器人最终抵达目标地点 (a,b)。

    为了达成这一目的,我们可能需要对指令序列进行修改。

    每次修改可以选择其中一个指令,并将其替换为四种指令之一。

    注意,只能对序列中的指令进行替换,不得随意删除指令或添加额外指令。

    不妨设经过修改的指令中,编号最小的指令编号为 minID,编号最大的指令编号为 maxID。

    我们定义修改成本为 maxID−minID+1。

    例如,将 RRRRRRR 修改为 RLRRLRL,则编号为 2,5,7 的指令经过了修改,修改成本为 7−2+1=6。

    请你计算,为了使得机器人能够最终抵达目标点 (a,b),所需花费的最小修改成本。

    如果不需要对序列进行修改,则成本为 0。

    acwing 困难 二分 Created Sat, 29 Jan 2022 20:41:54 +0800
  • 你有  n  台电脑。给你整数  n  和一个下标从 0  开始的整数数组  batteries ,其中第  i  个电池可以让一台电脑 运行 batteries[i]  分钟。你想使用这些电池让  全部 n  台电脑 同时  运行。

    一开始,你可以给每台电脑连接 至多一个电池 。然后在任意整数时刻,你都可以将一台电脑与它的电池断开连接,并连接另一个电池,你可以进行这个操作 任意次 。新连接的电池可以是一个全新的电池,也可以是别的电脑用过的电池。断开连接和连接新的电池不会花费任何时间。

    注意,你不能给电池充电。

    请你返回你可以让 n  台电脑同时运行的 最长  分钟数。

    leetcode 困难 二分 Created Sun, 16 Jan 2022 12:20:00 +0800
  • 农夫约翰将按字典序排列的 N 头奶牛的名字列表贴在了牛棚的门上。

    每个奶牛的名字都由一个长度介于 1 到 20 之间的由小写字母构成的唯一字符串表示。

    麻烦制造者贝茜将列表中的奶牛名字重新排序打乱了列表。

    此外,她还对每头奶牛的名字中的字母顺序进行了重新排列(也可能保持不变)。

    给定修改过后的列表,请帮助约翰确定列表中的每个名字可能出现在原始列表中的最低和最高位置。

    acwing 简单 贪心 二分 Created Sun, 09 Jan 2022 18:39:18 +0800