一,游戏规则
示例:
9 | 5 | 4 | 9 | 3 | 6 | 6 | 3 | 4 | 5 |
5 | 9 | 1 | 5 | 8 | 2 | 7 | 3 | 2 | 5 |
3 | 5 | 3 | 7 | 1 | 7 | 6 | 2 | 4 | 5 |
5 | 7 | 8 | 6 | 7 | 4 | 7 | 4 | 6 | 9 |
1 | 3 | 4 | 9 | 5 | 5 | 2 | 2 | 4 | 1 |
6 | 1 | 7 | 6 | 6 | 5 | 1 | 5 | 6 | 9 |
3 | 2 | 5 | 5 | 4 | 4 | 4 | 3 | 4 | 1 |
5 | 2 | 2 | 7 | 5 | 7 | 1 | 4 | 6 | 6 |
9 | 1 | 4 | 8 | 3 | 6 | 3 | 5 | 7 | 1 |
6 | 3 | 9 | 2 | 3 | 6 | 2 | 5 | 5 | 7 |
4 | 1 | 8 | 8 | 2 | 5 | 1 | 9 | 8 | 4 |
6 | 1 | 5 | 2 | 5 | 3 | 9 | 6 | 7 | 9 |
8 | 7 | 9 | 8 | 2 | 2 | 5 | 9 | 4 | 3 |
4 | 2 | 2 | 8 | 6 | 4 | 5 | 4 | 7 | 9 |
2 | 8 | 7 | 2 | 4 | 6 | 8 | 9 | 8 | 9 |
1 | 3 | 2 | 6 | 4 | 4 | 9 | 7 | 5 | 8 |
二,贪心算法
我们先用贪心算法试一下,能消除到什么程度。
这里用的是一个不太严格的贪心算法,也就是肉眼所到之处,看到啥就消除啥。
(1)消除横着的或者竖着的2个或者3个
(2)继续消除,这一轮形状会比较多
(3)继续消除
(4)无法消除的数字
还有45个数字无法消除
三,枚举算法
我们用枚举算法试一下,可以消除到什么程度
代码:
void cal(vector<vector<int>>& v)
{
for (int r = 0; r < 16; r++) {
for (int r2 = r; r2 < 16; r2++) {
for (int c = 0; c < 10; c++) {
for (int c2 = c; c2 < 10; c2++) {
int s = 0;
for (int i = r; i <= r2; i++) {
for (int j = c; j <= c2; j++) {
s += v[i][j];
}
}
if (s > 10)break;
if (s == 10) {
for (int i = r; i <= r2; i++) {
for (int j = c; j <= c2; j++) {
v[i][j] = 0;
}
}
cout << "r:" << r << "to" << r2 << endl;
cout << "c:" << c << "to" << c2 << endl;
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 10; j++) {
cout << v[i][j];
}
cout << endl;
}
cout << endl << endl;
return;
}
}
}
}
}
}
int main() {
vector<vector<int>>v(16,vector<int>(10));
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 10; j++) {
cin >> v[i][j];
}
}
for (int i = 0; i < 100; i++) {
cal(v);
}
return 0;
}
输入:
9 5 4 9 3 6 6 3 4 5
5 9 1 5 8 2 7 3 2 5
3 5 3 7 1 7 6 2 4 5
5 7 8 6 7 4 7 4 6 9
1 3 4 9 5 5 2 2 4 1
6 1 7 6 6 5 1 5 6 9
3 2 5 5 4 4 4 3 4 1
5 2 2 7 5 7 1 4 6 6
9 1 4 8 3 6 3 5 7 1
6 3 9 2 3 6 2 5 5 7
4 1 8 8 2 5 1 9 8 4
6 1 5 2 5 3 9 6 7 9
8 7 9 8 2 2 5 9 4 3
4 2 2 8 6 4 5 4 7 9
2 8 7 2 4 6 8 9 8 9
1 3 2 6 4 4 9 7 5 8
输出:
......
r:14to14
c:0to1
9049000000
0000000000
0000000000
0086000000
0049000000
0076000000
0000000000
0027000000
9040000000
0090000000
0080000084
6000009679
8090000943
4000000479
0070008989
1320009758
剩余43个,单论个数的话,居然比我人工做的还好。。。
四,一些启发式策略
边框,小数字是资源,大数字是障碍