ac了,应该不会被卡掉吧

P11228 [CSP-J 2024] 地图探险

xiaomiao_001 @ 2024-10-28 18:41:47

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
int n,m,a[1005][1005],T,ans[1005][1005],x,y,d,k,num;
char w;
int main(){
    cin>>T;
    while(T--){
        num=0;
        memset(ans,0,sizeof(ans));
        cin>>n>>m>>k;
        cin>>x>>y>>d;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                w=getchar();
                if(w=='\n'){
                    w=getchar();
                }
                if(w=='.'){
                    a[i][j]=1;
                }
                if(w=='x'){
                    a[i][j]=0;
                }
            }
        }
        ans[x][y]++;
        while(k--){
            if(d==0){
                if(((x<=n&&y+1<=m)&&(x>=1&&y+1>=1))&&(a[x][y+1])){
                    ans[x][y+1]++;
                    y++; 
                }
                else{
                    d=(d+1)%4;
                }
            }
            else if(d==1){
                if(((x+1<=n&&y<=m)&&(x+1>=1&&y>=1))&&(a[x+1][y])){
                    ans[x+1][y]++;
                    x++; 
                }

                else{
                    d=(d+1)%4;
                }

            }
            else if(d==2){
                if(((x<=n&&y-1<=m)&&(x>=1&&y-1>=1))&&(a[x][y-1])){
                    ans[x][y-1]++;
                    y--;
                }
                else{
                    d=(d+1)%4;
                }   
            }
            else if(d==3){
                if(((x-1<=n&&y<=m)&&(x-1>=1&&y>=1))&&(a[x-1][y])){
                    ans[x-1][y]++;
                    x--; 
                }
                else{
                    d=(d+1)%4;
                }
            }

        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(ans[i][j]){
                    num++;
                }
            }
        }
        cout<<num<<endl;
    }
    return 0;
}

别被卡掉分了


by yedalong @ 2024-10-28 19:02:35

应该不会,csp说过自己不卡常的


|