down

leetcode 376. 摆动序列 java

*爱你&永不变心* 提交于 2019-12-04 07:18:21
题目: 如果连续数字之间的差严格地在正数和负数之间交替,则数字序列称为摆动序列。第一个差(如果存在的话)可能是正数或负数。少于两个元素的序列也是摆动序列。 例如, [1,7,4,9,2,5] 是一个摆动序列,因为差值 (6,-3,5,-7,3) 是正负交替出现的。相反, [1,4,7,2,5] 和 [1,7,4,5,5] 不是摆动序列,第一个序列是因为它的前两个差值都是正数,第二个序列是因为它的最后一个差值为零。 给定一个整数序列,返回作为摆动序列的最长子序列的长度。 通过从原始序列中删除一些(也可以不删除)元素来获得子序列,剩下的元素保持其原始顺序。 示例 1: 输入: [1,7,4,9,2,5] 输出: 6 解释: 整个序列均为摆动序列。 示例 2: 输入: [1,17,5,10,13,15,10,5,16,8] 输出: 7 解释: 这个序列包含几个长度为 7 摆动序列,其中一个可为[1,17,10,13,10,16,8]。 示例 3: 输入: [1,2,3,4,5,6,7,8,9] 输出: 2 进阶: 你能否用 O(n) 时间复杂度完成此题? 解题: 方法 3:线性动态规划 算法 数组中的任何元素都对应下面三种可能状态中的一种: 上升的位置,意味着 nums[i] > nums[i - 1]nums[i]>nums[i−1] 下降的位置,意味着 nums[i] < nums

python强制结束线程的那点事

故事扮演 提交于 2019-12-04 06:28:41
  在使用python3下载图片时, 常用的方法有urlretrieve和requests两种, 不管哪种方法在网速极慢的情况下, 会出现图片下载卡住现象。那如何解决呢? 小编根据网上提供的资料测试了几种方法。 1、socket: 设置默认超时   正常下载的情况 #!/usr/bin/env python3 # -*- coding:utf-8 -*- # __author__:kzg import datetime import os from urllib.request import urlretrieve # 函数运行计时器 def count_time(func): def int_time(*args, **kwargs): start_time = datetime.datetime.now() # 程序开始时间 func(*args, **kwargs) over_time = datetime.datetime.now() # 程序结束时间 total_time = (over_time-start_time).total_seconds() print("download picture used time %s seconds" % total_time) return int_time # 下载回调函数, 计算下载进度 def callbackinfo

舞蹈链

给你一囗甜甜゛ 提交于 2019-12-04 04:16:58
LuoguP4929 这种数据结构真的是奇妙啊!! 推荐一篇博客 万仓一黍 的博客 Code: 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 250501; 4 int n, m, cnt;//n行m列 cnt是总点数 5 int ans[N]; 6 int row[N];//该点本身所在行 7 int col[N];//该点本身所在列 8 int l[N];//该点水平方向左侧 9 int r[N];//该点水平方向右侧 10 int up[N];//该点竖直方向的上一个点 11 int down[N];//该点竖直方向的下一个点 12 int s[N];//每一列点数 13 int h[N];//每一行表头 14 //这里水平,竖直方向上的列表都是循环的 15 void init(int m) {//初始化 16 for (int i = 0; i <= m; i++) { 17 r[i] = i + 1; 18 l[i] = i - 1; 19 up[i] = down[i] = i; 20 } 21 r[m] = 0; 22 l[0] = m; 23 memset(h, -1, sizeof h); 24 memset(s, 0, sizeof s); 25 cnt = m + 1;/

phpcms 附件下载

我的梦境 提交于 2019-12-03 22:59:25
{if $_username}<a href="{$r[file]}" class="down" target="_blank">点击下载</a>{else} <a href="javascript:alert('请先登录');" class="down" target="_blank">点击下载</a> {/if} 判断登陆 $_username 来源: https://www.cnblogs.com/xaun/p/11810483.html

