二维

二维数组和二维指针作为函数的参数

江枫思渺然 提交于 2020-01-07 18:09:37
不管是在工作上,还是最近在LeetCode上刷题。都错误的认为 二维数组 和 二维指针作为函数的参数时是等价的。这种认知是错误的。究其原因,还是对数组和指针理解的不深入。今天把我的理解做一个总结: 假如一个函数的形参是一个二维指针,但是你实参传入的是一个二维数组。那么你就会编译报错。 为什么我会错误的认为二维数组作为函数参数的时候等价于二维指针呢? 我思考了我为什么会这么想的原因了:一维数组作为函数参数的时候,编译器会把数组名当作指向该数组第一个元素的指针。所以我想当然的以为:既然一维数组和一维指针在函数参数中等价,那二维数组应该就等价于二维指针啊。 但是很遗憾,二维数组作为函数参数并等价于二维指针。因为 数组作为函数参数时转换为指针没有传递性 。也就是说你不能认为一维数组和一维指针作为函数参数等价,就认为二维数组和二维指针就等价了。在C语言中没有这样的传递性。 其实仔细想想,也是很容易明白的。二维数组其实就是一个数组的数组(即它是一个一维数组,只不过它的每个元素又都是一个一维数组)。当二维数组作为函数入参时,比如 int a[3][4]; 它的第一维数组会被转换成指针,相当于是传入了一个指向数组的指针。即作为函数参数, int a[3][4]和 int (*p)[4]等价。那 int (*p)[4]和 int **pp等价吗?肯定不等价呀, p指针指向类型是 int [4]

概率论与数理统计教学内容

≡放荡痞女 提交于 2020-01-05 22:09:13
概率论部分 Chapter 1: 随机事件及其概率 1 随机试验;样本点;样本空间 2 随机事件, 必然事件, 不可能事件, 互不相容事件, 对立事件;随机事件的关系及运算 3 概率的定义 4 概率的性质:有限可加性,减法公式,加法公式,及推论 5 条件概率及乘法公式 6 两个事件相互独立的定义及性质;多个事件相互独立的定义及性质 7 伯努利概率模型 8 全概率公式 9 贝叶斯公式 Chapter 2: 随机变量及其分布 1 随机变量;离散型随机变量;连续型随机变量 2 分布函数及性质 3 离散型随机变量的分布率及性质;连续性随机变量的概率密度函数及性质 4 常见的离散型随机变量的分布:0-1 分布;二项分布;泊松分布 5 常见的连续型随机变量的分布: 均匀分布;指数分布;正态分布 6 随机变量的函数的分布: 离散型随机变量函数的分布;连续型随机变量函数的分布(分布函数法和公式法) Chapter 3: 数字特征 1 数学期望;离散型随机变量的期望;连续型随机变量的期望;随机变量的函数的期望 2 数学期望的性质 3 方差;标准差 4 方差的性质 5 变异系数(注:不是很重要) 6 常见随机变量的期望和方差: 两点分布的期望和方差;泊松分布的期望和方差;均匀分布的期望和方差;指数分布的期望和方差;正态分布的期望和方差 Chapter 4 : 随机向量(或称多维随机变量)及其分布 1

二维vector基本使用

