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

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

组成的三角形放置方式一共只有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. c_水程序

    * ** This program reads input lines from the standard input and prints ** each input line, followed ...

  2. Apache Thrift 环境配置

    在 Ubuntu 14.04 下Apache Thrift 的安装方法: 1安装依赖包 sudo apt-get install libboost-dev libboost-test-dev libb ...

  3. 2.2---找链表倒数第K个结点

    答案,注意,一种是递归,另一种是迭代,那么巧妙利用双指针: 迭代: public static LinkedListNode nthToLast(LinkedListNode head, int n) ...

  4. 使用Gitosis搭建Git服务器

    使用Gitosis搭建Git服务器 作者: JeremyWei | 可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明 网址: http://weizhifeng.net/build- ...

  5. [20160725]MyComparableTest

    知识点: 1.Collections的使用. 2.自定义类泛型的使用. 3.自定义类,toString();equals();hashCode()方法的重写. import java.util.*; ...

  6. java导出生成word

    最近做的项目,需要将一些信息导出到word中.在网上找了好多解决方案,现在将这几天的总结分享一下. 目前来看,java导出word大致有6种解决方案: 1:Jacob是Java-COM Bridge的 ...

  7. 【leetcode】Reverse Linked List II

    Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one-pass. F ...

  8. iOS 关于iphone6 和 iphone6 plus 的适配

    http://www.ui.cn/detail/26980.html 根据上面说的,iphone6 plus的屏幕的编程时的宽度应该是414,我理解的也是这样,但是我用iphone6 plus 模拟器 ...

  9. gcc-5.4.0 static dwarf2 compile

    ------------------------------------------------------------------------------- 又开始折腾了, 静态编译 gcc-5.4 ...

  10. Java for LeetCode 211 Add and Search Word - Data structure design

    Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...