[COCI2006-2007#6] KAMEN
2024年12月25日大约 1 分钟
P6370. [COCI2006-2007#6] KAMEN
60 分
#include <bits/stdc++.h>
using namespace std;
const int MAXR = 30000;
const int MAXC = 30;
int r, c, n;
char g[MAXR + 5][MAXC + 5];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> r >> c;
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
cin >> g[i][j];
cin >> n;
while (n--)
{
int x, y;
cin >> y;
x = 1;
if (g[x][y] == 'X' || g[x][y] == 'O')
continue;
while (x != r)
{
if (g[x + 1][y] == '.')
x++;
else if (g[x + 1][y] == 'X')
break;
else if (y != 1 && g[x][y - 1] == '.' && g[x + 1][y - 1] == '.')
x++, y--;
else if (y != c && g[x][y + 1] == '.' && g[x + 1][y + 1] == '.')
x++, y++;
else
break;
}
g[x][y] = 'O';
}
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= c; j++)
cout << g[i][j];
cout << "\n";
}
return 0;
}
100 分
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int r, c, m;
//存图
char g[30005][35];
//(1,i)为起点的路径,第j个点为(j,path[i][j])
int path[35][30005];
//(1,i)为起点的路径,最后一个点在第lastRow[i]行
int lastRow[35];
//维护路径
void run(int ith, int nowX, int nowY)
{
path[ith][nowX] = nowY;
while (1)
{
if (g[nowX + 1][nowY] == 'X')
break;
if (g[nowX + 1][nowY] == '.')
nowX++;
else if (g[nowX][nowY - 1] == '.' && g[nowX + 1][nowY - 1] == '.')
nowX++, nowY--;
else if (g[nowX][nowY + 1] == '.' && g[nowX + 1][nowY + 1] == '.')
nowX++, nowY++;
else
break;
path[ith][nowX] = nowY;
}
lastRow[ith] = nowX;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> r >> c;
memset(g, 'X', sizeof(g));
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
cin >> g[i][j];
for (int i = 1; i <= c; i++)
run(i, 1, i);
cin >> m;
while (m--)
{
int nowC;
cin >> nowC;
int toX, toY;
toX = lastRow[nowC];
toY = path[nowC][toX];
g[toX][toY] = 'O';
for (int i = 1; i <= c; i++)
if (lastRow[i] == toX && path[i][toX] == toY)
run(i, toX - 1, path[i][toX - 1]);
}
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= c; j++)
cout << g[i][j];
cout << endl;
}
return 0;
}