peak

Peak Index in a Mountain Array

泄露秘密 提交于 2020-03-09 15:39:58
Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] Given an array that is definitely a mountain, return any i such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] . Example 1: Input: [0,1,0] Output: 1 Example 2: Input: [0,2,1,0] Output: 1 思路:就是binary search;mid跟mid+1比较; class Solution { public int peakIndexInMountainArray(int[] A) { if(A == null || A.length == 0) { return 0; } int start = 0; int end = A.length - 1; while(start + 1

linux / unix进程的峰值内存使用情况

↘锁芯ラ 提交于 2020-02-27 21:11:08
是否有一个工具可以运行命令行并报告峰值RAM使用总量? 我在想象类似于/ usr / bin / time的东西 #1楼 Valgrind单线: valgrind --tool=massif --pages-as-heap=yes --massif-out-file=massif.out ./test.sh; grep mem_heap_B massif.out | sed -e 's/mem_heap_B=\\(.*\\)/\\1/' | sort -g | tail -n 1 注意使用--pages-as-heap来测量进程中的所有内存。 更多信息: http : //valgrind.org/docs/manual/ms-manual.html #2楼 如果进程运行至少几秒钟,那么您可以使用以下bash脚本,它将运行给定的命令行,然后打印到stderr峰值RSS(替换 rss 您感兴趣的任何其他属性)。 它有点轻量级,它适用于我使用Ubuntu 9.04中包含的 ps (我不能说 time )。 #!/usr/bin/env bash "$@" & # Run the given command line in the background. pid=$! peak=0 while true; do sleep 1 sample="$(ps -o rss= $pid 2>

The Best Peak Shape

泄露秘密 提交于 2020-02-09 00:02:28
In many research areas, one important target of analyzing data is to find the best "peak shape" out of a huge amount of raw data full of noises. A "peak shape" of length L is an ordered sequence of L numbers { D ​ 1 ​​, ⋯, D ​ L ​​ } satisfying that there exists an index i ( 1) such that D ​ 1 ​​ < ⋯ < D ​ i − 1 ​​ < D ​ i ​​ > D ​ i + 1 ​​ > ⋯ > D ​ L ​​. Now given N input numbers ordered by their indices, you may remove some of them to keep the rest of the numbers in a peak shape. The best peak shape is the longest sub-sequence that forms a peak shape. If there is a tie, then the most

[LeetCode 解题报告]162. Find Peak Element

江枫思渺然 提交于 2020-02-01 20:05:04
A peak element is an element that is greater than its neighbors. Given an input array nums , where nums[i] ≠ nums[i+1] , find a peak element and return its index. The array may contain multiple peaks, in that case return the index to any one of the peaks is fine. You may imagine that nums[-1] = nums[n] = -∞ . Example 1: Input: nums = [1,2,3,1] Output: 2 Explanation: 3 is a peak element and your function should return the index number 2. Example 2: Input: nums = [1,2,1,3,5,6,4] Output: 1 or 5 Explanation: Your function can return either index number 1 where the peak element is 2, or index

852. Peak Index in a Mountain Array

我怕爱的太早我们不能终老 提交于 2020-01-25 21:56:08
852. 山脉数组的峰顶索引 我们把符合下列属性的数组 A 称作山脉: A.length >= 3 存在 0 < i < A.length - 1 使得 A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] 给定一个确定为山脉的数组,返回任何满足 A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] 的 i 的值。 示例 1: 输入:[0,1,0] 输出:1 示例 2: 输入:[0,2,1,0] 输出:1 提示: 3 <= A.length <= 10000 0 <= A[i] <= 10^6 A 是如上定义的山脉 解法一 //时产复杂度O(n), 空间复杂度O(1) class Solution { public: int peakIndexInMountainArray(vector<int>& A) { int n = A.size(), i; for(i = 1; i < n; i++) { if(A[i - 1] < A[i]) continue; break; } return i - 1; } }; 解法二 //时间复杂度O(logn), 空间复杂度O(1) class Solution { public: int

生理周期 (枚举)

瘦欲@ 提交于 2020-01-22 03:12:09
生理周期  输入 输入四个整数:p, e, i和d。 p, e, i分别表示体力、情感和 智力高峰出现的日子。d是给定的日子,可能小于p, e或 i。 所有给定日子是非负的并且小于或等于365,所求的日子小于 或等于21252。  输出 从给定日子起,下一次三个高峰同一天的日子(距离给定日子 的天数)。  输入样例 0 0 0 0 0 0 0 100 5 20 34 325 4 5 6 7 283 102 23 320 203 301 203 40 -1 -1 -1 -1  输出样例 Case 1: the next triple peak occurs in 21252 days. Case 2: the next triple peak occurs in 21152 days. Case 3: the next triple peak occurs in 19575 days. Case 4: the next triple peak occurs in 16994 days. Case 5: the next triple peak occurs in 8910 days. Case 6: the next triple peak occurs in 10789 days. 简单的枚举,但是里面跳着试的思想真的是一个不错的思想!!! 问题相同,所用的思想却不同。

Day7 - K - Biorhythms POJ - 1006

喜你入骨 提交于 2020-01-21 19:30:01
Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes will be sharper and concentration will be easier. Since the three cycles have different periods, the peaks of the three cycles

Python Challenge 第五关

半世苍凉 提交于 2019-12-17 12:13:45
进入第五关,一张图和一行提示: pronounce it。右键源代码,只有一行注释: <!-- peak hell sounds familiar ? --> peak hell 听起来熟悉不?这我还真不熟悉。。再看其他部分,有个 <peakhell src =" banner.p "/>,这个 banner.p 是个链接,点进去一看,又是一堆乱码,这下我真没辙了。想了好久,去网上搜,说是用 pickle 模块,因为发音和 peak hell 很像。。。-_-||| 这理由真是雷死人不偿命。。。 印象中这个模块是用来序列化的,就去网上搜了下资料,先把这个序列化反序列化一下: url = 'http://www.pythonchallenge.com/pc/def/banner.p' rst = urllib.urlopen(url).read() pList = pickle.loads(rst) print pList 输出了这么个东西: [[(' ', 95)], [(' ', 14), ('#', 5), (' ', 70), ('#', 5), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)

opencv-python 指静脉的ROI(感兴趣区域)提取(原理+代码)

房东的猫 提交于 2019-12-17 00:07:43
静脉采集过程中,由于手指自由度比较大,所以可能会有手指旋转,平移等现象,这有可能使得同一个手指的两次采集图像差别较大。这是我们不希望看到的。所以对图像进行ROI的提取非常有必要,也是图像预处理的一个过程。 本文:阐述我是如何对一张图片进行指节的区分的 原理:由于指节的两端有关节腔,而关节腔内部主要是软骨和组织液,这样会使得在图片中关节腔的位置会比较亮,而根据这一特点,我们就可以方便的知道指节是哪个位置了。 代码及其原理: import cv2 as cv import numpy as np from matplotlib import pyplot as plt test_1= cv.imread('test_1.bmp',0) test0=cv.imread('test.bmp',0) gray_map=test0[240] gray_map_1=test_1[240] plt.plot(gray_map);plt.show() plt.plot(gray_map_1);plt.show() test0和test_1是我们用来实践的两张图(不同手指,网页存在拉伸): 在代码中,两句plt.plot()可以让我们清楚的看到在图像腰部的位置([240])的灰度分布 (上:test0,下test_1) 接下来只要找到灰度值最高的地方就大概是关节腔的位置了。

[LeetCode] 162. Find Peak Element

拜拜、爱过 提交于 2019-12-03 10:38:04
求数组的局部峰值。给一个数组,数组满足条件nums[i] ≠ nums[i+1],求数组峰值的下标。例子 Example 1: Input: nums = [1,2,3,1] Output: 2 Explanation: 3 is a peak element and your function should return the index number 2. Example 2: Input: nums = [1,2,1,3,5,6,4] Output: 1 or 5 Explanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6. 思路是用二分法,因为题目要求时间复杂度是log级别。 时间O(logn) 空间O(1) 1 /** 2 * @param {number[]} nums 3 * @return {number} 4 */ 5 var findPeakElement = function(nums) { 6 let start = 0; 7 let end = nums.length - 1; 8 while (start + 1 < end) { 9 let