HDU 4618 Palindrome Sub-Array (2013多校2 1008 暴力)
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
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.
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
很简单的题目
那个时候想复杂了
只要暴力过去就行了。
枚举中心点,然后扩展。
偶数和奇数行分开算
#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 ;
}
HDU 4618 Palindrome Sub-Array (2013多校2 1008 暴力)的更多相关文章
- HDU 4632 Palindrome subsequence (2013多校4 1001 DP)
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...
- HDU 4691 Front compression (2013多校9 1006题 后缀数组)
Front compression Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Othe ...
- HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)
Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- HDU 4671 Backup Plan (2013多校7 1006题 构造)
Backup Plan Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)
Building Fence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)To ...
- HDU 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)
Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4618 Palindrome Sub-Array 暴力
Palindrome Sub-Array 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4618 Description A palindrome s ...
- hdu 4618 Palindrome Sub-Array
http://acm.hdu.edu.cn/showproblem.php?pid=4618 直接DP+记忆化 虽然时间复杂度看起来是300^4 但实际执行起来要远远小于这个值 所有可以水过 代码: ...
- HDU 4658 Integer Partition (2013多校6 1004题)
Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- uses-permission权限汇总
问登记属性 android.permission.ACCESS_CHECKIN_PROPERTIES ,读取或写入登记check-in数据库属性表的权限 获取错略位置 android.permis ...
- Balsamiq Mockups简单介绍(UI草图绘制工具)
什么是Balsamiq Mockups Balsamiq Mockups出自加利福尼亚州的Balsamiq工作室,创始人Peldi在2008年6月推出了这款手绘风格的产品原型设计工具,并广受好评.2年 ...
- C实现类封装、继承、多态
1. 概述 C语言是一种面向过程的程序设计语言,而C++是在C语言基础上衍生来了的面向对象的语言,实际上,很多C++实现的底层是用C语言实现的,如在Visual C++中的Interface其实就是 ...
- [Web前端系列之_Firebug_00_序]
[因] 以前一直把Firebug当做参考他人网站界面结构的工具,看看css,js等,没有深挖.这段时间在项目组里主要充当前台工作,也有空,就准备把前端给精通点,firebug作为入手点. [参考资料] ...
- 使用phantomjs生成网站快照
http://phantomjs.org/ 昨天(2013/08/12)在代码区看到一个生成站点快照的代码,看了半天才发现,作者仅仅贴出来业务代码,最核心的生成快照图片的代码反而没有给出来. 以前记得 ...
- Heritrix源码分析(七) Heritrix总体介绍(转)
本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.iteye.com/blog/642794 本博客已迁移到本人独立博客: http://www.yun ...
- 计算机网络——TCP与UDP协议详解
根据应用程序的不同需求,运输层需要两种不同的运输协议,即面向连接的TCP和无连接的UDP. TCP:传输控制协议 TCP特点: 1)TCP是面向连接的运输层协议.所以,应用程序在使用TCP协议之前,必 ...
- K2 Blackpearl开发技术要点(Part1)
转:http://www.cnblogs.com/dannyli/archive/2012/09/14/2685260.html K2 Blackpearl开发技术要点(Part1) 预知后事如何,请 ...
- Undefined symbols for architecture armv7
xcode编译过程中出现如下问题Undefined symbols for architecture armv7:... ld: symbol(s) not found for architectur ...
- Android通过代码获取View
View view = LayoutInflater.from(mContext).inflate(R.layout.song_item_adapter, null); LayoutInflater ...