2.15最大效益,螺旋方阵,方块转化

1.题目:

明明的爸爸开了一家小公司,公司里有5名职员。今天,公司接待了5位客户。明明的爸爸知道,和任何一位客户谈判并签下合同都要花一整天的时间,而他又希望在一天之内,和这5位客户都签好合同。因此,明明的爸爸要求公司里的5名职员分别与1位客户谈判。

明明的爸爸也知道,这5名职员和5位客户的性格各不相同。因此,不同的职员与不同的客户谈判,会给公司带来不同的经济效益。他现在要做出一个决策,让5名职员分别与哪位客户谈判,才能让公司今天的总经济效益最大。

明明的爸爸首先做了一张5行5列的效益表,如下所示:

1 1 1 1 1

1 1 1 1 1

1 1 1 1 1

1 1 1 1 1

1 1 1 1 1

在这张效益表中,每行代表一名公司职员,每列代表一个客户,每行中的5个数字就表示了当该行所代表的公司职员和每位客户谈判时所能产生的效益。明明的爸爸就要通过这张效益表来决定哪位职员与哪位顾客谈判,然后能够使公司的效益最大。就拿上面这张表来看,由于无论哪位职员与哪位客户谈判,所产生的效益都是1,因此最大的效益就是5。这是最简单的一种情况,但是当效益表里的数字变得复杂,就很难进行选择,到底哪种组合方式才是最优的。因此明明的爸爸求助于你,帮助他解决这个问题。

明明的爸爸的问题可以归结为:给你一张5行5列的效益表,表中的数字均为大于等于0的整数,要求在这张表中选出5个数字,使这5个数字的和最大。(注:这5个数字分别来自表中的不同行不同列,即同一行只能选择一个数字,同一列也只能选择一个数字。)

输入:

98 97 96 95 94

1 2 3 4 5

11 22 33 44 55

66 77 88 99 1

13 32 64 7 86

输出:

318
个人心得:

1.先将数字输入到一个二维数组当中,再建立一个数组b里面存放数字的顺序

2.利用循环输出数组当中的组合,再利用函数next_permutation随机组合b中的数字

3.最后输出最大值

复制代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int a[5][5] = { 0 };
	while (true) {
		if (scanf("%d", &a[0][0]) != 1)
			break;
		for (int i = 0; i < 5; ++i) {
			for (int j = 0; j < 5; ++j) {
				if (i == 0 && j == 0) continue;
				scanf("%d", &a[i][j]);
			}
		}
		int maxnumber = 0;
		int b[5] = { 0,1,2,3,4 };
		while (1) {
			int sum = 0;
			for (int i = 0; i < 5; ++i) {
				sum = sum + a[i][b[i]];
			}
			maxnumber = max(maxnumber, sum);

			if (!next_permutation(b, b + 5)) {
				break;
			}
		}
		printf("%d\n", maxnumber);
	}
}

2.题目:

明明在上学的时候,参加数学兴趣班。在班上,老师介绍了一种非常有趣的方阵,称之为螺旋方阵。该方阵一共由n×n个正整数构成(我们称之为n阶螺旋方阵),即共有n行n列。

方阵中的数字从1开始递增,数字的排序规则是从左上角出发由1开始排序,并按顺时针方向旋进,即先排最外面的一圈,然后排里面的一圈,以此类推,直到排到最后一个数为止。

例如一个4阶的螺旋方阵,一共有4×4=16个正整数构成,数字从1递增到16,最后排出来的方阵如下:

1 2 3 4

12 13 14 5

11 16 15 6

10 9 8 7

明明回家后想自己动手构造这样的螺旋方阵。他从n=1开始构造,但是他发现当n越来越大时,螺旋方阵的复杂性就越高,然后构造出来的方阵就越容易出错。为了降低构造方阵的出错率,提高构造速度,明明就求助于你,请你帮他写一个程序,来构造螺旋方阵。 明明的问题可以归结为:给你一个正整数n,请你按题目描述中所述的方法,构造出n阶的螺旋方阵。

输入:

9

4

输出:

1 2 3 4 5 6 7 8 9

32 33 34 35 36 37 38 39 10

31 56 57 58 59 60 61 40 11

30 55 72 73 74 75 62 41 12

