1057: Beautiful Garden

Time Limit: 5 Sec  Memory Limit: 128 MB
Submit: 25  Solved: 12
[Submit][Status][Web
Board
]

Description

There's a beautiful garden whose size is  n  × m  in Edward's house. The garden can be 
partitioned  into  n  ×  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, Edward thinks the garden is not beautiful enough. Edward wants 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  × 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.
Edward wants to know how many different pairs of (p, q) he can choose.

Input

There are multiple test cases. The first line of input contains an integer  T  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), 
indicating  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.

Output

For  each  test  case,  output  an  integer  indicating  the  number  of  choices  to  build  the 
water pool.

Sample Input

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

Sample Output

6
0
3

HINT

For the first sample, you have following six choices (blank rectangle means the water

pool): 

很蛋疼的一道题,需要仔细调试。还有具体怎么计算呢?若下标均从0开始,显然上面的可抹除部分有2行(1与2),3列(1,2,3),那么答案就是2*3,其他情况均用这种办法求解。

代码:

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
char pos[2009][2009];
int hang,lie;
inline bool huiwen(const char s[])
{
int len=strlen(s);
int i;
for (i=0; i<len/2;i++)
{
if(s[i]!=s[len-1-i])
return false;
}
return true;
}
int main(void)
{
int t,i,j,l,r;
scanf("%d",&t);
while (t--)
{
memset(pos,0,sizeof(pos));
scanf("%d%d",&hang,&lie);
for (i=0; i<hang; i++)
{
scanf("%s",pos[i]);
}
l=hang/2-1;
r=lie/2-1;
for (i=0; i<hang/2; i++)//判断上下是否相同且回文
{
if( (strcmp(pos[i],pos[hang-1-i])!=0) || (!huiwen(pos[i])) || (!huiwen(pos[hang])))
{
l=i;
break;
}
}
bool ok=0;
for (i=0; i<lie/2; i++)//列相同判断
{
for (j=l; j<=hang-1-l; j++)
{
if(pos[j][i]!=pos[j][lie-1-i])
{
r=i;
ok=1;
break;
}
}
if(ok)
break;
}
for (i=0; i<r; i++)//列回文判断(放到上面的for里十分麻烦,独立出来判断)
{
for (j=l; j<hang/2; j++)
{
if(pos[j][i]!=pos[hang-1-j][i])
{
r=min(r,i);//肯定要取小的那列
ok=1;
break;
}
}
if(ok)
break;
}
printf("%d\n",l*r);//输出答案
}
return 0;
}

ACM程序设计选修课——1057: Beautiful Garden(模拟+耐心调试)的更多相关文章

  1. ACM程序设计选修课——1044: (ds:队列)打印队列(queue模拟)

    问题 A: (ds:队列)打印队列 时间限制: 1 Sec  内存限制: 128 MB 提交: 25  解决: 4 [提交][状态][讨论版] 题目描述 网络工程实验室只有一台打印机,它承担了非常繁重 ...

  2. ACM程序设计选修课——1030: Hungar的时尚球场(水题+耐心)

    1030: Hungar的时尚球场 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 14  Solved: 8 [Submit][Status][Web ...

  3. ACM程序设计选修课——1076汇编语言(重定向+模拟)

    1076: 汇编语言 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 34  Solved: 4 [Submit][Status][Web Board] ...

  4. 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛 G 旋转矩阵 【模拟】

    链接:https://www.nowcoder.com/acm/contest/90/G 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  5. ACM程序设计选修课——Problem D: (ds:树)合并果子(最优二叉树赫夫曼算法)

    Problem D: (ds:树)合并果子 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 80  Solved: 4 [Submit][Status][ ...

  6. ACM程序设计选修课——1041: XX's easy problem(神烦的多次字符串重定向处理)

    1041: XX's easy problem Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 41  Solved: 7 [Submit][Statu ...

  7. ACM程序设计选修课——Problem E:(ds:图)公路村村通(Prim)

    问题 E: (ds:图)公路村村通 时间限制: 1 Sec  内存限制: 128 MB 提交: 9  解决: 5 题目描述 现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本, ...

  8. ACM程序设计选修课——Problem F:(ds:图)旅游规划(优先队列+SPFA)

    问题 F: (ds:图)旅游规划 时间限制: 1 Sec  内存限制: 128 MB 提交: 14  解决: 4 题目描述 有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路 ...

  9. ACM程序设计选修课——Problem E:(ds:图)公路村村通(优先队列或sort+克鲁斯卡尔+并查集优化)

    畅通工程 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

随机推荐

  1. Android(java)学习笔记131:关于构造代码块,构造函数的一道面试题(华为面试题)

    1. 代码实例: package text; public class TestStaticCon { public static int a = 0; static { a = 10; System ...

  2. 10分钟搞懂toString和valueOf函数(详细版)

    首先要说明的是这两种方法是toPrimitive抽象操作里会经常用到的. 默认情况下,执行这个抽象操作时会先执行valueOf方法,如果返回的不是原始值,会继续执行toString方法,如果返回的还不 ...

  3. FFT快速傅里叶变化

    纪念人生第一次FFT 前排感谢iamzky,讲解非常详细 #include<iostream> #include<cstdio> #include<cmath> u ...

  4. k8s资源指标API及metrics-server资源监控

    简述: 在k8s早期版本中,对资源的监控使用的是heapster的资源监控工具. 但是从 Kubernetes 1.8 开始,Kubernetes 通过 Metrics API 获取资源使用指标,例如 ...

  5. MYSQL导入数据:Table XXX doesn't exist的解决

    数据表为Innodb引擎 data文件夹中存在数据表的frm文件,但在phpmyadmin中看不到这些表,于是采用导入sql文件的方式进行恢复 1.直接导入原数据表的sql文件,原frm文件不删除 出 ...

  6. paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之enhanced coding styles

    1.ANSI style 的代码比较紧凑. 下面规范推荐,比较好. 下面是带有parameter的module header的完整规范 一般1bit ,大家都是wire signal1 = gen_s ...

  7. php 计算当天凌晨时间戳 以及获取其他常用时间戳

    php 计算当日凌晨时间戳 以及获取其他常用时间戳(持续补充中...) 获取当天凌晨时间戳: echo strtotime(date('Y-m-d')); 以下再列举一些获取其他常用时间戳的方法 获取 ...

  8. Linux安装配置***客户端

    1.创建root用户 sudo passwd root su root 2.安装shadowsocks sudo apt-get install python-pip sudo pip install ...

  9. java/jsp执行sql语句的方式

    首先给出sql驱动包 引入sql包 import java.sql.*;//java <%@ page import="java.sql.*"%>//jsp 连接mys ...

  10. 请问batch_normalization做了normalization后为什么要变回来?

    请问batch_normalization做了normalization后为什么要变回来? 请问batch_normalization做了normalization后为什么要变回来? - 莫驚蟄的回答 ...