码迷,mamicode.com
首页 >  
搜索关键字:二分搜索    ( 480个结果
uva 12097 Pie(二分搜索)
uva 12097 Pie My 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...
分类:其他好文   时间:2015-01-29 17:50:43    阅读次数:174
Leetcode#35 Search Insert Position
原题地址二分搜索变种,注意到当左指针和右指针相交后,应该插入的位置总是在左指针处,所以直接返回左指针即可。代码: 1 int searchInsert(int A[], int n, int target) { 2 int l = 0; 3 int r = n - 1...
分类:其他好文   时间:2015-01-28 12:58:55    阅读次数:124
LeetCode --- 4. Median of Two Sorted Arrays
题目链接:Median of Two Sorted Arrays There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 这...
分类:其他好文   时间:2015-01-27 23:34:01    阅读次数:169
Sqrt(x)
Sqrt(x)Implementint sqrt(int x).Compute and return the square root ofx.分析:方案一:遍历0~n, 第一次出现i * i > n,返回 i-1即可。方案二:二分搜索: (1) 当n = 0, 或者 n = 1时,返回 n (2.....
分类:其他好文   时间:2015-01-26 13:24:41    阅读次数:157
Leetcode#162 Find Peak Element
原题地址很有意思的一道题,二分搜索求极值。题目中已经说明num[i] != num[i+1],即相邻元素不可能相等,所以相邻元素间的大小关系要么是大于,要么是小于,这就是二分搜索的判断条件。假设左边界是l,右边界是r,中点m=(l+r)/2如果num[m]比左右两边都大,那么num[m]就已经是极值...
分类:其他好文   时间:2015-01-25 15:12:03    阅读次数:183
[LeetCode] Search in Rotated Sorted Array II 二分搜索
Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to...
分类:其他好文   时间:2015-01-22 01:40:55    阅读次数:130
[LeetCode] Search Insert Position 二分搜索
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or...
分类:其他好文   时间:2015-01-22 01:38:07    阅读次数:116
二分搜索法
给定已排好序的n个元素a[0:n-1],现要在这n个元素中找出一特定元素x。 二分搜索法的基本思想是将n个元素分成个数大致相同的两半,取a[n/2]与x进行比较。如果x=a[n/2],则找到x,算法终止。如果xa[n/2],则只要在数组右半部分继续搜索x。 1 public class bin...
分类:其他好文   时间:2015-01-21 13:18:52    阅读次数:77
POJ 3111 K Best &&NYOJ 914 (二分+ 贪心,最大化平均值)
poj3111 && NYOJ 914 有n个物品的重量和价值分别是w[i]和v[i],从中选出K个物品使得单位重量的价值最大。(1<=k<=n<=10^41<=w[i],v[i]<=10^6)...
分类:其他好文   时间:2015-01-20 10:34:35    阅读次数:182
二分搜索 float
Given a sorted array of floats, find the index of the number closest to x: Example: {1.2, 2.5, 9.3} x = 5, return 1#include#include#include using name...
分类:其他好文   时间:2015-01-19 15:39:44    阅读次数:160
480条   上一页 1 ... 41 42 43 44 45 ... 48 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!