RE求助,请大佬挑错!
查看原帖
RE求助,请大佬挑错!
257621
翼德天尊楼主2020/4/30 09:02
#include<bits/stdc++.h>
using namespace std;
int flag=99999999,n,m,cy,cs,d,ma2[351][351],ans[351][351][15][15],anz=99999999,any=99999999,anss;
bool v[351][351][15][15];
char ma1;
int dx[8]={0,0,1,-1,1,1,-1,-1};
int dy[8]={1,-1,0,0,-1,1,1,-1};
struct node{
    int x,y,cy,cs;
};
node s,e;
queue<node> q;
int main(){
    //freopen("bandit.in","r",stdin);
    //freopen("bandit.out","w",stdout);
    ios::sync_with_stdio(false);
    cin>>n>>m>>cy>>cs>>d;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            string zc;
            cin>>zc;
            if (zc.size()==1){
                ma1=zc[0];
                if (ma1=='S') s.x=i,s.y=j,s.cs=cs,s.cy=cy;
                if (ma1=='T') e.x=i,e.y=j;
                if (ma1>='0'&&ma1<='9'){
                    ma2[i][j]=2;
                    int a=ma1-'0';
                    for (int x=i-a;x<=i+a;x++){
                        for (int y=j-a;y<=j+a;y++){
                            if (abs(x-i)+abs(y-j)<a&&x>=1&&y>=1&&x<=n&&y<=m&&!ma2[x][y]) ma2[x][y]=1;
                        }
                    }
                }
            }else{
                int w=0;
                for (int x=0;x<zc.size();x++){
                    w=w*10+zc[x]-'0';
                }
                ma2[i][j]=2;
                for (int x=i-w;x<=i+w;x++){
                    for (int y=j-w;y<=j+w;y++){
                        if (abs(x-i)+abs(y-j)<w&&x>=1&&y>=1&&x<=n&&y<=m&&!ma2[x][y]) ma2[x][y]=1;
                    }
                }
            }
        }
    }

    q.push(s);
    v[s.x][s.y][s.cy][s.cs]=1;
    while (!q.empty()){
        node w=q.front();
        q.pop();
        int s=ans[w.x][w.y][w.cy][w.cs]+1;
        if (s-1>flag) break;
        if (w.x==e.x&&w.y==e.y){
            flag=s-1;
            int r=cs+cy-w.cs-w.cy;
            if (r<anz) anz=r,any=cy-w.cy,anss=cs-w.cs;
            else if (r==anz&&cy-w.cy<any) any=cy-w.cy,anss=cs-w.cs;
            continue;
        }
        for (int i=0;i<8;i++){
            node ww;
            ww.x=w.x+dx[i],ww.y=w.y+dy[i],ww.cs=w.cs,ww.cy=w.cy;
            if (ma2[ww.x][ww.y]==1) ww.cy--;

            if (ww.x>=1&&ww.x<=n&&ww.y>=1&&ww.y<=m&&v[ww.x][ww.y][ww.cy][ww.cs]==0&&(ma2[ww.x][ww.y]==0||ma2[ww.x][ww.y]==1&&ww.cy>=0)){

                q.push(ww);

                v[ww.x][ww.y][ww.cy][ww.cs]=1;
                ans[ww.x][ww.y][ww.cy][ww.cs]=s;
            }
        }
        if (w.cs>0){
            for (int i=0;i<4;i++){
                node ww;
                ww.x=w.x+dx[i]*d,ww.y=w.y+dy[i]*d,ww.cs=w.cs-1,ww.cy=w.cy;
                if (ma2[ww.x][ww.y]==1) ww.cy--;
                if (ww.x>=1&&ww.x<=n&&ww.y>=1&&ww.y<=m&&v[ww.x][ww.y][ww.cy][ww.cs]==0&&(ma2[ww.x][ww.y]==0||ma2[ww.x][ww.y]==1&&ww.cy>=)0&&ww.cs>=0){
                    q.push(ww);
                    v[ww.x][ww.y][ww.cy][ww.cs]=1;
                    ans[ww.x][ww.y][ww.cy][ww.cs]=s;
                }
            }
        }
    }
    if (anz==99999999) cout<<-1<<endl;
    else cout<<flag<<" "<<any<<" "<<anss<<endl;
    return 0;
} 
2020/4/30 09:02
加载中...