【HDOJ】3500 Fling

时间:2023-11-22 19:05:38

题意巨难懂。简言之,就是球互相碰撞时,主动碰撞的球将会停止,另一个球将沿着碰撞方向继续移动,不断碰撞。但是无法弹射紧挨着的球,但是若a弹射b,bc相邻,这种情况b可以弹射c。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; #define MAXN 10 typedef struct {
int x, y;
char d;
} node_t; node_t nodes[];
char map[MAXN][MAXN];
int on;
// U < L < R < D.
int dir[][] = {-,,,-,,,,}; bool check(int x, int y) {
return x<||x>=||y<||y>=;
} char getDir(int k) {
if (k==) return 'U';
if (k==) return 'L';
if (k==) return 'R';
return 'D';
} bool dfs(int n) {
int i, j, k, x, y;
bool flag; if (n == )
return true; for (i=; i<; ++i) {
for (j=; j<; ++j) {
if (map[i][j] == 'O') {
for (k=; k<; ++k) {
x = i + dir[k][];
y = j + dir[k][];
if (check(x, y) || map[x][y]=='O')
continue;
flag = false;
while (!check(x, y)) {
if (map[x][y] == 'O') {
flag = true;
map[x][y] = 'X';
map[x-dir[k][]][y-dir[k][]] = 'O';
}
x += dir[k][];
y += dir[k][];
}
if (flag) {
map[i][j] = 'X';
nodes[n].x = i;
nodes[n].y = j;
nodes[n].d = getDir(k);
if (dfs(n-))
return true;
do {
x -= dir[k][];
y -= dir[k][];
if (map[x][y] == 'O') {
map[x][y] = 'X';
map[x+dir[k][]][y+dir[k][]] = 'O';
}
} while (x!=i || y!=j);
map[i][j] = 'O';
}
}
}
}
} return false;
} int main() {
int i = , j;
int t = ; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%s", &map[i]) != EOF) {
for (i=; i<; ++i)
scanf("%s", &map[i]);
on = ;
for (i=; i<; ++i)
for (j=; j<; ++j)
if (map[i][j] == 'O')
++on;
dfs(on-); if (t != )
printf("\n");
printf("CASE #%d:\n", ++t);
for(i=on-; i>=; --i)
printf("%d %d %c\n", nodes[i].x, nodes[i].y, nodes[i].d);
getchar();
i = ;
} return ;
}