HDU 4618 Palindrome Sub-Array (2013多校2 1008 暴力)
2024-10-19 03:27:09
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.
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
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 ;
}
最新文章
- JS案例之2——cycle元素轮播
- oracle中trim,ltrim,rtrim函数用法
- Android手动签名
- 理解MapReduce哲学
- Simulate android behaviors on win32
- java List交集 并集 差集 去重复并集
- html doctype 作用
- 仿糯米弹框效果demo
- ARC 工作原理
- redhat linux使用Centos yum源
- php 执行效率
- windows中启动和终止nginx的两个批处理
- 10个常见的JavaScript BUG
- Python学习之旅(三十五)
- Jmeter(八)-发送JDBC请求
- CodeBlocks 17.12 工程如何引用其他文件夹的头文件和源程序
- Lua------------------改善Unity编辑器对Lua文件的支持
- Mybatis数据库连接报错:对实体 ";characterEncoding"; 的引用必须以 &#39;;&#39; 分隔符结尾
- PHP中的密码加密的解决方案
- matplot模块中的pylab
热门文章
- 函数lock_rec_has_expl
- android 安装 出现Android Native Development Tools不能安装
- java中进程与线程的三种实现方式
- JSP:include的flush属性的作用
- UVa 10106 Product
- UVa 11825 (状压DP) Hackers&#39; Crackdown
- QCon 2015 阅读笔记 - 团队建设
- 20160122.CCPP详解体系(0001天)
- Google Code Pretiffy 代码 着色 高亮 开源 javascript(JS)库
- 几种Menu和几种对话框