【作业】难倒小学生的问题?

【作业】难倒小学生的问题?,第1张

【作业】难倒小学生的问题? 题目

妹的,完全是标题党

所谓难题

观察以下计算,发现有什么规律?
1 + 1 = 0
1 + 6 = 1
6 + 6 = 2
8 + 1 = 2
8 + 6 = 3
其实,就是数字的圈数计算,1 有零圈,6有一个, 8有两

其实是考图形?

那么按0,1填充m,n 的表格,1表示填充,组成图案1,6或8,并识别出他的数字

结果

row: 7, col:7
0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 0 1 0 1 0 0
0 0 1 1 1 0 0
0 0 1 0 1 0 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0
RES: 8
row: 7, col:7
0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 0 1 0 0 0 0
0 0 1 1 1 0 0
0 0 1 0 1 0 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0
RES: 6
row: 7, col:7
0 0 0 0 0 0 0
0 0 1 0 0 0 0
0 0 1 0 0 0 0
0 0 1 1 0 0 0
0 0 1 0 0 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 0
RES: 1

代码
#include 
#include 

const static std::map HOLE_COUNT_2_NUMS = {
	std::make_pair(0, 1),
	std::make_pair(1, 6),
	std::make_pair(2, 8)
};

int _cal_num_type(const bool* content, int row, int col) {

	int hole_count = 0;
	for (int i = 0; i < row; ++i) {
		int left_index = -1;
		int start_index = i * col;
		for (int j = 0; j < col; ++j) {
			const int cur_index = start_index + j;
			if (left_index == -1) {
				if (content[cur_index]) {
					left_index = cur_index;
				}
			}
			else {
				if (content[cur_index]) {
					if (cur_index - left_index > 1) {
						++hole_count;
					}
					left_index = cur_index;
				}
			}
		}
	}

	const auto res = HOLE_COUNT_2_NUMS.find(hole_count);
	if (res != HOLE_COUNT_2_NUMS.end()) {
		return res->second;
	}
	return -1;
}

void output_res(const bool* content, const int row, const int col, const int res) {
	std::cout << "row: " << row << ", col:" << col<< std::endl;
	for (int i = 0; i < row; ++i) {
		for (int j = 0; j < col; ++j) {
			std::cout << " " << content[i * col + j];
		}
		std::cout << std::endl;
	}
	std::cout << "RES: " << res<< std::endl;
}

void cal_num_type() {
	{
		const int n = 7, m = 7;
		const bool content[] = {
			0, 0, 0, 0, 0, 0, 0,
			0, 0, 1, 1, 1, 0, 0,
			0, 0, 1, 0, 1, 0, 0,
			0, 0, 1, 1, 1, 0, 0,
			0, 0, 1, 0, 1, 0, 0,
			0, 0, 1, 1, 1, 0, 0,
			0, 0, 0, 0, 0, 0, 0,
		};
		const int res = _cal_num_type(content, n, m);
		output_res(content, m, n, res);
	}
	{
		const int n = 7, m = 7;
		const bool content[] = {
			0, 0, 0, 0, 0, 0, 0,
			0, 0, 1, 1, 1, 0, 0,
			0, 0, 1, 0, 0, 0, 0,
			0, 0, 1, 1, 1, 0, 0,
			0, 0, 1, 0, 1, 0, 0,
			0, 0, 1, 1, 1, 0, 0,
			0, 0, 0, 0, 0, 0, 0,
		};
		const int res = _cal_num_type(content, n, m);
		output_res(content, m, n, res);
	}
	{
		const int n = 7, m = 7;
		const bool content[] = {
			0, 0, 0, 0, 0, 0, 0,
			0, 0, 1, 0, 0, 0, 0,
			0, 0, 1, 0, 0, 0, 0,
			0, 0, 1, 1, 0, 0, 0,
			0, 0, 1, 0, 0, 0, 0,
			0, 0, 1, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0,
		};
		const int res = _cal_num_type(content, n, m);
		output_res(content, m, n, res);
	}
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5634601.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存