浜岀淮鏁扮粍瑕嗙洊

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了浜岀淮鏁扮粍瑕嗙洊相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/net' title='net'>net   def   main   棰樼洰   codeforce   end   define   string   name   

棰樼洰閾炬帴锛?a href="https://codeforces.com/contest/1280/problem/B">https://codeforces.com/contest/1280/problem/B

#include<iostream>
#include<cstring>
#define int long long
using namespace std;
const int N = 65;
int rt[N],ct[N],t,r,c;
char g[N][N];

/*
棰樻剰:鍙兘閫夋嫨1x X 鎴栬€?X * 1鐨勬牸瀛愶紝鍙互涓婁笅宸﹀彸绉诲姩浠绘剰姝ワ紝灏嗗叏鍥惧彉鎴怉闇€瑕佸灏戞鎿嶄綔.

杈撳嚭MORTAL锛氬綋鍏ㄩ儴涓篜鏃?杈撳嚭0锛氬綋鍏ㄩ儴涓篈鏃?杈撳嚭1锛氱1琛屾垨绗瑀琛屾垨绗?鍒楁垨绗琧鍒楀叏涓篈
杈撳嚭2锛氬洓瑙掓湁涓€涓负A 鎴栬€?绗簩琛岃嚦鍊掓暟绗簩琛屾湁涓€琛屽叏涓篈 鎴?绗簩鍒楄嚦鍊掓暟绗垪琛屾湁涓€鍒楀叏涓篈
杈撳嚭3锛氬湪涓嶆弧瓒充笂杩版潯浠朵笅锛岀涓€琛屾垨鏈€鍚庝竴琛屾垨绗竴鍒楁垨鏈€鍚庝竴鍒楁湁涓€涓负A鍗冲彲
杈撳嚭4锛氫笂杩伴兘涓嶆弧瓒炽€?*/

int solve()
{
    memset(rt,0,sizeof(rt));
    memset(ct,0,sizeof(ct));
    int sum = 0;
    for(int i = 1;i <= r;i++)
    {    
        for(int j = 1;j <= c;j++)
        {
            if(g[i][j] == 鈥?/span>A鈥?/span>)
            {
                sum++;
                rt[i]++;
                ct[j]++;
            }
        }
    }
    if(sum == 0)
        return -1;
    if(sum == r * c)
        return 0;
    if(rt[1] == c || rt[r] == c || ct[1] == r || ct[c] == r)
        return 1;
    if(g[1][1] == 鈥?/span>A鈥?/span> || g[1][c] == 鈥?/span>A鈥?/span> || g[r][1] == 鈥?/span>A鈥?/span> || g[r][c] == 鈥?/span>A鈥?/span>)
        return 2;
    for(int i = 2;i <= r;i++)
        if(rt[i] == c)
            return 2;
    for(int i = 2;i <= c;i++)
        if(ct[i] == r)
            return 2;
    if(rt[1] || rt[r] || ct[1] || ct[c])
        return 3;
    return 4;
}

signed main()
{
    int t;
    cin >> t;
    while(t--)
    {
        cin >> r >> c;
        for(int i = 1;i <= r;i++)
            cin >> g[i] + 1;
        int sol = solve();
        if(sol == -1)
            cout << "MORTAL" << endl;
        else
            cout << sol << endl;
    }
    return 0;
}

鎬濊矾涓庝唬鐮佹潵婧愶細https://blog.csdn.net/qq_41280600/article/details/103604769

以上是关于浜岀淮鏁扮粍瑕嗙洊的主要内容,如果未能解决你的问题,请参考以下文章

涓€缁?amp;&浜岀淮鏍戠姸鏁扮粍

leetcode-64-鏈€灏忚矾寰勫拰

銆愮粡鍏搞€戝甫闅滅鐨勯摵鐮栧潡鈥斺€擫EETCODE 瑕嗙洊

js鏁扮粍鐨勫0鏄庝笌搴旂敤

鏁扮粍鐨勫唴瀛樺浘

鎷兼帴鏁扮粍