方法-二分法
文章平均质量分 75
STILLxjy
不要让任何人打乱你生活的节奏
展开
-
(LeetCode 069) x的平方根 【分析一道简单题,避免二分查找中死循环的写法】
题目:69. x 的平方根实现 int sqrt(int x) 函数。计算并返回 x 的平方根,其中 x 是非负整数。由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。来源:力扣(LeetCode)分析:题目很简单,很容易就想到使用二分查找。答案区间为 [left, right], 并且 mid = (left + right) >>>1更新条件为:if(mid * mid > x) right = mid - 1;else left = mid;上原创 2020-12-07 16:32:54 · 180 阅读 · 0 评论 -
(POJ1905)Expanding Rods <几何+二分法(解方程)>
Expanding Rods DescriptionWhen a thin rod of length L is heated n degrees, it expands to a new length L’=(1+n*C)*L, where C is the coefficient of heat expansion. When a thin rod is mounted on two so原创 2016-11-30 14:00:37 · 423 阅读 · 0 评论 -
(POJ3258)River Hopscotch <二分法>
River Hopscotch DescriptionEvery year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a lon原创 2016-11-30 12:32:52 · 488 阅读 · 0 评论 -
(POJ3273)Monthly Expense <二分法 + 贪心>
Monthly Expense DescriptionFarmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (原创 2016-11-30 11:12:54 · 692 阅读 · 0 评论 -
(POJ3122)Pie <二分法>
Pie DescriptionMy birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my par原创 2016-11-30 14:42:39 · 396 阅读 · 0 评论 -
(HDU 5726)GCD <RMQ + map + 二分> 多校训练1
GCD Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3087 Accepted Submission(s): 1116Problem Description Give you a sequence of N(N≤100,0原创 2017-01-07 11:32:20 · 571 阅读 · 0 评论 -
(LeetCode 33)搜索旋转排序数组 [分段二分查找]
33 搜索旋转排序数组假设按照升序排序的数组在预先未知的某个点上进行了旋转。( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。搜索一个给定的目标值,如果数组中存在这个目标值,则返回它的索引,否则返回 -1 。你可以假设数组中不存在重复的元素。你的算法时间复杂度必须是 O(log n) 级别。示例 1: 输入: nums = [...原创 2018-09-07 11:42:11 · 439 阅读 · 0 评论 -
(LeetCode 35 and 34)查找第一个大于(等于)target的位置 [二分查找解题思路模板]
35 搜索插入位置给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。你可以假设数组中无重复元素。示例 1: 输入: [1,3,5,6], 5 输出: 2示例 2: 输入: [1,3,5,6], 2 输出: 1示例 3: 输入: [1,3,5,6], 7 输出: 4示例 4: 输入: [1,3...原创 2018-09-07 13:18:06 · 4851 阅读 · 0 评论