33分大红大紫求调
查看原帖
33分大红大紫求调
1153156
Elysium_Guiwow楼主2024/7/23 09:50
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ri register int
#define ld long double
#define ii inline int
#define iv inline void
#define ib inline bool
#define il inline ll
#define is inline string
#define ci const int
#define vi vector<int>
#define pq prioritb_queue
#define di deque<int>
#define pr pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define mod 500000007
#define N 15
#define endl '\n'
char m[N][N];
int hashh, fx, fy, cx, cy, fc, cc, h[mod], ans;
ib check();
iv walk(int x, int y, int c, int ck); // 0:上 1:右 2:下 3:左
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    for (ri i = 1; i <= 10; i++)
        for (ri j = 1; j <= 10; j++)
        {
            cin >> m[i][j];
            if (m[i][j] == 'F')
                fx = i, fy = j;
            if (m[i][j] == 'C')
                cx = i, cy = j;
        }
    while (!check())
    {
        hashh = fx + fy * 10 + cx * 100 + cy * 1000 + fc * 10000 + cc * 100000;
        if (h[hashh])
            cout << 0 << endl, exit(0);
        h[hashh] = 1;
        walk(fx, fy, fc, 0);
        walk(cx, cy, cc, 1);
        ++ans;
    }

    cout << ans << endl;
    return 0;
}
ib check()
{
    if (fx == cx && fy == cy)
        return 1;
    return 0;
}
iv walk(int x, int y, int c, int ck)
{
    switch (c)
    {
    case 0:
        if (m[x - 1][y] == '*')
            if (!ck)
                fc = 1;
            else
                cc = 1;
        else if (!ck)
            --fx;
        else
            --cx;
        break;
    case 1:
        if (m[x][y + 1] == '*')
            if (!ck)
                fc = 2;
            else
                cc = 3;
        else if (!ck)
            ++fy;
        else
            ++cy;
        break;
    case 2:
        if (m[x + 1][y] == '*')
            if (!ck)
                ++fc;
            else
                ++cc;
        else if (!ck)
            fx = 3;
        else
            cx = 3;
        break;
    case 3:
        if (m[x][y - 1] == '*')
            if (!ck)
                fc = 0;
            else
                cc = 0;
        else if (!ck)
            --fy;
        else
            --cy;
        break; // 0上 1右 2下 3左
    default:
        break;
    }
}
2024/7/23 09:50
加载中...