计算机复试学习笔记 Day24【补】

70. 矩阵问题

题目

问题描述

从键盘上输入一个整数N,按以下规律输出一个(2N+1)*(2N+1)的矩阵:

对角线的值为1,

上半三角区域值为2,

下半三角区域值为3,

左半三角区域的值为4,

右半三角区域的值为5。

输入说明

你的程序需要从标准输入设备(通常为键盘)中读入多组测试数据。每组测试数据数据占一行,大于零,小于等于8。

输出说明

对每组测试数据,你的程序需要向标准输出文件(通常为启动该程序的终端)依次输出符合要求的矩阵,每行数据与数据之间以空格分隔,在行首和行尾不要输出多余的空格。在所有数据前后,以及两组数据之间不要输出多余的空行。

个人总结

思路

将 (2N+1)×(2N+1) 矩阵分为三部分处理:上半部分 N 行、中间 1 行、下半部分 N 行。每行按照从左到右的顺序依次输出:左侧的 4、左对角线 1、中间区域(上半用 2,下半用 3)、右对角线 1、右侧的 5。通过计算每个区域的元素个数来控制输出。

易错点
  1. 矩阵分三段:上半 N 行(中间填 2)、中间 1 行(只有 4、1、5)、下半 N 行(中间填 3)
  2. 第 i 行(从 0 开始)的结构:i 个 4 + 1 个 1 + (2N+1-2i-2) 个中间值 + 1 个 1 + i 个 5
  3. 下半段用倒序循环 i 从 N-1 到 0,保证结构对称
  4. 空格处理:每行第一个数字前不输出空格,其余数字前都输出空格
  5. 不要忘记中间的一行

代码

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int N;
	while (cin >> N) {
		// 输出上半段
		for (int i = 0; i < N; i++) {
			// 左边的 4
			for (int j = 0; j < i; j++) {
				if (j != 0) cout << " ";
				cout << "4";
			}
			// 对角线 1
			if (i != 0) cout << " ";
			cout << "1";
			// 中间的 2
			int cnt2 = 2 * N + 1 - 2 * i - 2;
			for (int j = 0; j < cnt2; j++) {
				cout << " 2";
			}
			// 对角线 1
			cout << " 1";
			// 右边的 5
			for (int j = 0; j < i; j++) {
				cout << " 5";
			}
			
			// 换行
			cout << "\n";
		}
		
		// 不要忘记中间一行
		for (int i = 0; i < N; i++) {
			if (i != 0) cout << " ";
			cout << "4";
		}
		cout << " 1";
		for (int i = 0; i < N; i++) {
			cout << " 5";
		}
		cout << "\n";

		// 输出下半段
		for (int i = N-1; i >= 0; i--) {
			// 左边的 4
			for (int j = 0; j < i; j++) {
				if (j != 0) cout << " ";
				cout << "4";
			}
			// 对角线 1
			if (i != 0) cout << " ";
			cout << "1";
			// 中间的 3
			int cnt3 = 2 * N + 1 - 2 * i - 2;
			for (int j = 0; j < cnt3; j++) {
				cout << " 3";
			}
			// 对角线 1
			cout << " 1";
			// 右边的 5
			for (int j = 0; j < i; j++) {
				cout << " 5";
			}
			
			// 换行
			cout << "\n";
		}


	}
	return 0;
}

71. 发牌

题目

问题描述

编制一个模拟发牌的程序。有编号为1,2,3,4四个人,将一付去掉大小怪的扑克按照如下顺序排列梅花c0-c12,方块d0-d12,红桃h0--h12,黑桃s0-s12,然后按照1,2,3,4四个人的顺序发牌,问最后每个人手上的牌有哪些。

输入说明

你的程序需要从标准输入设备(通常为键盘)中读入多组测试数据。每组输入数据由一行组成。每组数据包含一个在1到4之间的整数,代表四个人中的一个,在行首和行尾没有多余的空格。

输出说明

对每组测试数据,你的程序需要向标准输出设备(通常为启动该程序的终端)依次输出一组对应的答案。对于每组输入,输出那个人手上的牌。每组一行。每行包括13张牌,每张牌由牌的花色和牌的大小组成。牌的花色和牌的大小之间有一个空格,前后两张牌之间也有一个空格。其余数据前后没有多余的空格,两组数据之间也没有多余的空行。