微笑、不失礼 提交于 2020-01-05 05:41:39
变量声明 vector<vector<int> > 变量名; 添加行 vector<vector<int> > v2d; for(int i=0;i<n;i++) {   v2d.push_back(vector<int>());//往v2d里添加行 } v2d.pop_back();//删除一行,由后向前。 遍历二维vector中的元素 int m=v2d.size();//行数不定所以要求出v2d的长度。 for(int i=0;i<m;i++) {   for(int j=0;j<n;j++)   {     v2d[i][j]=0;   } }//依次访问v2d内的元素 代码 #include<bits/stdc++.h> using namespace std; vector<vector<int> > v2d; int main() { for(int i=0;i<5;i++) { v2d.push_back(vector<int>());//不断往v2d里加行 } for(int i=0;i<v2d.size();i++)//行 { for(int j=0;j<5;j++)//添加5列 { v2d[i].push_back(i*j); } } v2d.pop_back(); for(int i=0;i<v2d.size();i++) { for(int j=0;j<5

POJ 2155 Matrix【二维线段树】

£可爱£侵袭症+ 提交于 2020-01-05 03:24:36
题目大意:给你一个全是0的N*N矩阵,每次有两种操作:1将矩阵中一个子矩阵置反,2.查询某个点是0还是1 思路:裸的二维线段树 #include<iostream> #include<cstdio> #include <math.h> #include<algorithm> #include<string.h> #include<queue> #define MOD 1000003 #define maxn 4009 #define LL long long using namespace std; int n,num; bool tree[maxn][maxn]; void add_y(int xx,int node,int l,int r,int ql,int qr) { if(ql<=l && r<=qr){tree[xx][node]^=1;return ;} int mid=(l+r)>>1; if(ql<mid)add_y(xx,node*2,l,mid,ql,qr); if(qr>mid)add_y(xx,node*2+1,mid,r,ql,qr); } void add_x(int node,int l,int r,int ql,int qr,int y1,int y2) { if(ql<=l && r<=qr){add_y(node,1,1,n+1,y1,y2)

UVA 11297 Census(二维线段树)

别等时光非礼了梦想. 提交于 2020-01-05 03:24:13
Description This year, there have been many problems with population calculations, since in some cities, there are many emigrants, or the population growth is very high. Every year the ACM (for Association for Counting Members) conducts a census in each region. The country is divided into N^2 regions, consisting of an N x N grid of regions. Your task is to find the least, and the greatest population in some set of regions. Since in a single year there is no significant change in the populations, the ACM modifies the population counts by some number of inhabitants. The Input In the first line

POJ2029 二维线段树

青春壹個敷衍的年華 提交于 2020-01-05 03:23:49
Get Many Persimmon Trees POJ - 2029 Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate was strictly specified by the lord, he was allowed to choose any location for the estate in the field. Inside the field which had also a rectangular shape, many Japanese persimmon

(匹配 二维建图) Antenna Placement --POJ --3020

我与影子孤独终老i 提交于 2020-01-05 03:14:44
链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82834#problem/H 首先分别对顶点进行编号:空地用0表示. 1002 3400 0056 7890 接下来划分顶点集合 集合u: 1 2 4 5 8 集合v: 3 6 7 9 问题就是求这两个集合之间的最小路径覆盖. 最小路径覆盖 = 顶点个数 - 最大匹配数 建图时为了方便,如果顶点u和顶点v相邻,就认为g[u][v] = 1和g[v][u] = 1.也就是说两个顶点集都是由全部顶点组成的,这样求出来的最大匹配数将翻倍,所以最后计算的时候要除以2 . 代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 510 #define INF 0x3f3f3f3f // un是匹配左边的定点数, vn是匹配右边的定点数 int n, m, un, vn, used[N], p[N], hash[N][N], g[N][N]; char G[N][N]; //匈牙利算法, 从左边开始找增广路 int Find(int u) { for

LeetCode:1260.二维网格迁移

ぃ、小莉子 提交于 2020-01-04 01:04:49
题目: 给你一个 n 行 m 列的二维网格 grid 和一个整数 k。你需要将 grid 迁移 k 次。 每次「迁移」操作将会引发下述活动: 位于 grid [ i ] [ j ] 的元素将会移动到 grid [ i ] [ j + 1 ] 。 位于 grid [ i ] [ m - 1 ] 的元素将会移动到 grid [ i + 1 ] [ 0 ] 。 位于 grid [ n - 1 ] [ m - 1 ] 的元素将会移动到 grid [ 0 ] [ 0 ] 。 请你返回 k 次迁移操作后最终得到的 二维网格。 示例 2 : 输入:grid = [ [ 3 , 8 , 1 , 9 ] , [ 19 , 7 , 2 , 5 ] , [ 4 , 6 , 11 , 10 ] , [ 12 , 0 , 21 , 13 ] ] , k = 4 输出: [ [ 12 , 0 , 21 , 13 ] , [ 3 , 8 , 1 , 9 ] , [ 19 , 7 , 2 , 5 ] , [ 4 , 6 , 11 , 10 ] ] 示例 3 : 输入:grid = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] , k = 9 输出: [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] 源码:

php 数组去重 (一维数组与二维数组)

徘徊边缘 提交于 2020-01-03 02:20:14
数组中重复项的去除 一维数组的重复项 : 使用array_unique函数即可,使用实例如下: <?php $aa=array("apple","banana","pear","apple","wail","watermalon"); $bb=array_unique($aa); print_r($bb); ?> 结果如下:Array ( [0] => apple [1] => banana [2] => pear [4] => wail [5] => watermalon ) 。 二维数组的重复项 : 对于二维数组咱们分两种情况讨论,一种是因为某一键名的值不能重复,删除重复项;另一种因为内部的一维数组不能完全相同,而删除重复项,下面举例说明: ㈠因为某一键名的值不能重复,删除重复项 <?php function assoc_unique($arr, $key) { $tmp_arr = array(); foreach($arr as $k => $v) { if(in_array($v[$key], $tmp_arr))//搜索$v[$key]是否在$tmp_arr数组中存在,若存在返回true { unset($arr[$k]); } else { $tmp_arr[] = $v[$key]; } } sort($arr); //sort函数对数组进行排序 return

python更新二维字典的值

依然范特西╮ 提交于 2020-01-02 02:46:59
已知二维字典: datas = {'pay_method_info': '{"card_no":"123456789","expiration_month":"06","expiration_year":"28","cvv":"123","first_name":"sdss","last_name":"kite"}'} (1)需要更新card_no的值为:123456 card_no_refresh = {"card_no": "123456"} (2)取出pay_method_info的值,并且由str转为dict,方便对card_no键值对进行操作 import json pay_method_info_value = json.loads(datas['pay_method_info']) 此时的结果pay_method_info_value 为: {"card_no":"123456789","expiration_month":"06","expiration_year":"28","cvv":"123","first_name":"sdss","last_name":"kite"} (3)更新card_no的值 pay_method_info_value.update(card_no_refresh) 此时的结果pay_method_info_value 为: {