求组成的等腰三角形面积最大值。

对此题的总结:暴力出奇迹

组成的三角形放置方式一共只有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的更多相关文章

  1. [LeetCode] Perfect Rectangle 完美矩形

    Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...

  2. [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 ...

  3. [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 ...

  4. [LeetCode] Rectangle Area 矩形面积

    Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...

  5. [LeetCode] Maximal Rectangle 最大矩形

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...

  6. [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  7. Maximal Rectangle

    很不好想的一道题,参考:http://blog.csdn.net/doc_sgl/article/details/11832965 分为两步:把原矩阵转为直方图,再用largest rectangle ...

  8. 85. Maximal Rectangle

    85. Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle c ...

  9. poj 2559 Largest Rectangle in a Histogram - 单调栈

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19782 ...

随机推荐

  1. nc 局域网聊天+文件传输(netcat)

    nc 局域网聊天+文件传输 nc的全程是netcat,这个工具非常好用. 有时候我们需要在局域网内传送一些文本消息或者文件的时候,通常的做法是安装一些局域网通讯软件,然后来做.其实不必要这样,使用nc ...

  2. ubuntu系统安装PHP扩展

    GD库的安装 sudo apt-get install php5-gd sudo apt-get install php5-gd sudo /etc/init.d/apache2 restart CU ...

  3. HTML——meta标签

    <meta> 元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频度的描述和关键词. <meta> 标签位于文档的头部,不包含任何内容.&l ...

  4. SQL 执行计划(一)

    缓存执行计划  SQL Server 2008提供了一些服务器对象来分析执行计划Sys.dm_exec_cached_plans:    包含缓存的执行计划,每个执行计划对应一行.Sys.dm_exe ...

  5. cxGrid 增加序号 (非数据库绑定模式) (测试通过)

    cxGrid 增加序号 (非数据库绑定模式) ----------------------------------- 1. 选在 adoQuery 控件 , 鼠标右键菜单中 选择 Fields Edi ...

  6. ACM/ICPC 之 拓扑排序+DFS(POJ1128(ZOJ1083)-POJ1270)

    两道经典的同类型拓扑排序+DFS问题,第二题较第一题简单,其中的难点在于字典序输出+建立单向无环图,另外理解题意是最难的难点,没有之一... POJ1128(ZOJ1083)-Frame Stacki ...

  7. Mathematics:Prime Path(POJ 3126)

    素数通道 题目大意:给定两个素数a,b,要你找到一种变换,使得每次变换都是素数,如果能从a变换到b,则输出最小步数,否则输出Impossible 水题,因为要求最小步数,所以我们只需要找到到每个素数的 ...

  8. Velocity 基本语法

    Velocity 基本语法 Velocity 是一个基于 Java 的模板引擎框架,提供的模板语言可以使用在 Java 中定义的对象和变量上.Velocity 是 Apache 基金会的项目,开发的目 ...

  9. codeforces 495A. Digital Counter 解题报告

    题目链接:http://codeforces.com/problemset/problem/495/A 这个题目意思好绕好绕~~好绕~~~~~,昨天早上做得 virtual 看不懂,晚上继续看还是,差 ...

  10. IOS - Passbook

    1. 什么是Passbook Passbook是苹果公司于北京时间2012年6月12日上午,在全球开发者大会(WWDC)上宣布了iOS 6系统将提供操作一个全新的应用——Passbook 这是一款可以 ...