个人总结

思路

采用直接模拟发牌的过程,利用二维数组预处理存储4名玩家各自的13张牌。 按序遍历4种花色与13种点数生成52张扑克牌。 维护当前玩家编号与当前手牌下标两个变量,每发一张牌循环更迭为下一名玩家,当最后一名玩家完成拿牌后,手牌下标变量自增一位。 由于发牌结果固定,在循环接收查询前完成一次发牌模拟预处理即可,后续只需根据输入的玩家编号直接输出对应数组的内容。

易错点
  1. 题目输入的玩家编号为1至4,而数组索引范围是0至3,代入数组查询时需要进行减一的偏移操作。
  2. 输出格式中空格的精细控制,不仅两张牌之间有空格,单张牌的花色与数值之间也需要空格隔开,且行末不能有多余空格。

代码

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

struct card{
	char c;
	int n;
};

char color[] = {'c', 'd', 'h', 's'};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	card p[4][13];
	
	// 发牌
	int pn = 0;
	int pos = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			// 发牌
			p[pn][pos].c = color[i];
			p[pn][pos].n = j;
			
			// 下一个人
			if (pn == 3) pos++;
			pn = (pn + 1) % 4;
		}
	}
	
	int N;
	while (cin >> N) {
		for (int i = 0; i < 13; i++) {
			if (i != 0) cout << " ";
			
			cout << p[N-1][i].c << " " << p[N-1][i].n;
		}
		cout << "\n";
	}
	
	return 0;
}

72. 数字金字塔

题目

问题描述

考虑在下面被显示的数字金字塔(第n行有n列)。写一个程序来计算从最高点开始在底部任意处结束的路径经过数字的和的最大。每前进一步可以走到它的正下方或者右下方(往下一行、往右一列)的位置。

7

3 8

8 1 0

2 7 4 4

4 5 2 6 5

在上面的样例中,从7 到 3 到 8 到 7 到 5 的路径产生了最大和:30

输入说明

第一个行包含 R(1<= R<=1000) ,表示行的数目。后面每行为这个数字金字塔特定行包含的整数。所有的被供应的整数是非负的且不大于100。

输出说明

输出仅一行,包含那个可能得到的最大的和。

个人总结

思路
  1. 采用自底向上的动态规划策略,避免了自顶向下搜索可能出现的路径状态记录复杂问题。
  2. 直接在原数组上进行状态转移,a[i][j]最终存储的是从该点出发到底部的最大路径和,空间利用率高。
  3. 外层循环从倒数第二行(R-2)开始向上遍历至第0行,内层循环遍历当前行的所有元素。
  4. 状态转移方程选取下一行相邻两个元素中的较大值累加到当前元素,保证每一步都是局部最优以达到全局最优。
  5. 最终输出a[0][0]即为从塔顶到底部的最大和。
易错点
  1. 数组尺寸需要能够容纳最大行数R=1000,声明为全局变量或足够大的静态数组以防止栈溢出。
  2. 倒序遍历的起始行是R-2,因为最后一行本身就是到底部的路径和,不需要计算。
  3. 状态转移时取的是a[i+1][j]和a[i+1][j+1]的最大值,注意下标偏移不要出错。
  4. 不管是在输入还是计算,注意金字塔的双重循环结束条件,外层循环不加等于号,而内层循环需要等于号

代码

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int a[1005][1005];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	// 输入金字塔
	int R;
	cin >> R;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j <= i; j++) {
			cin >> a[i][j];
		}
	}
	
	// 逐层向上
	for (int i = R - 2; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			a[i][j] += max(a[i+1][j], a[i+1][j+1]);
		}
	}
	
	cout << a[0][0];
	
	return 0;
}

计算机英语翻译练习

Figure 12C-2: The architecture of an loT consisting of sensing devices that are connected to various applications via mobile networks, the Internet, and processing clouds

The signal processing clouds are built over the mobile networks, the Internet backbone , and various information networks at the middle layer. In the loT, the meaning of a sensing event does not follow a deterministic or syntactic model. In fact, the service- oriented architecture (SOA) model is adoptable here. A large number of sensors and filters are used to collect the raw data. Various compute and storage clouds and grids are used to process the data and transform it into information and knowledge formats. The sensed information is used to put together a decision-making system for intelligence applications. The middle layer is also considered as a Semantic Web or Grid . Some actors (services, components, avatars ) are self-referenced.

