frogThroughRiver
青蛙过河description在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧。在桥上有一些石子,青蛙很讨厌踩在这些石子上。由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数轴上的一串整点:0,1,……,L(其中L是桥的长度)。坐标为0的点表示桥的起点,坐标为L的点表示桥的终点。青蛙从桥的起点开始,不停的向终点方向跳跃。一次跳跃的距离是S到T之间的任意正整数(包括S,T)。当青蛙跳到或跳过坐标为L的点时,就算青蛙已经跳出了独木桥。题目给出独木桥的长度L,青蛙跳跃的距离范围S,T,桥上石子的位置。你的任务是确定青蛙要想过河,最少需要踩到的石子数。
input包含多组测试数据,每组测试数据第一行有一个正整数L(1 <= L <= 1000000000),表示独木桥的长度。第二行有三个正整数S,T,M,分别表示青蛙一次跳跃的最小距离,最大距离,及桥上石子的个数,其中1 <= S <= T <= 10,1 <= M <= 100。第三行有 ...
segment-tree
线段树线段树是一种二叉搜索树,他将一个区间划分成为一些单元区间,每个单元区间对应线段树中的一个叶节点。可以使用线段树快速查询某一个节点在若干条线段出现的次数时间复杂度为O(log(n))
代码实现123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566#include <stdio.h>#define MAXL 100005void build_tree(int arr[], int tree[], int node, int start, int end){ if (start == end) { tree[node] = arr[start]; return; } int mid = (start + end) / 2; int left_node = node * 2 + 1; int right_node = node * 2 ...
merge-sort
并归排序并归排序是将两个有序的子序列和并得到一个完整的有序子序列,通过分治法将序列分成多个子序列进行并归排序 ,速度仅仅次与快速排序,为稳定排序算法,一般对总体无序,但是各个子项相对有序的数列
时间复杂度
平均时间复杂度O(nlogn) 最佳时间复杂度O(n)
基本思想
分解: 将n个元素分解成含n/2个元素的子序列
合并: 用合并排序法对两个子序列进行排序
动图演示
代码实现12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758#include<bits/stdc++.h>using namespace std;void merge(int arr[],int L,int M,int R){ int leftSize=M-L; int rightSize=R-M+1; int left[leftSize]; int right[rightSize]; for( ...
manage-npm-version
遇到了一些坑如hexo在npm 14.00时候会一直报错,所以我们安装一个node版本管理模块n
1sudo npm install n
安装稳定版本
1sudo n stable
安装最新版本
1sudo n latest
安装版本号
1sudo n 版本号
例如
1sudo n 12.0
查看当前已有版本号
1n
切换版本号
1n 版本号
删除版本号
1sudo n rm 版本号
navicat-for-linux-cheat
打开这个网站下载版本并且破解即可https://navicat.rainss.cc/
javaScriptLearning
对象hasOwnProperty()检测传递参数是否有该属性
12345678function oss(options){ if(!options.hasOwnProperty('host')){ throw new Error('must set host') }}oss({name:"test"});// will throw Error lack of host
翻译做题技巧
强化讲义例题一 p118
It was the culture , rather than the language (that made it hard for him to adapt to the new environment abroad)—————–使他适应国外的新环境很难
Much (to the researchers’ surprise/amazement )使研究人员感到惊讶, the outcome of the experiment was far better than they had expected.
(It was not until I came here—直到我到了这儿) that I realized this place was famous for not only its beauty but also its weather
It’s said that the power plant is now (twice as large as what it was/twice large than what it ...
53-maximum-subarray
最大连续子序和题目链接
解题思路判断目前子序列最大的值,如果小于的当前nums的值 就吧当前子序列的值换成num值 并且每一步判断下num的值和max值大小
go代码1234567891011121314151617func maxSubArray(nums []int) int { max := nums[0] num := nums[0] for i := 1; i < len(nums); i++ { if num+nums[i] > nums[i] { num += nums[i] } else { num = nums[i] } if num >= max { max = num } } return max}