1 solutions

  • 2
    @ 2024-2-22 21:36:05

    有一个点特别关键!!!!!!

    如果没有ans>=1000时退出循环的话

    就会有一个点TLE

    因为是10*10的格子,完了还没相遇就不会相遇 了,输出0.

    AC呆马:

    #include<bits/stdc++.h>
    using namespace std;
    const int x[10]={-1,0,1,0},y[10]={0,1,0,-1};
    string arr[1100];
    int main(){
        int fx,fy,cx,cy,a=0,b=0,ans=0;
        for(int i=0;i<10;i++){
            cin>>arr[i];
            for(int j=0;j<10;j++){
                if(arr[i][j]=='F') fx=i,fy=j;
                if(arr[i][j]=='C') cx=i,cy=j;
            }
        }
        while(true){
            ans++;
            if(fx+x[a]>=0 && fx+x[a]<10 && fy+y[a]>=0 && fy+y[a]<10 && arr[fx+x[a]][fy+y[a]]!='*'){
                fx+=x[a];
                fy+=y[a];
            }
            else{
                a+=1;
                a%=4;
            }
            if((fx==cx && fy==cy) || ans>1000){
                cout<<'0';
                return 0;
            }
            if(cx+x[b]>=0 && cx+x[b]<10 && cy+y[b]>=0 && cy+y[b]<10 && arr[cx+x[b]][cy+y[b]]!='*'){
                //cout<<cx<<' '<<cy<<endl;
                cx+=x[b];
                cy+=y[b];
            }
            else{
                b+=1;
                b%=4;
            }
            if(fx==cx && fy==cy){
                cout<<ans;
                return 0;
            }
        }
        return 0;
    }
    
    • 1

    Information

    ID
    982
    Time
    1000ms
    Memory
    125MiB
    Difficulty
    5
    Tags
    # Submissions
    37
    Accepted
    17
    Uploaded By