array

【矩阵---求A的1到N次幂之和】

旧街凉风 提交于 2020-03-06 02:55:16
引例: Matrix Power Series : 题目大意,给定矩阵A,求A^ 1 +A^ 2 +A^ 3 +...A^N。 题解:已知X=a,可以通过以下矩阵求出ans=a^ 1 +a^ 2 +...a^ N ans =矩阵^n后第一行之和- 1 =矩阵^(n+ 1 )后右上格的和- 1 。 同理:矩阵也可以,只需要把1改为单位矩阵元即可。 左图a是常数,1就是1; 右图A是矩阵,1是单位元矩阵(主对角线是1)。 代码1:矩阵^N,第一行之和-1。 #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxn=70; int N,K,Mod; struct mat { int mp[maxn][maxn],len; mat(int x){ len=x; memset(mp,0,sizeof(mp)); } mat friend operator *(mat a,mat b) { mat res(a.len); for(int k=1;k<=res.len;k++) for(int i=1;i<=res.len;i++) for(int j=1;j<=res.len;j++) res.mp

算法题LC105:minimum-depth-of-binary-tree

非 Y 不嫁゛ 提交于 2020-03-05 19:55:42
贪心: 题目描述 : 给出一个非负整数数组,你最初在数组第一个元素的位置 数组中的元素代表你在这个位置可以跳跃的最大长度 你的目标是用最少的跳跃次数来到达数组的最后一个元素的位置 例如 给出数组 A =[2,3,1,1,4] 最少需要两次才能跳跃到数组最后一个元素的位置。(从数组下标为0的位置跳长度1到达下标1的位置,然后跳长度3到数组最后一个元素的位置) Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of jumps. For example: Given array A =[2,3,1,1,4] The minimum number of jumps to reach the last index is2. (Jump1step from index 0 to 1, then 3 steps to the last index.) 输入描述 :

05-数组高级操作

那年仲夏 提交于 2020-03-05 19:11:12
import numpy as np x=np.array([[1],[2],[3]]) y=np.array([4,5,6]) b=np.broadcast(x,y)#对y广播x #1. print(b.index) print(b.__next__())#循环到下一个(1, 4) print(b.__next__())#循环到下一个(1, 5) print(b.__next__())#循环到下一个(1, 6) print(b.__next__())#循环到下一个(2, 4) print(b.__next__())#循环到下一个(2, 5) print(b.__next__())#循环到下一个(2, 6) print(b.__next__())#循环到下一个(3, 4) print(b.__next__())#循环到下一个(3, 5) print(b.__next__())#循环到下一个(3, 6) print(b.index) c=np.empty(b.shape)#清空 print(b,"\n",c) #2. print(c.shape) c.flat=[u+v for (u,v) in b]#数组的加法 print(c) #3. d=np.arange(4).reshape(1,4) print("\n\n",d)#[[0 1 2 3]] print(np

旋转数组的最小数字

