Palindrome Sub-Array

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 173    Accepted Submission(s): 80

Problem Description
  A palindrome sequence is a sequence which is as same as its reversed order. For example, 1 2 3 2 1 is a palindrome sequence, but 1 2 3 2 2 is not. Given a 2-D array of N rows and M columns, your task is to find a maximum sub-array of P rows and P columns, of which each row and each column is a palindrome sequence.
 
Input
  The first line of input contains only one integer, T, the number of test cases. Following T blocks, each block describe one test case.
  There is two integers N, M (1<=N, M<=300) separated by one white space in the first line of each block, representing the size of the 2-D array.
  Then N lines follow, each line contains M integers separated by white spaces, representing the elements of the 2-D array. All the elements in the 2-D array will be larger than 0 and no more than 31415926.
 
Output
  For each test case, output P only, the size of the maximum sub-array that you need to find.
 
Sample Input
1
5 10
1 2 3 3 2 4 5 6 7 8
1 2 3 3 2 4 5 6 7 8
1 2 3 3 2 4 5 6 7 8
1 2 3 3 2 4 5 6 7 8
1 2 3 9 10 4 5 6 7 8
 
Sample Output
4
 
Source
 
Recommend
zhuyuanchen520
 

很简单的题目

那个时候想复杂了

只要暴力过去就行了。

枚举中心点,然后扩展。

偶数和奇数行分开算

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#include <math.h>
using namespace std;
const int MAXN = ;
int a[MAXN][MAXN];
int n,m;
int calc(int x,int y,int tt)//tt=0奇数,tt=1偶数
{
int ans;
int x1,y1,x2,y2;//两个角坐标
if(tt == )
{
ans = ;
x1 = x; y1 = y;
x2 = x; y2 = y;
}
else
{
if(x+>=n || y+>=m)return ;
ans = ;
x1 = x;y1 = y;
x2 = x+;y2 = y+;
if(a[x1][y1]!=a[x2][y1]||a[x1][y1]!=a[x2][y1])
return ;
if(a[x2][y2]!=a[x2][y1]||a[x2][y2]!=a[x2][y1])
return ;
}
while()
{
x1--;y1--;
x2++;y2++;
if(x1 < || y1 < || x2 >= n || y2 >= m)
return ans;
for(int i = x1;i <= x2;i++)
if(a[i][y1]!=a[x2-i+x1][y1])
return ans;
for(int i = x1;i <= x2;i++)
if(a[i][y2]!=a[x2-i+x1][y2])
return ans;
for(int i = y1;i <= y2;i++)
if(a[x1][i]!=a[x1][y2-i+y1])
return ans;
for(int i = y1;i <= y2;i++)
if(a[x2][i]!=a[x2][y2-i+y1])
return ans;
for(int i = x1;i <= x2;i++)
if(a[i][y1]!=a[i][y2])
return ans;
for(int i = y1;i <= y2;i++)
if(a[x1][i]!=a[x2][i])
return ans;
ans += ;
}
return ans;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T; scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i = ; i < n;i++)
for(int j = ;j < m;j++)
scanf("%d",&a[i][j]);
int ans = ;
for(int i = ;i < n;i++)
for(int j = ;j < m;j++)
{
ans = max(ans,calc(i,j,));
ans = max(ans,calc(i,j,));
}
printf("%d\n",ans); }
return ; return ;
}

最新文章

  1. JS案例之2——cycle元素轮播
  2. oracle中trim,ltrim,rtrim函数用法
  3. Android手动签名
  4. 理解MapReduce哲学
  5. Simulate android behaviors on win32
  6. java List交集 并集 差集 去重复并集
  7. html doctype 作用
  8. 仿糯米弹框效果demo
  9. ARC 工作原理
  10. redhat linux使用Centos yum源
  11. php 执行效率
  12. windows中启动和终止nginx的两个批处理
  13. 10个常见的JavaScript BUG
  14. Python学习之旅(三十五)
  15. Jmeter(八)-发送JDBC请求
  16. CodeBlocks 17.12 工程如何引用其他文件夹的头文件和源程序
  17. Lua------------------改善Unity编辑器对Lua文件的支持
  18. Mybatis数据库连接报错:对实体 &quot;characterEncoding&quot; 的引用必须以 &#39;;&#39; 分隔符结尾
  19. PHP中的密码加密的解决方案
  20. matplot模块中的pylab

热门文章

  1. 函数lock_rec_has_expl
  2. android 安装 出现Android Native Development Tools不能安装
  3. java中进程与线程的三种实现方式
  4. JSP:include的flush属性的作用
  5. UVa 10106 Product
  6. UVa 11825 (状压DP) Hackers&#39; Crackdown
  7. QCon 2015 阅读笔记 - 团队建设
  8. 20160122.CCPP详解体系(0001天)
  9. Google Code Pretiffy 代码 着色 高亮 开源 javascript(JS)库
  10. 几种Menu和几种对话框