array

CSU-2220 Godsend

纵然是瞬间 提交于 2020-03-16 11:17:03
题目链接 http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2220 题目 Description Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will

【CF Round 429 B. Godsend】

北慕城南 提交于 2020-03-16 11:16:03
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who

Javascript数组(array)操作

 ̄綄美尐妖づ 提交于 2020-03-14 18:45:46
数组-Array /*--> */ /*--> */ 创建数组 var aColor=new Array(); aColor[0]="red"; aColor[1]="blue"; /************************** 或者 ***************************/ //var aColor=new Array("red","blue"); //var aColor=["red","blue"]; length属性 数组.length可读可写 document.write(aColor.length);//2 aColor[aColor.length]="green";//在第三项添加"green" 数组的push,pop方法 push可以在数组末尾添加一项,而pop则可以删除末尾项 var count=aColor.push("brown","orange");//可以添加多个值 count返回数值个数 var result=aColor.pop(); //orange shift,unshift shift和unshift方法很像push,pop方法,shift,unshift是对数组前项的添加和删除,比较专业点的说法是:push,pop是后进先出,而shift,unshift是先进先出,不知道我说对了没有。 var item=aColor

NumPy 基础教程

点点圈 提交于 2020-03-14 15:37:47
注:本文是我在阅读 An introduction to Numpy and Scipy 时,一边实践一边记下的笔记。个人觉得这篇介绍 NumPy 的英文文档写的很好,因此如果可以,请停止阅读本文,转去参考此英文文档。 目录 Arrays 其他创建数组的方法 数组的数学运算 数组的迭代 基本的数组操作 比较操作 数组元素选择和操作 向量和矩阵的数学运算 随机数 Numpy 是在 Python 中进行科学计算所依赖的核心库,它提供高性能的多维数组对象,已经大量便于计算的方法。 可以在 Installing packages 找到安装方法,而后在 Python 中采用如下方式引入它: import numpy as np Arrays NumPy 中的核心对象是多维数组 np.ndarray ,它有一个别名 np.array ,这个数组和 Python 中的 array.array 不同,Python 中的 array 只支持一维,而 np.array 支持多维,且提供了更多的方法。 np.array 中只能存放同种类型的数据,如下,使用 np.array 创建数组,第二个参数需指明数组中元素的类型,否则 np.array 会自动推测数据类型: >>> a = np.array([1, 4, 5, 8], float) >>> a array([ 1., 4., 5., 8.]) >>

167. Two Sum II - Input array is sorted

南楼画角 提交于 2020-03-12 05:42:55
167. Two Sum II - Input array is sorted Easy Given an array of integers that is already sorted in ascending order , find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Note: Your returned answers (both index1 and index2) are not zero-based. You may assume that each input would have exactly one solution and you may not use the same element twice. Example: Input: numbers = [2,7,11,15], target = 9 Output: [1,2] Explanation: The sum of 2 and 7 is

php asort同值顺序不稳定问题解决

徘徊边缘 提交于 2020-03-11 21:49:34
一个数组: $test = array(1 => 0, 99 => 0, 87 => 0, 45 => 0, 67 => 0, 11 => 1, 2 => 0); 使用 asort($test) 排序,结果是: {"67":0,"2":0,"1":0,"45":0,"87":0,"99":0,"11":1} 虽然值为 1 的键排在了最后,但是同样值为 0 的键,顺序跟之前不同了。 这里如何保证值为 0 的顺序不变? PHP的asort和sort,底层是用快排实现的。无法保证同等大小的元素的顺序。要保证值为0的顺序不变?只能自己实现一个数组排序。对于数组中相等的元素,它们在排序后的顺序是未定义的。 (也即相等元素之间的顺序是不稳定的) ps:php7返回顺序正常的 <?php function stable_uasort(&$array, $cmp_function) { if(count($array) < 2) { return; } $halfway = count($array) / 2; $array1 = array_slice($array, 0, $halfway, TRUE); $array2 = array_slice($array, $halfway, NULL, TRUE); stable_uasort($array1, $cmp_function);

Java:Arrays.fill方法

☆樱花仙子☆ 提交于 2020-03-11 13:15:56
Java中如果说你想给数组中所有的数字赋值当然可以使用for循环一个一个来,但是Arrays类已经提供了一个方法了,为什么还要写行for循环呢? Arrays.fill方法 Arrays . fill ( array , value ) ; Arrays . fill ( array , from_index , to_index , value ) ; 其实第一个方法很容易理解,就是将array数组的所有数值都赋值为value,就结束了。 而第二种方法也只是加了一个范围,即让array[from_index] ~ array[to_index - 1]的所有值赋值为value,这里务必记住这个范围不包含array[to_index]这个数。 还有一点差点忘了说了,这里得提前导入Arrays类,即在开头写如下代码 import java . utl . Arrays ; 代码 package base ; import java . util . Arrays ; public class Arrays_fill { public static void main ( String [ ] args ) { int a [ ] = new int [ 10 ] ; Arrays . fill ( a , 999 ) ; for ( int i = 0 ; i < 10 ; i ++

Numpy的使用

走远了吗. 提交于 2020-03-10 14:07:28
Numpy的使用: 一、创建ndarray数组 二、指定ndarray数组元素的类型 三、ndarray运算: 四、ndarray数组的基本索引和切片: 五、ndarray数组的布尔索引和花式索引 六、ndarray数组的转置和轴对换 七、ndarray通用函数 7.1一元ufunc: 7.2二元ufunc: 7.3NumPy的where函数使用: 八、ndarray常用的统计方法 九、ndarray数组的去重以及集合运算 十、numpy中的线性代数 十一、numpy中的随机数生成 十二、ndarray数组重塑 十三、ndarray数组的拆分与合并 十四、数组的元素重复操作 参考文档: 一个在Python中做科学计算的基础库,重在数值计算,也是大部分PYTHON科学计算库的基础库,多用于在大型、多维数组上执行数值运算 import numpy as np 一、创建ndarray数组 NumPy最重要的一个特点就是其 N维数组对象 (即ndarray),该对象是一个快速而灵活的 大数据集容器 。你可以 利用这种数组 对 整块数据 执行一些数学运算,其语法跟标量元素之间的运算一样。 创建ndarray数组函数: 创建代码: import numpy as np ; print ( '使用列表生成一维数组' ) data = [ 1 , 2 , 3 , 4 , 5 , 6 ] x =

详解es6新增数组方法简便了哪些操作

本秂侑毒 提交于 2020-03-10 13:28:33
在es6中,只需要一行代码就可以搞定! Array.from && newSet() let a = [1,2,2,3,3,4,5]; let b = Array.from(new Set(a)) console.log(b) // [1,2,3,4,5] 是不是及其简单!其中 new Set()会把重复的数据过滤到,得到一个类数组的对象,Array.from()可以把类数组的对象转换为真正的数组对象,有兴趣的同学可以对这两个属性进行更加深入的了解。 数组过滤 在我们拿到后端数据的时候,可能会对数据进行一些筛选、过滤,传统的做法如下 // 取出数组中name为kele的数组集合 let a = [ { name: 'kele', title: '可口可乐' }, { name: 'kele', title: '芬达' }, { name: 'wlg', title: '王老吉' } ] let b = []; for(let i = 0; i < a.length; i++){ if( a[i].name === 'kele' ){ b.push(a[i]) } } console.log(b) //[{name: 'kele', title: '可口可乐'},{name: 'kele', title: '芬达'}] es6中的处理方法如下 Array.filter