题目:

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. ButtonAddListener监听按钮点击事件

    ButtonAddListener监听按钮点击事件 using UnityEngine; using System.Collections; using UnityEngine.UI; using U ...

  2. centOS使用.htaccess

    首先,你要保证你的Aapche已经开启了.htaccess 可以参考:http://www.veryhuo.com/a/view/21259.html 以下是.htaccess文件中的内容: Rewr ...

  3. Windows与Unix思想

    Unix与Windows的思想 Unix中的哲学是"一切皆文件",这里的一切皆文件是一个广泛的概念,有一些特殊的设备文件,在/dev目录下 物理设备在Unix中就对应一个特殊的设备 ...

  4. 深入理解JavaScript系列(20):《你真懂JavaScript吗?》答案详解

    介绍 昨天发的<大叔手记(19):你真懂JavaScript吗?>里面的5个题目,有很多回答,发现强人还是很多的,很多人都全部答对了. 今天我们来对这5个题目详细分析一下,希望对大家有所帮 ...

  5. 冒泡排序——Java实现

    一.排序思想 比较相邻的元素.如果第一个比第二个大,就交换他们两个. 对每一对相邻元素做同样的工作,从开始第一对到结尾的最后一对.在这一点,最后的元素应该会是最大的数. 针对所有的元素重复以上的步骤, ...

  6. 2、Spring之AOP

    AOP术语 通知:定义了切面是什么以及何时使用.除了要描述页面要完成的工作,通知还解决了何时执行这个工作的问题. 连接点:连接点是一个物理的存在.这个点可以是调用方法时.抛出异常时.甚至是修改一个字段 ...

  7. html-其他常见标签的使用

    b:加粗 s:删除线 u:下划线 i:斜体 per:原样输出 sup:上标 sub:下标 p:段落标签 比br多一行 (CSS) div:自动换行 span:在一行显示 完整代码: <html& ...

  8. ajax异步请求/同源策略/跨域传值

    基本概念 Ajax 全称是异步的 JavaScript 和 XML . 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重新加载整个网页的情况下,对网页的某部分进 ...

  9. Web前端面试指导(七):入职后的建议

    7.2 关于合同 签合同的时候,看公司要求,有些是3年,有些是5年,不要怕,签了就是了,真到想走的时候,提前说一声,随时可以走,不存在什么违约赔偿. 注意:你的合同和薪资都是属于保密的,不能让公司其他 ...

  10. 30 Excellent WordPress Video Tutorials

    http://sixrevisions.com/wordpress/30-excellent-wordpress-video-tutorials/ WordPress是一种使用PHP语言开发的博客平台 ...