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

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

组成的三角形放置方式一共只有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. OpenGL官方教程——着色器语言概述

    OpenGL官方教程——着色器语言概述 OpenGL官方教程——着色器语言概述 可编程图形硬件管线(流水线) 可编程顶点处理器 可编程几何处理器 可编程片元处理器 语言 可编程图形硬件管线(流水线) ...

  2. jquery 生成table表格 部分代码

    想生成上面这样的table表格先看返回数据格式 <div id="create_img_tab"></div> window.onload = functi ...

  3. sql server 2008笔记

    sql server 2008开启远程访问数据库 1.以windows验证模式进入数据库管理器. 第二步:右击sa,选择属性: 在常规选项卡中,重新填写密码和确认密码(改成个好记的).把强制实施密码策 ...

  4. css常用代码

    透明度: filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5; 英文大小写: div{text-transform:capitalize|U ...

  5. 【Kubernetes】两篇文章 搞懂 K8s 的 fannel 网络原理

    近期公司的flannel网络很不稳定,花时间研究了下并且保证云端自动部署的网络能够正常work. 1.网络拓扑 拓扑如下:(点开看大图)  容器网卡通过docker0桥接到flannel0网卡,而每个 ...

  6. ios 在storyboard 和 xib中,显示自定义view的预览效果

    发现FSCalendar这个控件能在xib中显示预览效果,是怎么实现的呢?其中涉及的知识又有哪些? 主要就是IBInspectable 和 IB_DESIGNABLE 先看 IBInspectable ...

  7. redis 中文字符显示

    2015年5月20日 09:57:01 星期三 方法一: redis-cli -h --raw 方法二: linux 终端: echo -e "\xe7\xa5\x9e\xe6\xa3\x8 ...

  8. VMware ESXi客户端连接控制台时提示"VMRC控制台连接已断开...正在尝试重新连接"的解决方法

    通过vSphere Client连接到安装VMware ESXi虚拟环境的主机时,当启动操作系统,选中控制台时控制台上方提示一行"VMRC控制台的连接已断开...正在尝试重新连接" ...

  9. CentOS搭建svn服务器支持https访问

    在CentOS6.3 64位机器上配置SVN服务器,并设置只允许HTTPS连接,可以配置多个repos源,每个源都拥有自己的组和成员,用于权限控制. 安装相关软件 Apache yum install ...

  10. 安装PostgreSQL数据库 ,Database Cluster 失败!

    在安装PG数据库的过程中,会选择安装目录以及数据存放目录和端口,并需要选择Local,如果全部使用默认,并且设置好自己的密码后开始安装,前期进展还比较顺利,到了安装Database Cluster时, ...