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

题目

妹的,完全是标题党

所谓难题

观察以下计算,发现有什么规律?
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 <iostream>
#include <map>

const static std::map<int, int> 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);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值