HDU4495 Rectangle
求组成的等腰三角形面积最大值。
对此题的总结:暴力出奇迹
组成的三角形放置方式一共只有4种,用ans表示目前已知的最长三角形的边长,从上到下,从左到右枚举顶点,再枚举边长,一个重要剪枝是枚举边长l时先判断l = ans时的边能不能对称。
最终暴力只要200多ms,而时间限制为10s
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
using namespace std;
typedef long long LL;
const int N = , INF = 0x3F3F3F3F;
#define MS(a, num) memset(a, num, sizeof(a))
#define PB(A) push_back(A)
#define FOR(i, n) for(int i = 0; i < n; i++)
char g[N][N];
int n, m;
int ans = ; bool judge(int x1, int y1, int x2, int y2){
while(y1 < y2){
if(g[x1][y1] != g[x2][y2]){
return false;
}
x1--;
x2++;
y1++;
y2--;
}
return true;
} bool judge2(int x1, int y1, int x2, int y2){
while(x1 < x2){
if(g[x1][y1] != g[x2][y2]){
return false;
}
x1++;
x2--;
y1++;
y2--;
}
return true;
} void solve1(){
for(int i = ;i < n; i++){
for(int j = ; j < m; j++){
if(i + ans - < n && j + ans - < m){ if(!judge(i + ans - , j, i, j + ans - )){
continue;
}
for(int l = ; i + l - < n && j + l - < m; l++){
if(!judge(i + l - , j, i, j + l - )){
break;
}
ans = max(ans , l);
}
}
}
}
} void solve2(){
for(int i = ;i < n; i++){
for(int j = ; j < m; j++){ if(j - ans + >= && i + ans - < n){ if(!judge2(i, j - ans + , i + ans - , j )){
continue;
} for(int l =; j - l + >= && i + l - < n; l++){
if(!judge2(i, j - l + , i + l - , j )){
break;
}
ans = max(ans , l);
}
}
}
}
} void solve3(){
for(int i = ;i < n; i++){
for(int j = ; j < m; j++){
if(i - ans + >= && j + ans - < m){ if(!judge2(i - ans + , j, i , j + ans - )){
continue;
}
for(int l = ; i - l + >= && j + l - < m; l++){
if(!judge2(i - l + , j, i , j + l - )){
break;
}
ans = max(ans , l);
}
}
}
}
} void solve4(){
for(int i = ;i < n; i++){
for(int j = ; j < m; j++){
if(j - ans + >= && i - ans + >= ){ if(!judge(i, j - ans + , i - ans + , j)){
continue;
}
for(int l = ; j - l + >= && i - l + >= ; l++){
if(!judge(i, j - l + , i - l + , j)){
break;
}
ans = max(ans , l);
}
}
}
}
} int main(){
int t;
cin>>t;
while(t--){
cin>>n>>m;
for(int i= ; i< n; i++){
scanf("%s", g[i]);
}
ans = ;
int mini = min(n ,m);
solve1();
if(ans != mini){
solve2();
}
if(ans != mini){
solve2();
} if(ans != mini){
solve3();
}
if(ans != mini){
solve4();
} cout<<ans * (ans + )/<<'\n';
} return ;
}
HDU4495 Rectangle的更多相关文章
- [LeetCode] Perfect Rectangle 完美矩形
Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...
- [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...
- [LeetCode] Smallest Rectangle Enclosing Black Pixels 包含黑像素的最小矩阵
An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...
- [LeetCode] Rectangle Area 矩形面积
Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...
- [LeetCode] Maximal Rectangle 最大矩形
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...
- [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- Maximal Rectangle
很不好想的一道题,参考:http://blog.csdn.net/doc_sgl/article/details/11832965 分为两步:把原矩阵转为直方图,再用largest rectangle ...
- 85. Maximal Rectangle
85. Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle c ...
- poj 2559 Largest Rectangle in a Histogram - 单调栈
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19782 ...
随机推荐
- 4.1---二叉树是否平衡(CC150)
//也就是把高度在递归过程中给一并算了.public class Balance { public static boolean checkBalance(TreeNode root, int[] d ...
- Quartz表达式详解(转载)
1. CronTrigger时间格式配置说明 CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 允许填写的值 允许的通配符 ...
- phpcms中action值的含义
action值的含义:lists 内容数据(文章?)列表relation 内容相关文章hits 内容数据点击排行榜category 内容栏目列表position 内容推荐位列表
- SQL Server 2008 R2 Developer (x86, x64, ia64) – DVD (Chinese-Simplified)
http://blog.sina.com.cn/s/blog_4aedf6370101j9tz.html 1. SQL Server 2008 R2 Developer (x86, x64, ia64 ...
- 除Hadoop大数据技术外,还需了解的九大技术
除Hadoop外的9个大数据技术: 1.Apache Flink 2.Apache Samza 3.Google Cloud Data Flow 4.StreamSets 5.Tensor Flow ...
- JavaScript——特殊点总结
首先,== equality 等同,=== identity 恒等. ==, 两边值类型不同的时候,要先进行类型转换,再比较. ===,不做类型转换,类型不同的一定不等. 下面分别说明: 先说 === ...
- FlexPaper使用小结
FlexPaper相关介绍及后台swf生成,参见 FlexPaper实现文档在线浏览(附源码) 前台swf在flash中的预览: 1.下载相关文档 FlexPaper Classic 2.将下载的文件 ...
- javascript开发 ios和android app的简单介绍
先看几个名词解释: nodejs ionic,Cordova,phoneGap,anjularjs react-native,reactjs nodeJs 的介绍参见这里,写的很好http://www ...
- ACM/ICPC 之 分治法入门(画图模拟:POJ 2083)
题意:大致就是要求画出这个有规律的Fractal图形了= = 例如 1 对应 X 2 对应 X X X X X 这个题是个理解分治法很典型的例子(详情请参见Code) 分治法:不断缩小规 ...
- Java for LeetCode 204 Count Primes
Description: Count the number of prime numbers less than a non-negative number, n. 解题思路: 空间换时间,开一个空间 ...