(第四场)F Beautiful Garden
题目:
F Beautiful Garden
题目描述
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的更多相关文章
- 牛客多校第四场 F Beautiful Garden
链接:https://www.nowcoder.com/acm/contest/142/F来源:牛客网 题目描述 There's a beautiful garden whose size is n ...
- 牛客网暑期ACM多校训练营(第四场) F Beautiful Garden
链接: https://www.nowcoder.com/acm/contest/142/F 题意: n x m的矩形,选个p x q的矩形去掉,两个矩形中⼼重合,去掉后的矩形上下左右对称 求(p, ...
- 2018年牛客多校寒假 第四场 F (call to your teacher) (图的连通性)
题目链接 传送门:https://ac.nowcoder.com/acm/contest/76/F 思路: 题目的意思就是判断图的连通性可以用可达性矩阵来求,至于图的存储可以用邻接矩阵来储存,求出来可 ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- bnu 34982 Beautiful Garden(暴力)
题目链接:bnu 34982 Beautiful Garden 题目大意:给定一个长度为n的序列,问说最少移动多少点,使得序列成等差序列,点的位置能够为小数. 解题思路:算是纯暴力吧.枚举等差的起始和 ...
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
- NOI.AC NOIP模拟赛 第四场 补记
NOI.AC NOIP模拟赛 第四场 补记 子图 题目大意: 一张\(n(n\le5\times10^5)\)个点,\(m(m\le5\times10^5)\)条边的无向图.删去第\(i\)条边需要\ ...
- CTF-i春秋网鼎杯第四场部分writeup
CTF-i春秋网鼎杯第四场部分writeup 因为我们组的比赛是在第四场,所以前两次都是群里扔过来几道题然后做,也不知道什么原因第三场的题目没人发,所以就没做,昨天打了第四场,简直是被虐着打. she ...
- 牛客网NOIP赛前集训营-提高组(第四场)B区间
牛客网NOIP赛前集训营-提高组(第四场)B区间 题目描述 给出一个序列$ a_1 \dots a_n$. 定义一个区间 \([l,r]\) 是好的,当且仅当这个区间中存在一个 \(i\),使得 ...
随机推荐
- IT职场?未来?
转自 IT职场?未来? 不能否认,有些技术大牛,生活也过的不错,工资不少挣.但是这种人,本来就不多啊,很少啊.这些人一般都是小时候就搞程序的,你觉得你半路出家,能变成这种超级牛人么?? 而且这些牛人, ...
- 安装clouderamaner时出现Failed to detect distribution错误(在ubuntu14.04版本里)
不多说,直接上干货! 在安装过程中,本来我的ubuntu系统都是14.04的. 问题详情 问题查看 解决办法 然后,再次执行安装即可. 欢迎大家,加入我的微信公众号:大数据躺过的坑 人 ...
- CSS像素、设备独立像素、设备像素之间关系
CSS像素.设备独立像素.设备像素,三者联系紧密又有很大的区别,而我们主要是在做移动端开发的时候需要更多地用到这些概念,那他们分别是指什么呢? 概念 CSS像素(CSS Pixel):适用于web编程 ...
- 很有用的PHP笔试题系列二
1.如何用php的环境变量得到一个网页地址的内容?ip地址又要怎样得到? Gethostbyname() echo $_SERVER ["PHP_SELF"];echo $_SER ...
- C# 实现OrderBy按多个字段排序
//倒序 list.OrderByDescending(i => i.a).ThenByDescending(i => i.b); //顺序 list.OrderBy(i => i. ...
- Xcode10 闪退问题
最新更新了iOS12,mac10.13.6,xcode10之后,打开之前的项目,只要进行import,xcode就会闪退.那么就来看一下解决方案: Xcode10 新增了一个构建系统起名“New Bu ...
- 自己用到的vim常用命令
一.前言 这里整理的是我在实习期间用到的常用vim命令,特记录如下,以免忘记. 二.vim常用命令 1.vim中的光标移动 shift+6(^):跳到行首(第一个非空格字符)(注:在shell跳到行首 ...
- 集合异常之List接口
List接口介绍:是Collection接口中的子类, 特点: l 它是一个元素存取有序的集合.例如,存元素的顺序是11.22.33.那么集合中,元素的存储就是按照11.22.33的顺序完成的).( ...
- Ruby(或cmd中)输入命令行编译sass
Ruby(或cmd中)输入命令行编译sass步骤如下: 举例: 1.在F盘中新建一个总文件夹,比如test文件夹,其中在该文件夹下面建立html.images.js.sass等文件夹. 2.在sass ...
- 五校联考模拟赛Day2T2矩阵(容斥原理)
题意 $n * m$的网格,对其进行黑白染色,问每一行每一列至少有一个黑格子的方案数. Sol 考场上只会$n^3$的dp,还和指数级枚举一个分qwq 设$f[i][j]$表示到了第$i$行,已经有$ ...