• (第四场)F Beautiful Garden


    题目:

    F Beautiful Garden

    题目描述 

    There's a beautiful garden whose size is n x m in Chiaki's house. The garden can be partitioned into n x m equal-sized square chunks. There are some kinds of flowers planted in each square chunk which can be represented by using lowercase letters.
    However, Chiaki thinks the garden is not beautiful enough. Chiaki would like to build a water pool in the garden. So that the garden would look like symmetric (both horizontally and vertically). The water pool is a rectangle whose size is p x q and the center of the water pool is also the center of the garden.
    Something else important you should know is:
    • n, m, p and q are all even.
    • p is always less than n.
    • q is always less than m.
    • The borders of the water pool are parallel to the border of garden.
    Chiaki would like to know the number of different pairs of (p, q) she can choose.

    输入描述:

    There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 100) indicating the number of test cases. For each test case:
    The first line contains two integers n and m (1 ≤ n, m ≤ 2000, n and m are even) -- the size of the garden. For next n lines, each line contains m characters showing the garden. It is guaranteed that only lowercase letters will appear.

    输出描述:

    For each test case, output an integer indicating the number of choices to build the water pool.

    题目大意:

    •n x m的格⼦子,选个p x q的,中⼼心重合,且上下左右对称

    •求(p, q)⽅方案数

    •n, m <= 2000, n, m是偶数 

    官方题解:

    •直接模拟即可

    大概思路:

    其实就是求外框的长 max_p 和 宽 max_q,内部的变换就是 max_p*max_q, 不过有些特殊的就是外框必须要 >= 1 ,否则无解,而且当外框 max_p == N/2 或者 max_q == M/2时,对应得需要减一,模拟题,细心点就可以了。

    AC code:

    #include <map>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define INF 0x3f3f3f3f
    #define ll long long int
    using namespace std;
    
    const int MAXN = 2e3+10;
    const int MAXM = 2e3+10;
    
    char mmp[MAXN][MAXM];
    int N, M;
    
    int main()
    {
        int T_case;
        scanf("%d", &T_case);
        while(T_case--)
        {
            scanf("%d%d", &N, &M);
            for(int i = 0; i < N; i++)
            {
                scanf("%s", &mmp[i]);
            }
    
            long long int max_p = 0;
            bool flag = 1;
            for(int i = 0; i < N/2; i++)
            {
                flag = 1;
                for(int j = 0; j < M; j++)
                {
                    if(mmp[i][j] != mmp[N-i-1][j])
                    {flag = 0;break;}
    
                }
                if(flag)max_p++;
                else break;
            }
    
            long long int max_q = 0;
            flag = 1;
            for(int i = 0; i < M/2; i++)
            {
                flag = 1;
                for(int j = 0; j < N; j++)
                {
                    if(mmp[j][i] != mmp[j][M-i-1]) {
                            flag = 0;break;
                    }
    
                }
                if(flag) max_q++;
                else break;
            }
    
            //printf("p:%d q:%d
    ", max_p, max_q);
            if(max_p >= 1 && max_q >= 1)
            {
                if(max_p == N/2)
                max_p = max_p-1;
                if(max_q == M/2)
                max_q = max_q-1;
                long long int ans = (max_p)*(max_q);
                printf("%lld
    ", ans);
            }
            else printf("0
    ");
    
            }
    
        return 0;
    }
  • 相关阅读:
    字典序(摘)
    N
    Y
    B
    购物网站和秒杀系统实现技术
    行测技巧:十字交叉法解决比值混合问题
    数学符号读法大全
    搜狐畅游编程题
    sql删除重复记录
    'for' loop initial declarations are only allo
  • 原文地址:https://www.cnblogs.com/ymzjj/p/9385747.html
Copyright © 2020-2023  润新知