10分,求助(考场过了,回家WA)
查看原帖
10分,求助(考场过了,回家WA)
1279423
zzhengxi楼主2024/10/26 21:56

代码来了

#include<bits/stdc++.h>
using namespace std;

bool v[1010][1010];
char mp[1010][1010];
int ne[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};
int main(){
    int t,n,m,k;
    cin >> t;
    while(t --){
        cin >> n >> m >> k;
        int x,y,d;
        cin >> x >> y >> d;
        for(int i = 1 ; i <= n ; i ++)
            for(int j = 1 ; j <= m ; j ++)
                cin >> mp[i][j];
        v[x][y] = true;
        for(int i = 1 ; i <= k ; i ++){
            //cout << i << "." << x << ' ' << y << ' ' << d << '\n';
            int xx = x + ne[d][0];
            int yy = y + ne[d][1];
            //cout << xx << ' ' << yy << '\n';
            if(xx >= 1 && yy >= 1 && xx <= n && yy <= m && mp[xx][yy] == '.'){
                x = xx,y = yy;
                v[xx][yy] = true;
                //cout << "A";
            }
            else 
            {
            d = (d + 1) % 4;
                //cout << "A";
            }
        }
        int cnt = 0;
        for(int i = 1 ; i <= n ; i ++)
            for(int j = 1 ; j <= m ; j ++)
                if(v[i][j] == true)
                    cnt ++;
        cout << cnt << '\n';

    }
    return 0;
}

求助

2024/10/26 21:56
加载中...