题目:

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+;
const int MAXM = 2e3+; 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 = ; i < N; i++)
{
scanf("%s", &mmp[i]);
} long long int max_p = ;
bool flag = ;
for(int i = ; i < N/; i++)
{
flag = ;
for(int j = ; j < M; j++)
{
if(mmp[i][j] != mmp[N-i-][j])
{flag = ;break;} }
if(flag)max_p++;
else break;
} long long int max_q = ;
flag = ;
for(int i = ; i < M/; i++)
{
flag = ;
for(int j = ; j < N; j++)
{
if(mmp[j][i] != mmp[j][M-i-]) {
flag = ;break;
} }
if(flag) max_q++;
else break;
} //printf("p:%d q:%d\n", max_p, max_q);
if(max_p >= && max_q >= )
{
if(max_p == N/)
max_p = max_p-;
if(max_q == M/)
max_q = max_q-;
long long int ans = (max_p)*(max_q);
printf("%lld\n", ans);
}
else printf("0\n"); } return ;
}

(第四场)F Beautiful Garden的更多相关文章

  1. 牛客多校第四场 F Beautiful Garden

    链接:https://www.nowcoder.com/acm/contest/142/F来源:牛客网 题目描述 There's a beautiful garden whose size is n ...

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

    链接: https://www.nowcoder.com/acm/contest/142/F 题意: n x m的矩形,选个p x q的矩形去掉,两个矩形中⼼重合,去掉后的矩形上下左右对称 求(p, ...

  3. 2018年牛客多校寒假 第四场 F (call to your teacher) (图的连通性)

    题目链接 传送门:https://ac.nowcoder.com/acm/contest/76/F 思路: 题目的意思就是判断图的连通性可以用可达性矩阵来求,至于图的存储可以用邻接矩阵来储存,求出来可 ...

  4. HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...

  5. bnu 34982 Beautiful Garden(暴力)

    题目链接:bnu 34982 Beautiful Garden 题目大意:给定一个长度为n的序列,问说最少移动多少点,使得序列成等差序列,点的位置能够为小数. 解题思路:算是纯暴力吧.枚举等差的起始和 ...

  6. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  7. NOI.AC NOIP模拟赛 第四场 补记

    NOI.AC NOIP模拟赛 第四场 补记 子图 题目大意: 一张\(n(n\le5\times10^5)\)个点,\(m(m\le5\times10^5)\)条边的无向图.删去第\(i\)条边需要\ ...

  8. CTF-i春秋网鼎杯第四场部分writeup

    CTF-i春秋网鼎杯第四场部分writeup 因为我们组的比赛是在第四场,所以前两次都是群里扔过来几道题然后做,也不知道什么原因第三场的题目没人发,所以就没做,昨天打了第四场,简直是被虐着打. she ...

  9. 牛客网NOIP赛前集训营-提高组(第四场)B区间

    牛客网NOIP赛前集训营-提高组(第四场)B区间 题目描述 给出一个序列$ a_1  \dots   a_n$. 定义一个区间 \([l,r]\) 是好的,当且仅当这个区间中存在一个 \(i\),使得 ...

随机推荐

  1. Dubbo解析及原理浅析

    原文链接:https://blog.csdn.net/chao_19/article/details/51764150 一.Duboo基本概念解释 Dubbo是一种分布式服务框架. Webservic ...

  2. (转)Shell中获取字符串长度的七种方法

    Shell中获取字符串长度的七种方法 原文:http://blog.csdn.net/jerry_1126/article/details/51835119 求字符串操作在shell脚本中很常用,下面 ...

  3. 1.3 js基础

    1.操作样式 .style  操作行间样式 .className  直接修改class   2.操作属性 .  操作已有的属性 []  点能做的方括号都能做,方括号里放字符串,能放变量.     3. ...

  4. Mavne 打包时出现程序包找到不的问题

    <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactI ...

  5. JS常用的设计模式(5)——代理模式

    代理模式的定义是把对一个对象的访问, 交给另一个代理对象来操作. 举一个例子, 我在追一个MM想给她送一束花,但是我因为我性格比较腼腆,所以我托付了MM的一个好朋友来送. 这个例子不是非常好, 至少我 ...

  6. c#-foreach的秘密

    foreach的秘密 class Program { static void Main(string[] args) { //创建Person的对象 Person p1=new Person(); / ...

  7. js数组与字符串相互转换

    一.数组转字符串(将数组元素用某个字符连接成字符串) var a, b;a = new Array(0,1,2,3,4);b = a.join("-"); 二.字符串转数组(将字符 ...

  8. 【Java集合】LinkedList详解中篇

    这是关于LinkedList的第二篇文章,我将会源码分析LinkedList的部分重要代码,关键地方我都有注释说明,希望大家能比较明白的看懂! 分析源码按照顺序分析: 变量 构造方法 方法 一.变量 ...

  9. XtraTabPage右键菜单(关闭当前页、关闭其它页、所有关闭的实现)

    实现的需求: 用户习惯是一个不可忽略的东西,默认这版的dx的tab也木有右键操作,但用户习惯操作如浏览器都有右键关闭功能,故这里实现先dx的该功能 技术实现: (1)在winform的相应控件内,拖入 ...

  10. XHR的应用场景

    一.简史 IE5.5最早实现XHR,需要通过ActiveXObject创建xhr实例,直到IE7才定义了XMLHttpRequest对象.IE5.5实现XHR之后,其他浏览器紧随其后实现了XHR,直接 ...