29 54 71 80 81 76 63 42 13

28 53 70 79 78 77 64 43 14

27 52 69 68 67 66 65 44 15

26 51 50 49 48 47 46 45 16

25 24 23 22 21 20 19 18 17

1 2 3 4

12 13 14 5

11 16 15 6

10 9 8 7

个人心得:

1.先级建立一个大小为10*10的数组,初始化为0,输入n,得到要输出的数组的上边,下边,左边,右边界

2.利用循环while (left <= right && above <= behind) 循环输出,先向右边走,当到达边界时就让上边界加1,再向下走,到达下边界时,让有边界减1,在向左边走,到达边界同理下边界减1,再向上走,到上边界,左边界加1,如此循环直到循环终止

复制代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int n;
	int flag = 1;
	while (scanf("%d", &n) != EOF) {
		if (flag != 1) {
			printf("\n");
		}
		flag = 0;
		int a[10][10] = { 0 };
		int left = 0;
		int right = n - 1;
		int above = 0;
		int behind = n - 1;
		int m = 1;
		while (left <= right && above <= behind) {
			for (int j = left; j <= right; j++) {
				a[above][j] = m++;
			}
			above++;
			for (int j = above; j <= behind; j++) {
				a[j][right] = m++;
			}
			right--;
			for (int j = right; j >= left; j--) {
				a[behind][j] = m++;
			}
			behind--;
			for (int j = behind; j >= above; j--) {
				a[j][left] = m++;
			}
			left++;
		}
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (j != 0) {
					printf(" ");
				}
				printf("%d", a[i][j]);
			}
			printf("\n");
		}
	}
}

3.题目:

一块N x N(1=<N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案。

写一个程序来找出将原始图案按照以下列转换方法转换成新图案的最小方式:

#1:转90度:图案按顺时针转90度。

#2:转180度:图案按顺时针转180度。

#3:转270度:图案按顺时针转270度。

#4:反射:图案在水平方向翻转(形成原图案的镜像)。

#5:组合:图案在水平方向翻转,然后按照#1-#3之一转换。

#6:不改变:原图案不改变。

#7:无效转换:无法用以上方法得到新图案。

如果有多种可用的转换方法,请选择序号最小的那个。

比如:

转换前:

@-@


@@-

转换后:

@-@

@--

--@

这种转换采取#1(按顺时针转90度)即可。

注意:图案中的字符"@"和"-"在转90度后,还是"@"和"-"。不要认为"-"转90度后变成"|"。

个人心得:

1先建立判断函数,判断0度,90度,180度,270度,镜像函数

2.再在主函数中从上到下判断,是否满足其中的一个,满足就输出对应的数字

复制代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
bool func0(int n, char a[][10], char b[][10]) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (b[i][j] != a[i][j]) {
				return false;
			}
		}
	}
	return true;

}
bool func90(int n,char a[][10],char b[][10]) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (b[i][j] != a[n - 1 - j][i]) {
				return false;
			}
		}
	}
	return true;
}
bool func180(int n,char a[][10],char b[][10]) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (b[i][j] != a[n-1-i][n-1-j]) {
				return false;
			}
		}
	}
	return true;
}
bool func270(int n, char a[][10], char b[][10]) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (b[i][j] != a[j][n-1-i]) {
				return false;
			}
		}
	}
	return true;
}
bool reverse(int n, char a[][10], char b[][10]) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (b[i][j] != a[i][n - 1 - j]) {
				return false;
			}
		}
	}
	return true;
}
int main() {
	int n;
	scanf("%d", &n);
	char a[10][10];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			scanf(" %c", &a[i][j]);
		}
	}
	char b[10][10];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			scanf(" %c", &b[i][j]);
		}
	}
	if (func90(n,a,b)) {
		printf("1\n");
		return 0;
	}
	if (func180(n,a,b)) {
		printf("2\n");
		return 0;
	}
	if (func270(n,a,b)) {
		printf("3\n");
		return 0;
	}
	if (reverse(n, a, b)) {
		printf("4\n");
		return 0;
	}
	char c[10][10];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			c[i][j] = a[i][n - 1 - j];
		}
	}
	if (func90(n, c, b) || func180(n, c, b) || func270(n, c, b)) {
		printf("5\n");
		return 0;
	}
	

	if (func0(n, a, b)) {
		printf("6\n");
		return 0;
	}
	printf("7\n");
}

