0tps求助
查看原帖
0tps求助
1409556
wanghonglei_stl楼主2025/7/28 16:13
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t, n, m, k, x, y, d;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        int ans = 0;
        cin >> n >> m >> k;
        cin >> x >> y >> d;

        char c[1001][1001];

        for (int j = 1; j <= n; j++)
        {
            for (int l = 1; l <= m; l++) 
            {
                cin >> c[j][l];
            }
        }

        if (i == 1 && 1 <= x && x <= n && 1 <= y && y <= m && c[x][y] == '.')
        {
            ans++;
        }

        for (int j = 1; j <= k; j++)
        {
            int x2 = x, y2 = y;
            if (d == 0)
            {
                y2++;
            }
            else if (d == 1)
            {
                x2++;
            }
            else if (d == 2)
            {
                y2--;
            }
            else if (d == 3)
            {
                x2--;
            }

            if (1 <= x2 && x2 <= n && 1 <= y2 && y2 <= m && c[x2][y2] == '.')
            {
                ans++;
                x = x2;
                y = y2;
            }
            else
            {
                d = (d + 1) % 4;
            }
        }

        cout << ans << endl;
    }
    return 0;
}
2025/7/28 16:13
加载中...