一道连教练(lxn)都查不出来错的代码,玄关
查看原帖
一道连教练(lxn)都查不出来错的代码,玄关
679907
S08578楼主2024/4/11 20:48

在线求调

#include<iostream>
#include<cstring>

using namespace std;
#define int long long
const int N=205;
char s[N][N];
int dx[5]={0,0,1,-1};
int dy[5]={1,-1,0,0};
int vis[N][N];//到达i,j的最多能有多少能量
int b[N][N];
int Vis[N][N];
struct id{
    int x,y,e;
}q[N*N];
int f=0,r=1;
int n,m;
void bfs(){
    while(f<=r){
        id t=q[f];
        //cout<<t.x<<" "<<t.y<<" "<<t.e<<endl;
        f++;
        Vis[t.x][t.y]=0;
        if(t.e==0) continue;
        for(int k=0;k<4;k++){
            int xx=t.x+dx[k];
            int yy=t.y+dy[k];
            int ee=t.e;
            if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&s[xx][yy]!='#'){
                ee=max(ee-1,b[xx][yy]);
                if(ee>vis[xx][yy]){
                    vis[xx][yy]=ee;
                    if(Vis[xx][yy]==0){
                        t.e=ee;
                        t.x=xx;
                        t.y=yy;
                        r++;
                        q[r]=t;
                        Vis[xx][yy]=1;
                        
                    }
                    
                    
                }
            }
        }
        
    }
}
signed main(){
    memset(vis,-1,sizeof(vis));
    cin>>n>>m;
    int si=0,sj=0,fi=0,fj=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>s[i][j];
            if(s[i][j]=='S') {
                si=i;sj=j;
            }
            if(s[i][j]=='T') {fi=i;fj=j;}
            
        }
    }
    int T;
    cin>>T;
    for(int i=1;i<=T;i++){
        int rr,cc,ee;
        cin>>rr>>cc>>ee;
        b[rr][cc]+=ee;
        
    }
    f++;
    q[f].x=si;
    q[f].y=sj;
    q[f].e=b[si][sj];
    Vis[si][sj]=1;
    bfs();
    if(vis[fi][fj]>=0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

2024/4/11 20:48
加载中...