Deadly 提交于 2020-03-05 10:55:00
1、题目 2、解法 import java . util . ArrayList ; public class Solution { public int minNumberInRotateArray ( int [ ] array ) { if ( array . length == 0 ) return - 1 ; if ( array . length == 1 ) return array [ 0 ] ; int start = 0 , end = array . length - 1 ; int mid = 0 ; while ( start < end ) { // 针对的时10111, 这样特殊的情况 if ( array [ start ] < array [ end ] ) { return array [ start ] ; } mid = ( start + end ) / 2 ; if ( array [ start ] < array [ mid ] ) { start = mid + 1 ; } else if ( array [ mid ] < array [ end ] ) { // 避免错过最小值 end = mid ; } else { // 这里end不能动,后部分有可能出最小值 start ++ ; } } // 当start和end相等时

C++ std::array

可紊 提交于 2020-03-05 08:04:18
std::array template < class T, size_t N > class array; Code Example #include <iostream> #include <array> #include <cstring> using namespace std; int main(int argc, char **argv) { array<int, 5> intArr = {1,2,3,4,5}; for(auto it = intArr.begin(); it != intArr.end(); it++ ) { cout << *it << "\t"; } ///< output: 1 2 3 4 5 cout << "\n"; ///< r means reverse for(auto rit = intArr.rbegin(); rit < intArr.rend(); rit++) { cout << *rit << "\t"; } ///< output: 5 4 3 2 1 cout << "\n"; ///< c means const for(auto cit = intArr.cbegin(); cit != intArr.cend(); cit++ ) { cout << *cit << "\t"; } ///< output:1 2

angular5 ngx datatable error context

泄露秘密 提交于 2020-03-05 05:41:03
获取到api的数据,需要render 到datatable 上的时候出错, 取到的数据:是一个object {"pool":[ {"pool_id":"2","libraries_library_id":"2"}, {"pool_id":"1","libraries_library_id":"1"} ]} 刷新页面: PoolsDisplayComponent.html:5 ERROR TypeError: val.slice is not a function at DatatableComponent.set [as rows] (index.js:2803) at updateProp (core.js:12661) at checkAndUpdateDirectiveInline (core.js:12368) at checkAndUpdateNodeInline (core.js:13935) at checkAndUpdateNode (core.js:13878) at debugCheckAndUpdateNode (core.js:14771) at debugCheckDirectivesFn (core.js:14712) at Object.eval [as updateDirectives] (PoolsDisplayComponent.html:5)

吴裕雄--天生自然JAVA反射机制学习笔记:反射机制深入探究

梦想与她 提交于 2020-03-04 23:53:10
package org.lxh.demo15.invokedemo ; import java.lang.reflect.Array ; public class ChangeArrayDemo{ public static void main(String args[]) throws Exception{ int temp[] = {1,2,3} ;// 声明一整型数组 int newTemp[] = (int []) arrayInc(temp,5) ; // 重新开辟空间5 print(newTemp) ; System.out.println("\n-------------------------") ; String t[] = {"lxh","mldn","mldnjava"} ; String nt[] = (String [])arrayInc(t,8) ; print(nt) ; } public static Object arrayInc(Object obj,int len){ Class<?> c = obj.getClass() ; Class<?> arr = c.getComponentType() ; // 得到数组的 Object newO = Array.newInstance(arr,len) ; // 开辟新的大小 int co =

剑指offer 37.数字在排序数组中出现的次数

柔情痞子 提交于 2020-03-04 20:53:40
剑指offer 37.数字在排序数组中出现的次数 题目 统计一个数字在排序数组中出现的次数。 思路 虽然递归已经是O(n)了,但是还要缩小,所以二分查找,找到前后的位置就行了。查找设k-0.5和k+0.5,反正都没有,所以能找到应该在的位置,然后减法就行。 代码 public int search(int[] array, double k) { int l = 0; int r = array.length - 1; int m = (r - l) / 2 + l; while (l <= r) { if (array[m] < k) { l = m + 1; } else { r = m - 1; } m = (r - l) / 2 + l; } return l; } public int GetNumberOfK(int[] array, int k) { int start = search(array, k - 0.5); int end = search(array, k + 0.5); return end - start; } 来源: https://www.cnblogs.com/blogxjc/p/12411887.html

【Perl】模块 Tie::File

杀马特。学长 韩版系。学妹 提交于 2020-03-04 20:20:17
1 Tie::File 建立一个list和file的关系,对list的操作会反映到file上去。 use Tie::File; tie @array, 'Tie::File', filename or die ...; $array[13] = 'blah'; # line 13 of the file is now 'blah' print $array[42]; # display line 42 of the file $n_recs = @array; # how many records are in the file? $#array -= 2; # chop two records off the end for (@array) { s/PERL/Perl/g; # Replace PERL with Perl everywhere in the file } # These are just like regular push, pop, unshift, shift, and splice # Except that they modify the file in the way you would expect push @array, new recs...; my $r1 = pop @array; unshift @array, new recs...;

Visual Studio 2017调试时内存数据可视化插件

风流意气都作罢 提交于 2020-03-04 20:09:08
Visual Studio 2017调试时内存数据可视化插件 软件调试时经常需要查看内存中数组的值,特别是用图形的方式展示数组的内容,非常有利于软件的调试。 (1)ArrayPlotter 折线方式显示序列数据 https://marketplace.visualstudio.com/items?itemName=RodneyThomson.ArrayPlotter ArrayPlotter is a debugger visualisation tool that allows you to dynamically plot the contents of your C++/C# arrays and IEnumerables within the Visual Studio debugger. Features Plot C++ or C# array or IEnumerable contents into a zoomable/pannable chart. Supported datatypes: float double unsigned/signed 8/16/32/64 bit integers Handles complex number of above datatypes (can plot real / imaginary / magnitude /