题目链接: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. 从List[Future[T]]到Future[List[T]]

    在课程<Principles Of Reactive Programming>里Week3的一节 "Promises, promises, promises"中,Eri ...

  2. 如何提高多线程程序的cpu利用率

    正如大家所知道的那样,多核多cpu越来越普遍了,而且编写多线程程序也是件很简单的事情.在Windows下面,调用CreateThread函数一次就能够以你想要的函数地址新建一个子线程运行.然后,事情确 ...

  3. Codeforces Round #240 (Div. 2)(A -- D)

    点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...

  4. 在NEXUS中加入自己定义的第三方PROXIES代理库

    就是要等会耐心,更新好之后,才能在PUBLIC库里进行操作. 下图是JBOSS的

  5. [itint5]最大子矩阵和

    http://www.itint5.com/oj/#39 最大子矩阵和,复杂度O(n^3).利用了最大子段和的方法. int maxRectSum(vector<vector<int> ...

  6. QT小技巧(书上没有的)

    1. Layout本身不能控制隐藏和显示,但是可以在外面专门套一个Widget,然后控制这个Widget就可以达到相应的效果了. 2. 空目录居然也存在 if (QDir(""). ...

  7. UnsupportedClassVersionError: Bad version number in...

    在使用eclipse开发servlet可能会出现一个很麻烦事情,版本不一致错误. java.lang.UnsupportedClassVersionError: Bad version number ...

  8. 反汇编(Disassembler) iPhone

    什么是反汇编? 反汇编就是把可执行的二进制文件转为汇编代码,进而可以研究该程序.IDA Pro Adv v5.2 版本起已直接支援 iPhone ARM 代码的静态反汇编分析.IDA Pro Adv ...

  9. Android开发之View动画效果插补器Interpolator

    插补器Interpolator 官网描述:An interpolator defines the rate of change of an animation. This allows the bas ...

  10. Android-xUtils框架介绍(四)

    今天介绍xUtils的最后一个模块——HttpUtils,拖了那么久,终于要结束了.另外,码字不易,如果大家有什么疑问和见解,欢迎大家留言讨论.HttpUtils是解决日常工作过程中繁杂的上传下载文件 ...