array

Codeforces Round #619 (Motarack's Birthday)

£可爱£侵袭症+ 提交于 2020-02-15 01:59:33
题目: Dark is going to attend Motarack’s birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers. Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows that Motarack hates to see an array that has two adjacent elements with a high absolute difference between them. He doesn’t have much time so he wants to choose an integer k (0≤k≤109) and replaces all missing elements in the array a with k. Let m be the maximum absolute difference between all adjacent elements (i.e. the maximum value of |ai−ai+1| for

1103. Distribute Candies to People--Easy

筅森魡賤 提交于 2020-02-14 21:03:13
We distribute some number of candies, to a row of n = num_people people in the following way: We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person. Then, we go back to the start of the row, giving n + 1 candies to the first person, n + 2 candies to the second person, and so on until we give 2 * n candies to the last person. This process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies. The last person will receive all of our remaining

Eigen 简明教程

∥☆過路亽.° 提交于 2020-02-14 13:34:10
Eigen Quick Reference 一个 Eigen 的参考手册,包含 Python(Numpy) 与 Eigen 的对应用法,以及一些练习题。持续更新中。 Eigen array, matrix and vector types 在 Eigen 中,Matrix 用来表示数学意义上的矩阵和向量,Array 用来表示 1D 和 2D 的数组,你可以这样定义它们: typedef Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options> MyMatrixType; typedef Array<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options> MyArrayType; Scalar 表示系数的类型(例如float, double, boll, int 等等)。 RowsAtCompileTime 和 ColsAtCompileTime 表示矩阵行数和列数(必须在编译时期给定),或者使用 Dynamic 表示其行数或者列数在运行时期给定。 Options 可以是 ColMajor 或者 RowMajor ,它们表示存储数据的顺序,默认是 ColMajor 。( 这里 有存储顺序的更多介绍) 你可以随意的组合上面的参数来创建 Matrix,例如 Matrix

gbdt基本原理

亡梦爱人 提交于 2020-02-14 13:27:15
gbdt 基本原理 为什么要建立多棵树 函数空间上的梯度下降 残差推导 建树过程 第一棵树 第i棵树 如何分裂 如何取值 为什么要建立多棵树 函数空间上的梯度下降 设样本为 ( x j , y j ) , j = 1 , 2 , ⋯   , n \begin{array}{rcl}(x^j,y^j),j=1,2,\cdots,n\end{array} ( x j , y j ) , j = 1 , 2 , ⋯ , n ​ 对于回归问题,损失函数为 L = ∑ j = 1 n l ( x j , y j , f j ) = L ( f 1 , f 2 , ⋯   , f j ) = L ( F ) \begin{array}{rcl}L&=&\sum_{j=1}^nl(x^j,y^j,f^j)\\&=&L(f^1,f^2,\cdots,f^j)\\&=&L(F)\end{array} L ​ = = = ​ ∑ j = 1 n ​ l ( x j , y j , f j ) L ( f 1 , f 2 , ⋯ , f j ) L ( F ) ​ 对于二分类问题,损失函数为 L = ∑ j = 1 n l ( x j , y j , σ ( f j ) ) = L ( f 1 , f 2 , ⋯   , f j ) = L ( F ) \begin{array}{rcl}L&=&

Python list.sort()排序

江枫思渺然 提交于 2020-02-13 17:47:58
List中字典指定元素排序 array = [{"score": "98", "name": "lili", "age": 19}, {"score": "98", "name": "chenming", "age": 18}, {"score": "88", "name": "wangxin", "age": 17}] print("排序前:", array) # 排序前: [{'score': '98', 'name': 'lili', 'age': 19}, {'score': '98', 'name': 'chenming', 'age': 18}, {'score': '88', 'name': 'wangxin', 'age': 17}] array.sort(key=lambda x: x["score"]) print("指定单个元素排序:", array) # 指定单个元素排序: [{'score': '88', 'name': 'wangxin', 'age': 17}, {'score': '98', 'name': 'lili', 'age': 19}, {'score': '98', 'name': 'chenming', 'age': 18}] array.sort(key=lambda x: (x["score"], x["age"])) print(

[Swift]LeetCode1103. 分糖果 II | Distribute Candies to People

吃可爱长大的小学妹 提交于 2020-02-13 14:14:08
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝( https://www.cnblogs.com/strengthen/ ) ➤GitHub地址: https://github.com/strengthen/LeetCode ➤原文地址: https://www.cnblogs.com/strengthen/p/11096567.html ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。 ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创! ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ We distribute some number of candies , to a row of n = num_people people in the following way: We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person. Then, we go back to the start of the row,

十大排序算法

a 夏天 提交于 2020-02-13 02:02:07
好好学习算法基础 0、排序算法说明 0.1 排序的定义 对一序列对象根据某个关键字进行排序。 0.2 术语说明 稳定 :如果a原本在b前面,而a=b,排序之后a仍然在b的前面; 不稳定 :如果a原本在b的前面,而a=b,排序之后a可能会出现在b的后面; 内排序 :所有排序操作都在内存中完成; 外排序 :由于数据太大,因此把数据放在磁盘中,而排序通过磁盘和内存的数据传输才能进行; 时间复杂度: 一个算法执行所耗费的时间。 空间复杂度 :运行完一个程序所需内存的大小。 0.3 算法总结 图片名词解释: n: 数据规模 k: “桶”的个数 In-place: 占用常数内存,不占用额外内存 Out-place: 占用额外内存 0.5 算法分类 0.6 比较和非比较的区别 常见的 快速排序、归并排序、堆排序、冒泡排序 等属于 比较排序 。 在排序的最终结果里,元素之间的次序依赖于它们之间的比较。每个数都必须和其他数进行比较,才能确定自己的位置。 在 冒泡排序 之类的排序中,问题规模为n,又因为需要比较n次,所以平均时间复杂度为O(n²)。在 归并排序、快速排序 之类的排序中,问题规模通过 分治法 消减为logN次,所以时间复杂度平均 O(nlogn) 。 比较排序的优势是,适用于各种规模的数据,也不在乎数据的分布,都能进行排序。可以说, 比较排序适用于一切需要排序的情况。 计数排序、基数排序

[Algorithm] 448. Find All Numbers Disappeared in an Array

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-12 03:21:35
Given an array of integers where 1 ≤ a[i] ≤ n ( n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n ] inclusive that do not appear in this array. Could you do it without extra space and in O( n ) runtime? You may assume the returned list does not count as extra space. Example: Input: [4,3,2,7,8,2,3,1] Output: [5,6] /** * @param {number[]} nums * @return {number[]} */ var findDisappearedNumbers = function(nums) { let a = new Set(); for (let i = 1; i <= nums.length; i++) { a.add(i); } for (let num of nums) { if (a.has(num)) { a.delete(num) } }

Js中去除数组中重复元素的6种方法

≡放荡痞女 提交于 2020-02-12 02:23:54
方法一: Array.prototype.method1 = function(){ var arr=[]; //定义一个临时数组 for(var i = 0; i < this.length; i++){ //循环遍历当前数组 //判断当前数组下标为i的元素是否已经保存到临时数组 //如果已保存,则跳过,否则将此元素保存到临时数组中 if(arr.indexOf(this[i]) == -1){ arr.push(this[i]); } } return arr; } 方法二: Array.prototype.method2 = function(){ var h={}; //定义一个hash表 var arr=[]; //定义一个临时数组 for(var i = 0; i < this.length; i++){ //循环遍历当前数组 //对元素进行判断,看是否已经存在表中,如果存在则跳过,否则存入临时数组 if(!h[this[i]]){ //存入hash表 h[this[i]] = true; //把当前数组元素存入到临时数组中 arr.push(this[i]); } } return arr; } 方法三: Array.prototype.method3 = function(){ //直接定义结果数组 var arr=[] ; for(var i = 1; i <

Codeforces——C. Anu Has a Function

折月煮酒 提交于 2020-02-12 02:18:23
Codeforces——C. Anu Has a Function Anu has created her own function f: f(x,y)=(x|y)−y where | denotes the bitwise OR operation. For example, f(11,6)=(11|6)−6=15−6=9. It can be proved that for any nonnegative numbers x and y value of f(x,y) is also nonnegative. She would like to research more about this function and has created multiple problems for herself. But she isn’t able to solve all of them and needs your help. Here is one of these problems. A value of an array [a1,a2,…,an] is defined as f(f(…f(f(a1,a2),a3),…an−1),an) (see notes). You are given an array with not necessarily distinct