1 条题解

  • 0
    @ 2025-11-9 9:00:12
    #include <bits/stdc++.h>
    using namespace std;
    // #define int long long
    const int N = 1e3 + 10, inf = 1e9;
    char a[N][N];
    char b[N * 10];
    void solve()
    {
        int n, m;
        cin >> n >> m;
        for (int i = 0; i < n; i++)
            cin >> a[i];
        int ans = 0;
        int n_m=min(n,m);//最小的层数
        for (int i = 0; (i + 1) * 2 <= n_m; i++)
        {
            int cnt = 0;
            for (int j = i; j < m - i; j++)  //上
                b[cnt++] = a[i][j];
    
            for (int j = i + 1; j < n - i - 1; j++)  //右
                b[cnt++] = a[j][m - i - 1];
    
            for (int j = m - i - 1; j >= i; j--)  // 下
                b[cnt++] = a[n - i - 1][j];
    
            for (int j = n - i - 2; j >= i + 1; j--)  //左
                b[cnt++] = a[j][i];
    
    
            for (int j = 0; j < cnt; j++)
            {
                if (b[j] == '1' && b[(j + 1) % cnt] == '5' && b[(j + 2) % cnt] == '4' && b[(j + 3) % cnt] == '3')
                    ans++;
            }
        }
        cout << ans << '\n';
    }
    
    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int _ = 1;
        cin >> _;
        while (_--)
            solve();
    
        return 0;
    }
    
    • 1

    信息

    ID
    1193
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    (无)
    递交数
    70
    已通过
    14
    上传者