比赛 |
防止颓废的小练习v0.2 |
评测结果 |
AAAAAAAAAA |
题目名称 |
玛雅游戏 |
最终得分 |
100 |
用户昵称 |
KZNS |
运行时间 |
2.000 s |
代码语言 |
C++ |
内存使用 |
0.29 MiB |
提交时间 |
2016-10-18 10:04:48 |
显示代码纯文本
//KZNS
#include <cstdio>
#include <cstring>
using namespace std;
class poi {
public:
int mp[5][7];
void a0() {
memset(mp, 0, sizeof(mp));
}
bool empty() {
for (int i = 0; i < 5; i++)
for (int j = 0; j < 7; j++)
if (mp[i][j])
return false;
return true;
}
void fall() {
for (int i = 0; i < 5; i++) {
for (int j = 0, k = 0; j < 7; j++) {
if (mp[i][j]) {
if (j != k) {
mp[i][k] = mp[i][j];
mp[i][j] = 0;
}
k++;
}
}
}
}
bool xiao() {
bool f[5][7] = {false};
int n = 0, l;
//x;
for (int j = 0; j < 7; j++) {
l = 0;
for (int i = 0; i < 5; i++) {
if (mp[i][j]) {
if (mp[i][j] == l)
n++;
else {
l = mp[i][j];
n = 1;
}
if (n == 3)
for (int k = 0; k < 3; k++)
f[i-k][j] = true;
else if (n > 3)
f[i][j] = true;
}
else
l = 0;
}
}
//y;
for (int i = 0; i < 5; i++) {
l = 0;
for (int j = 0; j < 7; j++) {
if (mp[i][j]) {
if (mp[i][j] == l)
n++;
else {
l = mp[i][j];
n = 1;
}
if (n == 3)
for (int k = 0; k < 3; k++)
f[i][j-k] = true;
else if (n > 3)
f[i][j] = true;
}
else
l = 0;
}
}
bool fff = false;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 7; j++) {
if (f[i][j]) {
fff = true;
mp[i][j] = 0;
}
}
}
return fff;
}
void change() {
fall();
while (xiao())
fall();
}
};
int N;
poi P;
void rin() {
scanf("%d", &N);
P.a0();
int u;
for (int i = 0; i < 5; i++) {
int j = 0;
for (; j < 7; j++) {
scanf("%d", &u);
if (u) {
P.mp[i][j] = u;
}
else {
break;
}
}
if (j == 7)
scanf("%d", &u);
}
}
int mvls[6][3];
bool found = false;
void DFS(poi G, int dp) {
if (dp >= N) {
if (G.empty())
found = true;
return;
}
poi U;
int c;
bool ud[4][7] = {false};
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 7; j++) {
if (!G.mp[i][j])
break;
mvls[dp][0] = i;
mvls[dp][1] = j;
if (i != 4 && !ud[i][j]) {
ud[i][j] = true;
U = G;
c = U.mp[i][j];
U.mp[i][j] = U.mp[i+1][j];
U.mp[i+1][j] = c;
mvls[dp][2] = 1;
U.change();
DFS(U, dp+1);
if (found)
return;
}
if (i != 0 && !ud[i-1][j]) {
ud[i-1][j] = true;
U = G;
c = U.mp[i][j];
U.mp[i][j] = U.mp[i-1][j];
U.mp[i-1][j] = c;
mvls[dp][2] = -1;
U.change();
DFS(U, dp+1);
if (found)
return;
}
}
}
}
void ansit() {
if (found)
for (int i = 0; i < N; i++)
printf("%d %d %d\n", mvls[i][0], mvls[i][1], mvls[i][2]);
else
printf("-1");
}
int main() {
freopen("mayan.in", "r", stdin);
freopen("mayan.out", "w", stdout);
rin();
DFS(P, 0);
ansit();
return 0;
}
//UBWH