p1518求调(悬2关)
  • 板块灌水区
  • 楼主Chinese_Dragon
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/11/13 20:14
  • 上次更新2023/11/13 21:40:47
查看原帖
p1518求调(悬2关)
966143
Chinese_Dragon楼主2023/11/13 20:14

11pts

#include<bits/stdc++.h>
using namespace std;
char a[50][50];
int main()
{
    int x1,y1,x2,y2,sum=0,fx1=1,fx2=1;
    for (int i=1;i<=10;++i)
    {
        for (int j=1;j<=10;++j)
        {
            cin>>a[i][j];
        }
    }
    for (int i=1;i<=10;++i)
    {
        for (int j=1;j<=10;++j)
        {
            if (a[i][j]=='F')
            {
                x1=i,y1=j;
            }
            if (a[i][j]=='C')
            {
                x2=i,y2=j;
            }
        }
    }
    while (x1!=x2||y1!=y2)
    {
        if (fx1==1)
        {
            if (x1-1==0)
            {
                fx1=2;
                goto here;
            }
            if (a[x1-1][y1]!='*')
            {
                --x1;
            }
            else
            {
                fx1=2;
                goto here;
            }
        }
        if (fx1==2)
        {
            if (y1+1==11)
            {
                fx1=3;
                goto here;
            }
            if (a[x1][y1+1]!='*')
            {
                ++y1;
            }
            else
            {
                fx1=3;
                goto here;
            }
        }
        if (fx1==3)
        {
            if (x1+1==11)
            {
                fx1=4;
                goto here;
            }
            if (a[x1+1][y1]!='*')
            {
                ++x1;
            }
            else
            {
                fx1=4;
                goto here;
            }
        }
        if (fx1==4)
        {
            if (y1-1==0)
            {
                fx1=1;
                goto here;
            }
            if (a[x1][y1-1]!='*')
            {
               --y1;
            }
            else
            {
                fx1=1;
                goto here;
            }
        }
        here:;
        if (fx2==1)
        {
            if (x2-1==0)
            {
                fx2=2;
                goto here;
            }
            if (a[x2-1][y2]!='*')
            {
                --x2;
            }
            else
            {
                fx2=2;
                goto here1;
            }
        }
        if (fx2==2)
        {
            if (y2+1==11)
            {
                fx2=3;
                goto here;
            }
            if (a[x2][y2+1]!='*')
            {
                ++y2;
            }
            else
            {
                fx2=3;
                goto here1;
            }
        }
        if (fx2==3)
        {
            if (x2+1==11)
            {
                fx2=4;
                goto here;
            }
            if (a[x2+1][y2]!='*')
            {
                ++x2;
            }
            else
            {
                fx2=4;
                goto here1;
            }
        }
        if (fx2==4)
        {
            if (y2-1==0)
            {
                fx2=1;
                goto here;
            }
            if (a[x2][y2-1]!='*')
            {
                --y2;
            }
            else
            {
                fx2=1;
                goto here1;
            }
        }
        here1:;
        ++sum;
    }
    cout<<sum;
    return 0;
}
2023/11/13 20:14
加载中...