33分求佬救救
查看原帖
33分求佬救救
1125710
Keria04楼主2023/10/25 23:15
#include<iostream>
#include<string>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<ctime>
using namespace std;
char map[12][12];
int ans=0;
int c[4],f[4];
void move(int x[])
{
    if(x[1]==0)
    {
     if(map[x[2]][x[3]+1]=='*')x[1]=1;
     else x[3]++;
    }
    else if(x[1]==1)
    {
     if(map[x[2]+1][x[3]]=='*')x[1]=2;
     else x[2]++;
    }
    else if(x[1]==2)
    {
     if(map[x[2]][x[3]-1]=='*')x[1]=3;
     else x[3]--;
    }
    else if(x[1]==3)
    {
        if(map[x[2]-1][x[3]]=='*')x[1]=0;
        else x[2]--;
    }
}
int main()
{
    c[1]=3;f[1]=3;
    //地图初始化
    for(int i=0;i<=11;i++){map[i][0]='*';map[i][11]='*';map[0][i]='*';map[11][i]='*';}
    for(int i=1;i<=10;i++)
        for(int j=1;j<=10;j++)
        {
            cin>>map[i][j];
            if(map[i][j]=='C'){c[2]=i;c[3]=j;}
            if(map[i][j]=='F'){f[2]=i;f[3]=j;}
        }
    
    while(c[2]!=f[2]&&c[3]!=f[3])
    {
        move(c);
        move(f);
        ans++;
        if(ans>180000){ans=0;break;}
    }
    cout<<ans;
}
2023/10/25 23:15
加载中...