(第四场)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\),使得 ...
随机推荐
- linux中安装软件,查看、卸载已安装软件方法
各种主流Linux发行版都采用了某种形式的包管理系统(PMS)来控制软件和库的安装. 软件包存储在服务器上,可以利用本地Linux系统上的PMS工具通过互联网访问.这些服务器称为仓库. 由于Linux ...
- 笔记_JSON
解析 JSON 步骤 如果没有自带 , 就添加 第三方包 (JavaScript编程语言本身自带解析JSON的能力) 一般是要手写 : 实体类 JSON -> 实体类 中间映射 Gson的话 ...
- 在Spark shell中基于Alluxio进行wordcount交互式分析
Spark是一个分布式内存计算框架,可部署在YARN或者MESOS管理的分布式系统中(Fully Distributed),也可以以Pseudo Distributed方式部署在单个机器上面,还可以以 ...
- 解决html5中标签出现的不兼容的问题
HTML5的语义化标签以及属性,可以让开发者非常方便地实现清晰的web页面布局,加上CSS3的效果渲染,快速建立丰富灵活的web页面显得非常简单. HTML5的新标签元素有: <header&g ...
- TOJ 2452 Ultra-QuickSort
描述 In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a se ...
- 诠释JavaScript中的this
文章首发:http://www.cnblogs.com/sprying/p/3573456.html 使用this的几种场合 1. 执行函数时,判断函数是对象方法还是一个单独的函数?单独的函数this ...
- PHP邮件发送
php带有内置的mail() 发送邮件函数,但是较为繁琐:建议上网下载一个PHPMailer:
- 基于 CentOS 搭建 WordPress 个人博客
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 腾讯云提供了开发者实验室帮助用户搭建 WordPress 个人博客,教程内容如下,用户可以点击开发者实验室快速上机完成实验. 准备 LNMP ...
- 如何优雅地进行错误处理(clean code阅读笔记之六)
错误处理是十分必要的,但是如果对错误处理使用不当则会让代码变得十分臃肿,让阅读者看不清代码的逻辑,更严重的是,这也会让程序变得十分脆弱.本文中将列出一些使用错误处理的技巧,帮助你写出既简洁又健壮的代码 ...
- sql 行列转换
create table #test1(id int,name varchar(20), Q1 int, Q2 int, Q3 int, Q4 int) insert into #test1 valu ...