HDU-4618 Palindrome Sub-Array 暴力枚举
题目链接: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 暴力枚举的更多相关文章
- HDU 4618 Palindrome Sub-Array 暴力
Palindrome Sub-Array 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4618 Description A palindrome s ...
- hdu 1172 猜数字(暴力枚举)
题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...
- hdu 4445 Crazy Tank (暴力枚举)
Crazy Tank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 4770 Lights Against Dudely 暴力枚举+dfs
又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...
- 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 ...
- hdu 4618 Palindrome Sub-Array
http://acm.hdu.edu.cn/showproblem.php?pid=4618 直接DP+记忆化 虽然时间复杂度看起来是300^4 但实际执行起来要远远小于这个值 所有可以水过 代码: ...
- HDU 4930 Fighting the Landlords(暴力枚举+模拟)
HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...
- HDU 4618 Palindrome Sub-Array(DP)
题目链接 我还是图样啊....比赛的时候没敢暴力去搜... #include <cstdio> #include <cstdlib> #include <cstring& ...
- HDU 4431 Mahjong (DFS,暴力枚举,剪枝)
题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ...
- HDU 1270 小希的数表 (暴力枚举+数学)
题意:... 析:我们可以知道,a1+a2=b1,那么我们可以枚举a1,那么a2就有了,并且a1+a3=b2,所以a3就有了,我们再从把里面的剩下的数两两相加,并从b数组中去掉, 那么剩下的最小的就是 ...
随机推荐
- zoj 2387
额 一个贪心 好难想到 ...... #include <cstring> #include <cstdio> #include <algorithm> #in ...
- ural 1066 uva 1555
好吧 竟然因为编译器的问题不过 到底有什么区别 ???? 可以推出公式Hi = (i-1)H2 +(i-1)(i-2)-(i-2)*H1 因为所有的Hi都要大于零 Hn要最小 即存在Hi=0 ...
- RASP 完爆 WAF 的5大理由!
Web 应用防火墙(WAF)已经成为常见 Web 应用普遍采用的安全防护工具,即便如此,WAF 提供的保护方案仍旧存在诸多不足,笔者认为称 WAF 为好的安全监控工具更为恰当.幸运的是,应用安全保护技 ...
- pythn BeautifulSoup
http://rsj217.diandian.com/post/2012-11-01/40041235132 Beautiful Soup 是用 Python 写的一个 HTML/XML 的解析器,它 ...
- How To Monitor Remote Linux Host using Nagios 3.0
In the previous post Nagios 3.0 Jumpstart guide , I explained the overview, installation and configu ...
- 【leetcode】Palindrome Number (easy)
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...
- Maven for Myeclipse的一个常见错误 Project configuration is not up-to-date with pom.xml
使用Myeclipse开发Maven项目时,经常会发现一个错误提示: Description Resource Path Location Type Project configuration is ...
- overrides final method getUnknownFields.()Lcom/google/protobuf/UnknownFieldSet 错误解决
使用java代码连接hbase服务器报错: java.lang.VerifyError: class org.apache.hadoop.hdfs.protocol.proto.ClientName ...
- 图模型的统计推断 inference in graphical models(马尔科夫链的推断)
有关因子图(factor graphs)以及其在sum product 算法,max-algorithm中的应用,将在一下篇博客中分享. 谢谢您的关注,欢迎提出意见问题.
- poj 3126 Prime Path( bfs + 素数)
题目:http://poj.org/problem?id=3126 题意:给定两个四位数,求从前一个数变到后一个数最少需要几步,改变的原则是每次只能改变某一位上的一个数,而且每次改变得到的必须是一个素 ...