码迷,mamicode.com
首页 >  
搜索关键字:二分    ( 14969个结果
poj 3233 Matrix Power Series(等比矩阵求和)
http://poj.org/problem?id=3233 ps转: 用二分方法求等比数列前n项和:即   原理:   (1)若n==0   (2)若n%2==0     (3)若n%2==1 代码如下: LL sum(LL p,LL n) { if(n==0) return 1; i...
分类:其他好文   时间:2014-06-15 20:01:44    阅读次数:210
二分匹配模版
const int maxn = 10010; int vis[maxn]; int y[maxn]; vector G[maxn]; int n; bool dfs(int u) { for(int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if(vis[v]) continue; vis[v] = true; ...
分类:其他好文   时间:2014-06-15 18:34:38    阅读次数:186
[LeetCode] Search in Rotated Sorted Array [35]
旋转数组中的查找。[1, 2, 3, 4, 5, 6]的一个旋转数组为[4, 5, 6, 1, 2, 3]。在旋转数组中寻找一个数。 最直接的方法,一次遍历,时间复杂度O(n)。但是既然是一个部分有序的数组,那么对于有序的部分我们可以想方法用二分查找。这个效率可以提高。 代码: .......
分类:其他好文   时间:2014-06-15 17:33:21    阅读次数:195
HDU 2813
http://acm.hdu.edu.cn/showproblem.php?pid=2813裸二分图最优匹配,需要用两个map把武将名字映射到点的序号上#include #include #include #include using namespace std;const int N=210;co...
分类:其他好文   时间:2014-06-15 17:21:24    阅读次数:179
Search for a Range
题目 Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target i...
分类:其他好文   时间:2014-06-15 16:53:32    阅读次数:177
[LeetCode] Search for a Range [34]
题目 Given a sorted array of integers, find the starting and ending position of a given target value. 解题思路: 查找一个数出现的范围,给一个排好序的数组和一个数,找出这个数在数组中出现的范围。 这个题直接使用一次遍历就可以得到结果,这样的时间复杂度为O(n)。但是对于有序数组我们一般可以使用二分查找可以得到更好的O(logn)的时间复杂度。我们可以使用二分查找找到这个数第一次出现的位置和这个数最后一次出现的位...
分类:其他好文   时间:2014-06-15 16:19:16    阅读次数:237
java的二分法查找数据
Java二分法查找的源代码: 二分查找是一种高效率线性表的查找算法。在查找时必须将线性表中的关键词排好序。基本思路是:先断定线性表的中心方位 mid=(first+last)/2;对比所要查找的关键词 key与中心方位的关键词的巨细,假如比key和mid.key持平则回来; key比mid.key大...
分类:编程语言   时间:2014-06-14 22:24:17    阅读次数:343
BZOJ2440(完全平方数)二分+莫比乌斯容斥
题意:完全平方数是指含有平方数因子的数。求第ki个非完全平方数。 解法:比较明显的二分,getsum(int middle)求1-middle有多少个非完全平方数,然后二分。求1-middle的非完全平方数个数可以用总数减掉完全平方数个数。计算完全平方数的个数用容斥:     首先加上n/(2*2)+n/(3*3)+n/(5*5)+n/(7*7)...+...然后减掉出现两次的,然后加...
分类:其他好文   时间:2014-06-14 12:09:25    阅读次数:265
Acdreamoj1116(Gao the string!)字符串hash+二分+矩阵快速幂
Problem Description give you a string, please output the result of the following function mod 1000000007 n is the length of the string f() is the function of fibonacci, f(0) = 0, f(1) = 1... a...
分类:其他好文   时间:2014-06-14 11:45:49    阅读次数:243
java的二分法查找数据
Java二分法查找的源代码:二分查找是一种高效率线性表的查找算法。在查找时必须将线性表中的关键词排好序。基本思路是:先断定线性表的中心方位mid=(first+last)/2;对比所要查找的关键词key与中心方位的关键词的巨细,假如比key和mid.key持平则回来;key比mid.key大(假定为升..
分类:编程语言   时间:2014-06-13 21:05:10    阅读次数:436
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!