题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4618

  直接暴力枚举中心点,在中间如果求不出最大值直接跳过优化下。。。

 //STATUS:C++_AC_31MS_800KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=,M=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int w[N][N];
int T,n,m,ans; int slove(int x,int y)
{
int i,j,c,ok,ret=;
for(c=ok=;x-c>=&&x+c<n && y-c>=&&y+c<m;c++){
for(i=;i<=c;i++){
if(w[x-c+i][y-c]!=w[x-c+i][y+c]
|| w[x-c][y-c+i]!=w[x+c][y-c+i]
|| w[x+i][y-c]!=w[x-i][y-c]
|| w[x+i][y+c]!=w[x-i][y+c]
|| w[x-c][y-i]!=w[x-c][y+i]
|| w[x+c][y-i]!=w[x+c][y+i]){ok=;break;}
}
if(!ok)break;
}
ret=(c-)<<|;
for(c=ok=;x-c+>=&&x+c<n && y-c+>=&&y+c<m;c++){
for(i=;i<=c;i++){
if(w[x-c+i+][y-c+]!=w[x-c+i+][y+c]
|| w[x-c+][y-c+i+]!=w[x+c][y-c+i+]
|| w[x+i][y-c+]!=w[x-i+][y-c+]
|| w[x+i][y+c]!=w[x-i+][y+c]
|| w[x-c+][y-i+]!=w[x-c+][y+i]
|| w[x+c][y-i+]!=w[x+c][y+i]){ok=;break;}
}
if(!ok)break;
}
return Max(ret,(c-)<<);
} int main()
{
// freopen("in.txt","r",stdin);
int i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(i=;i<n;i++){
for(j=;j<m;j++){
scanf("%d",&w[i][j]);
}
} ans=;
for(i=;i<n;i++){
if( ((i+)<<)<=ans || (((n-i-)<<)|)<=ans)continue;
for(j=;j<m;j++){
if( ((j+)<<)<=ans || (((m-j-)<<)|)<=ans)continue;
ans=Max(ans,slove(i,j));
}
} printf("%d\n",ans);
}
return ;
}

HDU-4618 Palindrome Sub-Array 暴力枚举的更多相关文章

  1. HDU 4618 Palindrome Sub-Array 暴力

    Palindrome Sub-Array 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4618 Description A palindrome s ...

  2. hdu 1172 猜数字(暴力枚举)

    题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...

  3. hdu 4445 Crazy Tank (暴力枚举)

    Crazy Tank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. HDU 4770 Lights Against Dudely 暴力枚举+dfs

    又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...

  5. HDU 4618 Palindrome Sub-Array (2013多校2 1008 暴力)

    Palindrome Sub-Array Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Oth ...

  6. hdu 4618 Palindrome Sub-Array

    http://acm.hdu.edu.cn/showproblem.php?pid=4618 直接DP+记忆化 虽然时间复杂度看起来是300^4 但实际执行起来要远远小于这个值 所有可以水过 代码: ...

  7. HDU 4930 Fighting the Landlords(暴力枚举+模拟)

    HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...

  8. HDU 4618 Palindrome Sub-Array(DP)

    题目链接 我还是图样啊....比赛的时候没敢暴力去搜... #include <cstdio> #include <cstdlib> #include <cstring& ...

  9. HDU 4431 Mahjong (DFS,暴力枚举,剪枝)

    题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ...

  10. HDU 1270 小希的数表 (暴力枚举+数学)

    题意:... 析:我们可以知道,a1+a2=b1,那么我们可以枚举a1,那么a2就有了,并且a1+a3=b2,所以a3就有了,我们再从把里面的剩下的数两两相加,并从b数组中去掉, 那么剩下的最小的就是 ...

随机推荐

  1. 使用 Spark 进行微服务的实时性能分析

    [编者按]当开发者从微服务架构获得敏捷时,观测整个系统的运行情况成为最大的痛点.在本文,IBM Research 展示了如何用 Spark 对微服务性能进行分析和统计,由 OneAPM 工程师编译整理 ...

  2. strip_tags() 函数剥去 HTML、XML 以及 PHP 的标签

    定义和用法 strip_tags() 函数剥去 HTML.XML 以及 PHP 的标签. 语法 strip_tags(string,allow) 参数 描述 string 必需.规定要检查的字符串. ...

  3. PYTHON设计模式,创建型之工厂方法模式

    我感觉和上一个差不多,可能不要动最要的地方吧... #!/usr/bin/evn python #coding:utf8 class Pizza(object): def prepare(self, ...

  4. 李洪强iOS开发之XMPP

      XMPP历史 这个xmpp框架在2008年开始,不过是一个简单地RFC实现.提供一个最小的代理去接受三种xmpp的基本类型presence.message.iq.因为framwork只提供了最小的 ...

  5. 李洪强漫谈iOS开发[C语言-011] - C语言标示符

    /** *    标示符 2016年 7月 14日 01 低级语言和高级语言的最大不同: 低级语言用的是机器指令 高级语言就是写一些人可以看得懂的代码-汇编语言 标示符 就是名字 命名规则: 1) 只 ...

  6. HDU1875——畅通工程再续(最小生成树:Kruskal算法)

    畅通工程再续 Description相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问题当 ...

  7. 启用了不安全的HTTP方法

    安全风险:       可能会在Web 服务器上上载.修改或删除Web 页面.脚本和文件. 可能原因:       Web 服务器或应用程序服务器是以不安全的方式配置的. 修订建议:       如果 ...

  8. Flex Array内置排序方法的使用

    在Array类中,提供内置的排序方法.排序是在软件开发的过程中,经常遇到的问题.通过这些内置的方法,可以快速轻便的进行排序操作. Array类提供sort方法对Array实例进行排序.sort方法没有 ...

  9. Android开发之ContentProvider的简单使用

    ContentProvider,内容提供者 官网结构图: 作为四大组件之一的ContentProvider,主要是用于应用间数据共享使用的. ContentProvider把应用的数据封装起来,然后提 ...

  10. node安装插件方法

    node安装插件方法有几种,这里列出常用的两种方法: 方法1: 进入要安装插件的目录,直接用 npm 软件安装包安装,如(安装express): cd /project npm install -g ...