手把手教你如何写事件处理的代码

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 11:32:06
剖析事件分发的过程 为了模拟实际情况,我特意搞了一幅画View各种嵌套的图 图中有一个 MyViewGroup ,它可以左右滑动,本文就用它来讲解事件处理的代码如何写。 后面的分析需要大家有前面两篇文章的基础,请务必理解清楚,否则你可能会觉得我在讲天书。 ACTION_DOWN 由于我们操作的目标是 MyViewGroup ,因此我会把手指在 MyViewGroup 内容区域内按下,至于按在哪里,其实无所谓,甚至在 TextView 上也行。此时系统会把 ACTION_DOWN 事件经过Activity传递给 ViewGroup0 ,那么问题来了 ViewGroup0 会不会截断事件呢? 如果 ViewGroup0 截断了 ACTION_DOWN 事件,那么它的所有子View在这个事件序列结束前,将无法接收到任何事件,包括 ACTION_DOWN 事件。 MyViewGroup 就是 ViewGroup0 的子View,很显然我们并不希望这样的事情发生。如果真的发生从一开始就截断 ACTION_DOWN 这样的事情,那父View控件的代码写的绝壁有问题。 事件序列是由 ACTION_DOWN 开始,由 ACTION_UP 或者 ACTION_CANCEL 结束,并且中间有0个或者多个 ACTION_MOVE 组成。 那么有没有截断 ACTION_DOWN 事件的情况呢?当然有,

How to get top down forecasts using `hts::combinef()`?

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to compare forecast reconciliation methods from the hts package on previously existing forecasts. The forecast.gts function is not available to me since there is no computationally tractable way to create a user defined function that returns the values in a forecast object. Because of this, I am using the combinef() function in the package to redistribute the forecasts. I have been able to work of the proper weights to get the wls and nseries methods, and the ols version is the default. I was able to get the "bottom up" method

How To Create SubMenu in Drop Down (HTML/CSS)

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I just want create submenu in my drop down ... but I cant find code to fix this. HTML CODE : <nav id='menu'> <ul> <li><a class='home' href='/'>Home</a></li> <li><a class='prett' href='#' title='Menu'>Menu</a> <ul class='menus'> <li><a class='prett' href='Dropdown 1' title='Dropdown 1'>Dropdown 1 + Sub Menu</a> <ul class='submenu'> <li><a href="#" title="Sub Menu">Sub Menu</a></li> </ul> </li> <li><a href='#' title='Dropdown 2'>Dropdown 2</a></li> <li><a href='#' title='Dropdown 3'>Dropdown 3</a></li> </ul> </li> </ul> </nav> CSS CODE : #menu

Text update slowing down app

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a Hebrew calendar app where each day is a UserControl. I have 6 labels in that control for the English date, the Hebrew date, Jewish holidays and some other user-defined data. When scrolling, the labels' content changes as the date value for the UserControl goes up or down a week. The scrolling is noticeably slower than Microsoft Outlook Calendar, and profiling reveals that the part taking the longest is updating the label contents, which is not handled by my code. Is there some way I can make this go faster? MS Outlook seems to have

Implementing a slide down for table rows

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to implement a slide down for table rows using the previous post here I have a newrole table where I click on add icon and it gets added to rolecart table with 3 rows for each item. First row is copied as it is from the role table the next 2 rows are added using jQuery, below is the code. $("#table_newrole img.move-row").live("click", function() { var tr = $(this).closest("tr").remove().clone(); tr.find("img.move-row") .attr("src", "/gra/images/icons/fugue/cross-circle.png") .attr("alt", "Remove"); // first row copied from the

ExecutorService is not shutting down

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following code ExecutorService es = Executors.newSingleThreadExecutor(); es.submit(new Runnable() { @Override public void run() { while(true); } }); es.shutdownNow(); The problem is that the ExecutorService doesn't shutdown after I call shutdownNow. Documentation says that it Attempts to stop all actively executing tasks. So why is the ES failing to shutdown? 回答1: I did this and it worked: ExecutorService es = Executors.newSingleThreadExecutor(); es.submit(new Runnable() { @Override public void run() { while(!Thread.currentThread(