考试时候所有样例都过了,再打倒是不对了,谁能帮我看一看

P11228 [CSP-J 2024] 地图探险

yanghaoyu123 @ 2024-10-26 16:59:37

#include <iostream>
using namespace std;
int main(){
    int T;
    cin>>T;
    for (int i=0;i<T;i++){
        int n,m,k,c=1;
        cin>>n>>m>>k;
        int x,y,d;
        cin>>x>>y>>d;
        char arr[n+1][m+1];
        for (int i=1;i<=n;i++){
            for (int j=1;j<=m;j++){
                cin>>arr[i][j];
            }
        }
        for (int i=0;i<=n;i++){
            for (int j=0;j<=m;j++){
                cout<<arr[i][j];
            }
            cout<<endl;
        }
        arr[x][y]=='1';
        for (int k1=0;k1<k;k1++){
            if (d==0){
                if (arr[x][y+1]=='.'){
                    c+=1;
                    y+=1;
                    arr[x][y]='1';
                }
                else if (arr[x][y+1]=='1'){
                    y+=1;
                }
                else{
                    d+=1;
                    d%=4;
                }
            }
            else if (d==1){
                if (arr[x+1][y]=='.'){
                    c+=1;
                    x+=1;
                    arr[x][y]='1';
                }
                else if (arr[x+1][y]=='1'){
                    x+=1;
                }
                else{
                    d+=1;
                    d%=4;
                }
            }
            else if (d==2){
                if (arr[x][y-1]=='.'){
                    c+=1;
                    y-=1;
                    arr[x][y]='1';
                }
                else if (arr[x][y-1]=='1'){
                    y-=1;
                }
                else{
                    d+=1;
                    d%=4;
                }
            }
            else if (d==3){
                if (arr[x-1][y]=='.'){
                    c+=1;
                    x-=1;
                    arr[x][y]='1';
                }
                else if (arr[x-1][y]=='1'){
                    x-=1;
                }
                else{
                    d+=1;
                    d%=4;
                }
            }
        }
        cout<<c<<endl;
    }
}

by hjb13357896690 @ 2024-10-26 18:29:31

@yanghaoyu123 坐标?


by yanghaoyu123 @ 2024-10-26 20:23:05

@hjb13357896690 啥坐标


by yanghaoyu123 @ 2024-10-26 20:29:53

O(T*K)的时间复杂度能100吗


by hjb13357896690 @ 2024-10-26 21:42:11

@yanghaoyu123 私信(明聊)


by yanghaoyu123 @ 2024-10-26 21:43:16

@hjb13357896690 6


上一页 |