第一段:

Software engineering is an area of software development in which computer scientists and engineers study methods and tools that facilitate the efficient development of correct, reliable, and robust computer programs. Research in this branch of computer science considers all the phases of the software life cycle, which begins with a formal problem specification, and progresses to the design of a solution, its implementation as a program, testing of the program, and program maintenance. Software engineers develop software tools and collections of tools called programming environments to improve the development process. For example, tools can help to manage the many components of a large program that is being written by a team of programmers.

翻译:

软件工程是软件开发的一个领域,在这个领域中,计算机科学家和工程师研究各种方法和工具,以促进正确、可靠且健壮的计算机程序的高效开发。该分支的研究涵盖软件生命周期的所有阶段,这一生命周期从正式的问题规格说明开始,依次经历解决方案的设计、作为程序的实现、程序测试以及程序维护。软件工程师会开发各种软件工具以及由多种工具组成的编程环境来改进开发过程。例如,这些工具可以帮助管理由一组程序员共同编写的大型程序中的众多组成部分。

第二段:

2.Computer Architecture

Computer architecture is the design and analysis of new computer systems. Computer architects study ways of improving computers by increasing their speed, storage capacity, and reliability, and by reducing their cost and power consumption. Computer architects develop both software and hardware models to analyze the performance of existing and proposed computer designs, and then use this analysis to guide the development of new computers. They are often involved with the engineering of a new computer because the accuracy of their models depends on the design of the computer's circuitry. Many computer architects are interested in developing computers that are specialized for particular applications such as image processing, signal processing, or the control of mechanical systems. The optimization of computer architecture to specific tasks often yields higher performance, lower cost, or both.

翻译:

  1. 计算机体系结构

计算机体系结构是对新型计算机系统的设计与分析。计算机体系结构师通过提高计算机的速度、存储容量和可靠性,以及降低其成本和功耗,来研究改进计算机的方法。他们开发软件模型和硬件模型来分析现有及拟议中的计算机设计的性能,并利用这些分析来指导新计算机的开发。由于模型的准确性取决于计算机电路的设计,计算机体系结构师通常会参与新计算机的工程设计。许多体系结构师还致力于为特定应用开发专用计算机,例如图像处理、信号处理或机械系统控制。针对特定任务对计算机体系结构进行优化,往往可以带来更高的性能、更低的成本,或两者兼具。

第三段:

3.Artificial Intelligence

Artificial intelligence (AI) research seeks to enable computers and machines to mimic human intelligence and sensory processing ability, and models human behavior with computers to improve our understanding of intelligence. The many branches of AI research include machine learning, inference, cognition, knowledge representation, problem solving, casebased reasoning, natural language understanding, speech recognition, computer vision, and artificial neural. networks.

翻译:

  1. 人工智能

人工智能(AI)研究旨在使计算机和机器能够模拟人类的智能和感知处理能力,并通过用计算机对人类行为进行建模来加深我们对智能本身的理解。人工智能研究包含许多分支领域,包括机器学习、推理、认知、知识表示、问题求解、基于案例的推理、自然语言理解、语音识别、计算机视觉以及人工神经网络。

相关推荐
im_AMBER2 小时前
Leetcode 122 二叉树的最近公共祖先 | 二叉搜索树迭代器
学习·算法·leetcode·二叉树
小亮✿2 小时前
二叉树OJ做题报告
数据结构·算法·做题报告
菜鸡儿齐2 小时前
leetcode-最小覆盖子串
算法·leetcode·职场和发展
流云鹤3 小时前
2026牛客寒假算法基础集训营4(A B C I H F G)
算法
每天要多喝水3 小时前
动态规划Day31:子序列长度1
算法·动态规划
lxl13073 小时前
C++算法(3)二分算法
数据结构·c++·算法
随意起个昵称3 小时前
Dijstra算法学习笔记
笔记·学习·算法
lifallen3 小时前
笛卡尔树 (Cartesian Tree)
java·数据结构·算法
ab1515173 小时前
2.15完成105、106、110
数据结构·算法