图12C-2: 物联网架构包括通过移动网络、互联网和处理云连接至不同应用的传感器

信号处理云建立在移动网络、互联网骨干网和中间层的各种信息网络之上。在物联网中,感知事件的含义并不遵循于一个决定论或语义学的模型。事实上,这里可采用面向服务的架构模型。

它采用了大量传感器和过滤器来收集原始信息,还使用了各种计算和储存云及网络来处理数据,并将它转变为信息与知识形式。

感知到的信息被集成为用于智能应用的决策系统。中间层也被视为语义网或网格。一些主体(服务、组件、化身)是自引用的。

IV. Applications of the Internet of Things

Table 12C-2 summarizes loT applications in three major civilian application domains . Obviously, the loT has a lot of military applications, which is beyond the scope of this section. In general, use of the loT aims to promote industrial productivity and raise economic growth. The loT plays important roles in environment protection, including pollution control, weather forecasting, and disaster avoidance and recovery. In terms of societal impacts, the loT can make our lives more convenient and comfortable. Government services, law enforcement, and home and health improvements are the major beneficiaries. In the remaining space of this section, we will briefly discuss some of the application domains.

IV. 物联网的应用

表格 12C-2 总结了在三大主要民用领域的物联网应用。显然,物联网在军事领域也有广泛应用,但这超出了本节的讨论范围。

总体上,物联网的应用旨在提高工业生产率并促进经济增长。物联网在环境保护中也起着重要作用,包括污染控制、天气预测、灾害预防与恢复。

在社会影响方面,物联网可以使我们的生活更加便捷舒适。政府服务、法律执行,还有家居和健康改善是主要的受益领域。

在本节接下来的内容中,我们将简要讨论其中的一些应用领域。

I.Retailing andLogistics Services

Emergence of RFID applications depends strongly on adoption by retailers , logistics organizations, and package-delivery companies. In particular, retailers may tag individual objects in order to solve a number of problems at once: accurate inventorying, loss control, and ability to supportunattended walk-through point of sale terminals (which promise to speed checkout while reducing both shoplifting and labor costs). Cold-chain auditing and assurance could require tagging food and medicine with temperature-sensitive materials and/or electronics; ensuring or monitoring whetherperishable materials areintact and/or need attention may entail communications among things,refrigeration systems , automated data logging systems, and human technicians.

一、零售及物流服务

RFID 应用的兴起很大程度上取决于零售商、物流机构和包裹递送公司的采纳。

特别是,零售商可能会对单个商品进行贴标,以期同时解决多项问题:准确的库存盘点、损耗控制,以及支持无人值守的走入式销售点终端,这有望在加快结账速度的同时,降低失窃风险和人工成本。

冷链审计与保障可能需要使用温敏材料和/或电子设备为食品和药品贴标;确保或监测易腐物资是否完好及是否需要处理,可能涉及物体、制冷系统、自动数据记录系统以及技术人员之间的通信。

背单词打卡

相关推荐
xhyu611 小时前
【学习笔记】推荐系统 (2.召回:ItemCF、Swing、UserCF)
笔记·学习
weixin_448119941 小时前
Datawhale Easy-Vibe 202602 第4次笔记
笔记·深度学习
日更嵌入式的打工仔2 小时前
LDR/STR
笔记
EmmaXLZHONG2 小时前
分布式系统概念与设计笔记(Notes of Distributed Systems Concepts and Design)
笔记·分布式·网络协议·计算机网络
DoogalStudio2 小时前
DevMind插件设计方案产品需求文档
人工智能·笔记
学历真的很重要2 小时前
【系统架构师】第三章 数据库系统知识 - 数据库基础到关系代数(详细版)
数据库·学习·职场和发展·系统架构·系统架构师
白云偷星子2 小时前
RHCSA笔记6
linux·笔记
weixin_448119942 小时前
Datawhale Easy-Vibe 202602 第5次笔记
笔记
三水彡彡彡彡3 小时前
深入理解指针:常量、函数与数组
c++·学习