图形谜题:数字圈数揭示的图案计算

图形谜题:数字圈数揭示的图案计算

题目

妹的,完全是标题党

所谓难题

观察以下计算,发现有什么规律?

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);

}

}

相关推荐

没有找到站点
365bet娱乐场网址

没有找到站点

📅 07-04 👁️ 7003
化州桔龙商务酒店 (化州火车站店)
365bet官方开户

化州桔龙商务酒店 (化州火车站店)

📅 06-28 👁️ 1107
阿根廷世界杯夺冠一周年之方尖碑二十四功臣:洛塞尔索
365bet用网址

阿根廷世界杯夺冠一周年之方尖碑二十四功臣:洛塞尔索

📅 07-09 👁️ 8233