牛客网暑期ACM多校训练营(第四场) F题 Beautiful Garden

链接:https://www.nowcoder.com/acm/contest/142/F
来源:牛客网
 

题目描述

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.

示例1

输入

3
6 8
acbbbbca
dcaccacd
cdaddadc
cdaddadc
dcaccacd
acbbbbca
6 8
acbcbbca
dcaccacd
cdaddadc
cdaddadc
dcaccacd
acbbbbca
6 8
acbbbbca
dcadcacd
cdaddadc
cdaddadc
dcaccacd
acbbbbca

输出

6
0
3

题意:

在给定的一个图中,挖取一个矩形游泳池,图的长宽和游泳池的长宽都为偶数,截取后剩下的图形中心对称,只能遍历1/4的图

不然会时间超限,主要代码如下:

 

如果一点不与该点的长宽以及对角都对称,则取出该点,并挖取其以该点为顶点的最大的不对称矩形,求出矩形的宽和长为x,y

则结果为(m-x)*(n-y)*4

判断图形是否对称的核心代码如下:

#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
char map[2100][2100];
int N,M;
bool jud(int x,int y)
{
    if(map[x][y]!=map[N-x-1][y])
        return 1;
    if(map[x][y]!=map[x][M-y-1])
        return 1;
    if(map[x][y]!=map[N-x-1][M-y-1])
        return 1;
    return 0;
}
int main()
{
    int x,y,n,m;
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        N=n;
        M=m;
        for(int i=0; i<n; ++i)
           scanf("%s",map[i]);
        n=n/2;
        m=m/2;
        x=n-1;
        y=m-1;
        for(int i=0; i<n; ++i)
        {
            for(int j=0; j<m; ++j)
            {
                if(jud(i,j))
                {
                    x=min(x,i);
                    y=min(y,j);
                    break;
                }
            }
        }
        printf("%d\n",x*y);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值