array

实现一个大小固定的有序数组,支持动态增删改操作

若如初见. 提交于 2019-12-14 19:56:00
package task1 ; /** * 功能:实现一个大小固定的有序数组,支持动态增删改操作 * Created by liumao 2019/8/4 **/ public class ControllerOrderArray { private int [ ] array ; private int n ; private int count ; public ControllerOrderArray ( int n ) { this . n = n ; count = 0 ; array = new int [ n ] ; } public static void main ( String [ ] args ) { ControllerOrderArray corderArr = new ControllerOrderArray ( 5 ) ; // 插入 corderArr . insert ( 3 ) ; corderArr . insert ( 45 ) ; corderArr . insert ( 5 ) ; corderArr . insert ( 23 ) ; corderArr . insert ( 9 ) ; System . out . println ( "插入后数组:" ) ; corderArr . print ( ) ; // 删除

分治FFT/NTT

那年仲夏 提交于 2019-12-14 15:35:09
考虑对当前左区间对右区间的贡献,由于右区间的F未更新,可以更改指标 \begin{array}{rcl} F_x&=&\sum\limits_{i=L}^{mid}F_iG_{x-i} \\ &=&\sum\limits_{i=L}^{x}F_iG_{x-i} \\ &=&\sum\limits_{i=0}^{x-L}F_{L+i}G_{x-L-i} \end{array} 设$A_i=F_{i+L},B_i=G_i$ \begin{array}{rcl} F_x=C_{x-L}=\sum\limits_{i=0}^{x-L}A_iB{x-L-i} \end{array} 模板: 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<cmath> 5 #define ll long long 6 #define reg register 7 #define F(i,a,b) for(register int (i)=(a);(i)<=(b);++(i)) 8 using namespace std; 9 int read(); 10 const int N=400005; 11 const ll mod=998244353ll; 12 int n,h,cs; 13 int rev[N]; 14

php安全字段和防止XSS跨站脚本攻击过滤函数

 ̄綄美尐妖づ 提交于 2019-12-14 12:42:05
function escape($string) { global $_POST; $search = array ( '/</i', '/>/i', '/\">/i', '/\bunion\b/i', '/load_file(\s*(\/\*.*\*\/)?\s*)+\(/i', '/into(\s*(\/\*.*\*\/)?\s*)+outfile/i', '/\bor\b/i', '/\<([\/]?)script([^\>]*?)\>/si', '/\<([\/]?)iframe([^\>]*?)\>/si', '/\<([\/]?)frame([^\>]*?)\>/si' ); $replace = array ( '<', '>', '">', 'union ', 'load_file (', 'into outfile', 'or ', '<\\1script\\2>', '<\\1iframe\\2>', '<\\1frame\\2>' ); if (is_array ( $string )) { $key = array_keys ( $string ); $size = sizeof ( $key ); for($i = 0; $i < $size; $i ++) { $string [$key [$i]] = escape ( $string [$key [

【剑指offer系列】系列一

Deadly 提交于 2019-12-14 02:25:34
系列一:1~10题 目录 系列一:1~10题 1、二维数组中的查找【数组】 题目描述 1.1、分析 1.2、代码 2、替换空格【字符串】 题目描述 2.1、分析 2.2、代码 3、从尾到头打印链表【链表】 题目描述 3.1、分析 3.2、代码 4、重建二叉树【树】 题目描述 4.1、分析 4.2、代码 5、用两个栈实现队列【队列】【栈】 题目描述 6.1、分析 6.2、代码 7、旋转数组的最小数字【查找】【二分】 题目描述 7.1 分析 7.2 代码 8、斐波那契数列【动态规划】 题目描述 8.1、分析 8.2、代码 9、跳台阶【动态规划】 题目描述 9.1、分析 9.2、代码 10、变态跳台阶【动态规划】【完全背包问题】 题目描述 10.1、分析 10.2、代码 1、二维数组中的查找【数组】 题目: 原题链接 题目描述 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 1.1、分析 对于这样的数组,我们可以发现,从右上角数字开始比较,若比目标数字小,那么一定不会在第一行,所有可以跳过第一行,若比目标数字大,那么肯定不在最后一列,则可以跳过最后一列。依次这样比较下去,直到相等为止。 1.2、代码 class Solution {

LeetCode_485. Max Consecutive Ones

十年热恋 提交于 2019-12-14 01:26:21
485. Max Consecutive Ones Easy Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3. Note: The input array will only contain 0 and 1 . The length of input array is a positive integer and will not exceed 10,000 package leetcode.easy; public class MaxConsecutiveOnes { public int findMaxConsecutiveOnes(int[] nums) { int max = 0; int curr_max = 0; for (int i = 0; i < nums.length; i++) { if (nums[i] == 1) { curr

JavaScript Array filter() 方法

徘徊边缘 提交于 2019-12-14 00:06:29
JavaScript Array filter() 方法 var ages = [32, 33, 16, 40]; function checkAdult(age) { return age >= 18; } function myFunction() { document.getElementById("demo").innerHTML = ages.filter(checkAdult); } 输出结果为: 32,33,40 来源: https://www.cnblogs.com/sexintercourse/p/12034697.html

How to Structure Associative Array to Inject into `dom-repeat`

寵の児 提交于 2019-12-13 17:40:00
问题 I have an array of arrays that I would like to use in a dom-repeat , but am getting an error saying the data isn't array-like. dom-repeat.html:465 dom-repeat expected array for items , found {0: Array(1), 1: Array(1), 2: Array(13)... The original data in order line items and is being converted into the array of arrays data to sort into cards. I think ideally the pattern would be something like: Card Parent <template is="dom-repeat" items="[[data]" index-as="index"> <card-item-group data="[

js数组

心已入冬 提交于 2019-12-13 16:19:21
JavaScript的Array可以包含任意数据类型,并通过索引来访问每个元素。 要取得Array的长度,直接访问length属性: var arr = [1, 2, 3.14, ‘Hello’, null, true]; arr.length; // 6 请注意,直接给Array的length赋一个新的值会导致Array大小的变化: var arr = [1, 2, 3]; arr.length; // 3 arr.length = 6; arr; // arr变为[1, 2, 3, undefined, undefined, undefined] arr.length = 2; arr; // arr变为[1, 2] Array可以通过索引把对应的元素修改为新的值,因此,对Array的索引进行赋值会直接修改这个Array: var arr = [‘A’, ‘B’, ‘C’]; arr[1] = 99; arr; // arr现在变为[‘A’, 99, ‘C’] 请注意,如果通过索引赋值时,索引超过了范围,同样会引起Array大小的变化: var arr = [1, 2, 3]; arr[5] = ‘x’; arr; // arr变为[1, 2, 3, undefined, undefined, ‘x’] 大多数其他编程语言不允许直接改变数组的大小,越界访问索引会报错。然而

剑指offer - 二维数组中的查找

孤街浪徒 提交于 2019-12-13 13:04:24
  这题我总觉得 oj 有问题。。。就算真的复杂度很高,也不可能通不过一个样例吧。。。   第一眼没注意到每一列都从上到下递增,写出来的算法平均时间复杂度为 O(lgn * lgm),最坏为O(nlgm),思路就是对第一列做二分查找得到一个行区间,然后遍历行区间,对每一行做二分查找,但提交后有段错误(本地 MSVC 编译、运行没问题)。。。   然后又认真看一遍题之后,经过思考各种边界情况,优化了很多小地方的查找步数,时间复杂度肯定比第一个小很多,所以有点不敢相信居然超时? class Solution { public: bool Find(int target, std::vector<std::vector<int>> array) { if (array.empty()) return false; if (array[0][0] > target) return false; if (array[array.size() - 1][array[0].size() - 1] < target) return false; int start_col = 0, end_col = array.size() - 1, mid_col = (start_col + end_col) / 2; while (array[start_col][0] < target &&

A Leapfrog in the Array (CodeForces - 949B )

。_饼干妹妹 提交于 2019-12-13 02:26:13
Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he has come up with the following extravagant algorithm. Let's consider that initially array contains n numbers from 1 to n and the number i is located in the cell with the index 2 i  - 1 (Indices are numbered starting from one) and other cells of the array are empty. Each step Dima selects a non-empty array cell with the maximum index and moves the number