40分求调

P11228 [CSP-J 2024] 地图探险

MuYuMC @ 2024-10-27 23:38:20

#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <iomanip>
using namespace std;
int t,n,m,k,x,y,d;
char A[2000][2000];
int book[2000][2000]; 
int chao()
{
    int x1,y1,cnt = 0;
    if(d == 0)
    {
        x1 = x;
        y1 = y + 1;
    }
    if(d == 1)
    {
        x1 = x + 1;
        y1 = y;
    }
    if(d == 2)
    {
        x1 = x;
        y1 = y - 1;
    }
    if(d == 3)
    {
        x1 = x - 1;
        y1 = y;
    }
    if(A[x1][y1] == '.')
    {
        x = x1;
        y = y1;
        if(book[x][y] == 0)
        {
            cnt++;
            book[x][y] = 1;
        }
    }
    else
    {
        d = (d + 1) % 4;
    }
    return cnt;
}
int main()
{
    long long i,j,sum = 0;
    cin >> t;
    while(t--)
    {
        int um;
        sum = 1;
        cin >> n >> m >> k;
        cin >> x >> y >> d;
        for(i = 1;i <= n;i++)
        {
            for(j = 1;j <= m;j++)
            {
                book[i][j]
            }
        }
        for(i = 1;i <= n;i++)
        {
            for(j = 1;j <= m;j++)
            {
                cin >> A[i][j];
            }
        }
        for(i = 1;i <= k;i++)
        {
            um = chao();
            sum += um;
        }
        cout << sum << endl;
    }
    return 0;
}

|