求条

P11228 [CSP-J 2024] 地图探险

shizhihao11 @ 2024-11-24 20:42:49

code:

#include<bits/stdc++.h>
using namespace std;
int cnt; 
int n,m,k;
int nx,ny,d;
char a[1005][1005];
int dx[4]={0,1,0,-1}; 
int dy[4]={1,0,-1,0}; 
int main() {
    int t;
    cin>>t;
    while(t--){
        cnt=0; 
        cin>>n>>m>>k;
        cin>>nx>>ny>>d;
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=m;j++) {
                cin>>a[i][j];
            }
        }
        while(k>0){
            int n_x=nx+dx[d];
            int n_y=ny+dy[d];
            if (n_x>=1&&n_x<=n&&n_y>=1&&n_y<=m&&a[n_x][n_y]=='.'){
                nx=n_x;
                ny=n_y;
                cnt++;
            } 
            else {
                d=(d+1)%4;
            }
            k--; 
        }
        cout<<cnt<<endl; 
    }
    return 0;
}

诸位大佬帮帮本蒟蒻吧!


by shizhihao11 @ 2024-11-24 20:43:54

目前:满江红


by Chengqijun2012 @ 2024-11-24 20:53:51

@shizhihao11哪题?


by shizhihao11 @ 2024-11-24 20:55:29

P11228


by KingkongLi @ 2024-11-30 14:47:29

cnt++有问题


by KingkongLi @ 2024-11-30 14:48:01

每走一格就+1?


|