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 ...
随机推荐
- 51nod1022 石子归并 V2
证明w满足四边形不等式,这里w是m的附属量,形如m[i,j]=opt{m[i,k]+m[k,j]+w[i,j]},此时大多要先证明w满足条件才能进一步证明m满足条件证明m满足四边形不等式证明s[i,j ...
- [Web前端系列之_Firebug_00_序]
[因] 以前一直把Firebug当做参考他人网站界面结构的工具,看看css,js等,没有深挖.这段时间在项目组里主要充当前台工作,也有空,就准备把前端给精通点,firebug作为入手点. [参考资料] ...
- redis接入sentinelPool的配置
package com.netease.mobile.commonUtil; import java.util.ArrayList; import java.util.HashSet; import ...
- PHP学习笔记06——面向对象版图形计算器
index.php 用于显示页面 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "h ...
- HDU 4606 Occupy Cities ★(线段相交+二分+Floyd+最小路径覆盖)
题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果 ...
- HDU 3342 Legal or Not (图是否有环)
题意: 给出n个人的师徒关系,如有 a是b的师傅,b是c的师傅,c是a的师傅,这样则不合法,输出NO,否则输出YES. 思路: 每段关系可以看成一条有向边,从师傅指向徒弟,那么徒弟的徒子徒孙都不可能再 ...
- Linux Shell编程(4): 逻辑运算符、逻辑表达式详解
shell的逻辑运算符 涉及有以下几种类型,因此只要适当选择,可以解决我们很多复杂的判断,达到事半功倍效果. 一.逻辑运算符 逻辑卷标 表示意思 1. 关于档案与目录的侦测逻辑卷标! -f 常用!侦测 ...
- 深入理解require/include的顺序
在大型的Web项目中, include_path是一个模块化设计的根本中的根本(当然,现在也有很多基于autoload的设计, 这个不影响本文的探讨), 但是正是因为include_path, 经常会 ...
- 【英语】Bingo口语笔记(10) - 常见词汇的缩读
- 【英语】Bingo口语笔记(24) - L的发音技巧
舌头往上跑