50pts求条
查看原帖
50pts求条
911026
jaspersgr114514楼主2024/10/28 21:50
#include <bits/stdc++.h>
using namespace std;
int T, n, m, k;
int stx, sty, stdd;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
bool mp[1005][1005];
bool vis[1005][1005];
int main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> T;
    while (T--)
    {
        memset(vis, 0, sizeof vis);
        memset(mp, 0, sizeof mp);
        cin >> n >> m >> k;
        cin >> stx >> sty >> stdd;
        char c;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                cin >> c;
                if (c == '.')
                    mp[i][j] = 1;
                else
                    mp[i][j] = 0;
            }
        }
        int x = stx, y = sty, d = stdd;
        int newx, newy, newd;
        int ans = 1;
        while (k--)
        {
            newx = x + dx[d];
            newy = y + dy[d];
            if (newx > n || newx < 1 || newy > m || newy < 1 || mp[newx][newy] == 0)
            {
                d = (d + 1) % 4;
                continue;
            }
            if (mp[newx][newy] && !vis[newx][newy])
            {
                vis[newx][newy] = true;
                ans++;
            }
            x = newx;
            y = newy;
        }
        cout << ans << endl;
    }
}
2024/10/28 21:50
加载中...