# 题目大意：

$1表示向右移动，-1表示向左移动。$$1 表示向右移动， -1 表示向左移动。$

# 分析：

①每次操作的格子按顺序从左往右选，从下往上选
$②当你操作的格子\left[x,y\right]，他的左列\left[x-1,y\right]是存在格子的，那么显然，\left[x-1,y\right]向右交换，比\left[x,y\right]向左交换要优$$②当你操作的格子[x,y]，他的左列[x-1,y]是存在格子的，那么显然，[x-1,y]向右交换，比[x,y]向左交换要优$
③相同颜色的交换没有意义
$④当某一次消完以后，存在一种颜色只剩下1个或2个，显然是无解的$$④当某一次消完以后，存在一种颜色只剩下1个或2个，显然是无解的$

# 代码：

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int Color[11], Step[6][4], Map[6][8], a[6][8], n, orz = 0, tot = 0;
bool Check = 0;

bool disPlay_Lzy() {
memset(Color, 0, sizeof(Color));
for (int i = 1; i <= 5; i++)
for (int j = 1; j <= 7; j++) Color[a[i][j]]++;
for (int i = 1; i <= 10; i++)
if (Color[i] >= 1 && Color[i] <= 2) return 0;
return 1;
}

void Move_down() {
for (int i = 1; i <= 5; i++) {
int k = 0;
for (int j = 1; j <= 7; j++) {
if (a[i][j]) a[i][++k] = a[i][j];
if (k != j) a[i][j] = 0;
}
}
}

int Shut_down() {
Move_down();
++orz;
for (int i = 1; i <= 5; i++)
for (int j = 1; j <= 5; j++)
if (a[i][j] && a[i][j + 1] && a[i][j + 2])
if (a[i][j] == a[i][j + 1] && a[i][j] == a[i][j + 2])
Map[i][j] = orz, Map[i][j + 1] = orz, Map[i][j + 2] = orz;
for (int i = 1; i <= 7; i++)
for (int j = 1; j <= 3; j++)
if (a[j][i] && a[j + 1][i] && a[j + 2][i])
if (a[j][i] == a[j + 1][i] && a[j][i] == a[j + 2][i])
Map[j][i] = orz, Map[j + 1][i] = orz, Map[j + 2][i] = orz;

int rp = 0;
for (int i = 1; i <= 5; i++)
for (int j = 1; j <= 7; j++)
if (Map[i][j] == orz) a[i][j] = 0, ++rp;

if (rp) rp += Shut_down();
return rp;
}

void Work(int dep, int num) {
if (!disPlay_Lzy) return;
if (dep > n) {
if (!num) {
for (int i = 1; i <= n; i++)
printf("%d %d %d\n", Step[i][1] - 1, Step[i][2] - 1, Step[i][3]);
exit(0);
}
return;
}
Move_down();
int c[6][8];
for (int i = 1; i <= 5; i++)
for (int j = 1; j <= 7; j++) c[i][j] = a[i][j];

for (int i = 1; i <= 5; i++)
for (int j = 1; j <= 7; j++)
if (c[i][j]) {
if (i != 5 && a[i + 1][j] != a[i][j]) {
swap(a[i][j], a[i + 1][j]);
Step[dep][1] = i,
Step[dep][2] = j,
Step[dep][3] = 1;

int rp = Shut_down();
Work(dep + 1, num - rp);
memcpy(a, c, sizeof(c));
}

if (i != 1 && !a[i - 1][j]) {
swap(a[i][j], a[i - 1][j]);
Step[dep][1] = i,
Step[dep][2] = j,
Step[dep][3] = -1;

int rp = Shut_down();
Work(dep + 1, num - rp);
memcpy(a, c, sizeof(c));
}
}
}

int main() {
scanf("%d", &n);
for (int i = 1; i <= 5; i++) {
int j = 0, x;
while (~scanf("%d", &x)) {
if (!x) break;
a[i][++j] = x;
Color[x]++;
tot++;
}
}
Work(1, tot);
printf("-1\n");
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120