二分||三分
别哔哔好伐
安静的coder
展开
-
hdu4004The Frog's Games 二分
河的长度为L, 有n个石头,最多跳m次,求青蛙最少至少能够跳多远的最小值。二分,去年学过,好像也写过,今年还是不会,惭愧。#include#include#include#include#include#includeusing namespace std;int a[500005],b[500005];int main(){ int i,L,n,m;原创 2014-11-13 09:13:18 · 1062 阅读 · 0 评论 -
快速幂取模
用二分,使复杂度由 O(n) 变为 O(logn)#include#includeusing namespace std;/// (b^n)mod m; (a*b mod m) = (a mod m)*(b mod m)mod m O(log n)/// (b^n)mod m; (a - b ) mod m =( (a mod m)-(b mod m)原创 2015-07-09 15:20:02 · 734 阅读 · 0 评论 -
leetcoder-50-Pow(x, n)
Pow(x, n) 可以直接用库函数pow(x,n)一步搞定,但明显这样就没意思了。参考快速幂取模二分,复杂度为O(logn)递归方法class Solution {public: double myPow(double x, int n) { if(n<0) return 1.0/myPow_1(x,-n);原创 2015-07-09 16:46:30 · 852 阅读 · 0 评论 -
leetcode-153-Find Minimum in Rotated Sorted Array
Find Minimum in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum ele原创 2015-07-15 22:24:33 · 429 阅读 · 0 评论