链接: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.

输入例子:
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

输入

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 题意:在一个n*m的花园,我们想要这个花园变得更加完美,也就是行对称,列对称,但是花园开始可能是不对称,也可能对称,
中间我们可以把中间的花铲走挖一个p*q池子,花园的中心就是池子的中心,来使花园看上去对称,问挖池子的方法有多少个,
而且n,m,p,q都是偶数,p<n q<m 思路:因为我们要使花园看上去对称,我们就去找从0开始最近的不对称的点在哪,行列分别去找,然后我们的池子必须涵盖最近的点,如果我们把
最近的错误点盖住就可以满足了,然后再看最近的点和边界相差多少,行列间隔的距离相乘就是答案,因为我没扩展的时候有x个,我们延伸两个的时候
,又有x个
#include <bits/stdc++.h>
using namespace std;
const int N = 2E3 + ;
string s[N];
int a[N], b[N];
int main()
{
ios::sync_with_stdio(false), cin.tie();
int T;
cin >> T;
while(T--)
{
int n, m;
cin >> n >> m;
for(int i = ; i < n; i++)
{
cin >> s[i];
}
int num1 = , num2 = ;
for(int i = ; i < n/; i++)//这里我们直接用num1作间隔,然后直接匹配字符串是否相等,实际上是匹配了列上的字符是否对称
{
if(s[i] == s[n-i-])
{
num1++;
}
else
{
break;
}
}
for(int i = ; i < m/; i++)//因为行的字符不能直接用字符串相等,所以我们判断下回文
{
int flag = ;
for(int j = ; j < n; j++)
{
if(s[j][i] != s[j][m-i-])
{
flag = ;
break;
}
}
if(flag)
{
num2++;
}
else
{
break;
}
}
if(num1 == || num2 == )
{
cout << << endl;
}
else
{
if(num1* == n) num1--;//如果到了边界减一,我们不能把花园边界挖掉
if(num2* == m) num2--;
cout << num1*num2 << endl;//最终答案
}
} }
主要思路:模拟+贪心

牛客多校第四场 F Beautiful Garden的更多相关文章

  1. 牛客多校第三场 F Planting Trees

    牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...

  2. 牛客多校第四场sequence C (线段树+单调栈)

    牛客多校第四场sequence C (线段树+单调栈) 传送门:https://ac.nowcoder.com/acm/contest/884/C 题意: 求一个$\max {1 \leq l \le ...

  3. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

  4. 牛客多校第五场 F take

    链接:https://www.nowcoder.com/acm/contest/143/F来源:牛客网 题目描述 Kanade has n boxes , the i-th box has p[i] ...

  5. 牛客多校第五场 F take 期望转化成单独事件概率(模板) 树状数组

    链接:https://www.nowcoder.com/acm/contest/143/F来源:牛客网 Kanade has n boxes , the i-th box has p[i] proba ...

  6. 2019牛客多校第四场 I题 后缀自动机_后缀数组_求两个串de公共子串的种类数

    目录 求若干个串的公共子串个数相关变形题 对一个串建后缀自动机,另一个串在上面跑同时计数 广义后缀自动机 后缀数组 其他:POJ 3415 求两个串长度至少为k的公共子串数量 @(牛客多校第四场 I题 ...

  7. 2019牛客多校第四场 A meeting

    链接:https://ac.nowcoder.com/acm/contest/884/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他语言10485 ...

  8. 牛客多校第四场 G Maximum Mode

    链接:https://www.nowcoder.com/acm/contest/142/G来源:牛客网 The mode of an integer sequence is the value tha ...

  9. 2019年牛客多校第四场 B题xor(线段树+线性基交)

    题目链接 传送门 题意 给你\(n\)个基底,求\([l,r]\)内的每个基底是否都能异或出\(x\). 思路 线性基交板子题,但是一直没看懂咋求,先偷一份咖啡鸡板子写篇博客吧~ 线性基交学习博客:传 ...

随机推荐

  1. Vue.js示例:文本编辑器。使用_.debounce()反抖动函数

    Markdown编辑器 https://cn.vuejs.org/v2/examples/index.html 新知识: Underscore.js库 用于弥补标准库,方便了JavaScript的编程 ...

  2. 手机中SN、MEID、IMEI的意思

    SN SN码是Serial Number的缩写,有时也叫SerialNo,也就是产品序列号,产品序列是为了验证“产品的合法身份”而引入的一个概念,它是用来保障用户的正版权益,享受合法服务的:一套正版的 ...

  3. 【洛谷p1031】均分纸牌

    [博客园的第一条随笔,值得纪念一下] 均分纸牌[传送门] 洛谷上的算法标签是 这道题是一道贪心题,过了四遍才过(蒟蒻有点废) 第一遍的时候考虑的非常少,只想到了求出平均数→求差值→从左往右加差值: 这 ...

  4. AS(Android Studio)不停的updating indices

    有同事问我他as进入后updating iindices个不停 就在此处一直刷一直刷,虽然对他项目没什么影响,但总归很是烦人,解决办法如下: 打开File->Invalidate Caches ...

  5. git merge和git rebase的区别

    git merge是用来合并两个分支的.# 将b分支合并到当前分支git merge b git cherry-pick可以选择某一个分支中的一个或几个commit(s)来进行操作.例如,假设我 们有 ...

  6. CF-339D-线段树

    http://codeforces.com/problemset/problem/339/D 给出一个序列.每次更改其中一个值然后询问序列的f(),序列的f()定义为: 每相邻两个元素按位或得到长度减 ...

  7. javascript的倒计时功能中newData().getTime()在iOS下会报错问题解决

    javascript的倒计时功能中newData().getTime()在iOS下会报错问题解决 在做移动端时间转化为时间戳时,遇到了一个问题,安卓手机上访问时,能拿到时间戳,从而正确转换时间,而在i ...

  8. 121. Best Time to Buy and Sell Stock 买卖股票的最佳时机

    网址:https://leetcode.com/problems/Best-Time-to-Buy-and-Sell-Stock/ 第一想法是滑动窗口法,稍微尝试后发现不可行,至少我不会... 而后想 ...

  9. 【LeetCode】矩阵操作

    1. 矩阵旋转 将 n × n 矩阵顺时针旋转 90°. 我的思路是 “ 从外到内一层一层旋转 ”. 一个 n × n 矩阵有 (n + 1) / 2 层,每层有 4 部分,将这 4 部分旋转. 顺时 ...

  10. Linux -- 基于zookeeper的java api(二)

    Linux -- 基于zookeeper的java api(二) 写一个关于基于集群的zookeeper的自定义实现HA 基于客户端和监控器:使用监控的方法查看每个注册过的节点的状态来做出操作. Wa ...