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

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

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

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
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#define long long LL
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define lson o<<1
#define rson o<<1|1
using namespace std;
char s[2005][2005];
char x[2005];
int n,m,t;
int main()
{
	cin>>t;
	//getchar();
	while(t--)
	{
		memset(s,0,sizeof(s));
		//memset(x,0,sizeof(x));
		//memset(y,0,sizeof(y));
		scanf("%d %d",&n,&m);
		getchar();
		int ans = INF;
		int ans1 = INF;
		for(int i=0;i<n;i++)
			scanf("%s",s[i]);
		for(int i=0;i<m;i++)
			{
				for(int j=0;j<n/2;j++)
				{
					if(s[j][i]!=s[n-j-1][i])
					{
						//printf("%c %c\n",s[i][j],s[i][m-j-1]);
						ans = min(ans,j);
						ans1 = min(i, ans1);
					}
				}
			}
			//printf("%d %d\n",ans,ans1);
			for(int i=0;i<n;i++)
			{
				for(int j=0;j<m/2;j++)
				{
					if(s[i][j]!=s[i][m-j-1])
					{
						//printf("%c %c\n",s[i][j],s[i][m-j-1]);
						ans = min(ans,i);
						ans1 = min(j, ans1);
					}
				}
			}
		//	printf("%d %d\n",ans,ans1);
			if(ans == 0 ||ans == n-1 || ans1 == 0 || ans1 == m-1)
				puts("0");
			else if(ans == INF && ans1 == INF)
				printf("%d\n",(n/2-1)*(m/2-1));
			else {
				
			//	printf("%d %d\n",ans,ans1);
				printf("%d\n",ans*ans1);
			}
		
		
	}
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值