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 ...
随机推荐
- replace、replaceAll、replaceFirst的区别详解
String s = "my.test.txt"; System.out.println(s.replace(".", "#")); Sys ...
- vmware-question
1.网卡修改序号ip link set eth3 name eth02.解决克隆虚拟机后网卡设备无法识别启动问题的方法******************************/etc/udev/r ...
- 普元部署多个应用的方法(适用EOS6.5以上版本,且无需governor中添加应用)
在EOS下跑default项目之外的另外一个项目,比如defaultNew 步骤1 安装EOS6.5,安装路径如下:E:\program\eos: 启动EOS Eos默认的应用名称为Default 步 ...
- vs2013 内置IIS Express相关问题
问题描述,以前做的程序迁移到vs2013后出现500.22问题. HTTP 错误 500.22 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.NET 设 ...
- atom 折腾记(转载的)
http://www.bkjia.com/webzh/999078.html
- 开源工作流 Bonita BPM (JAVA)
Bonita BPM 开源工作流 Bonita BPM (JAVA) http://www.bonitasoft.com/
- 转一篇Xcode中利用target编译不同版本的文章
http://www.cocoachina.com/ios/20160331/15832.html 主要说的是,不用自己定义debug宏,而是在xcode的编译配置文件中,设定debug宏,这样,不用 ...
- oracle 学习
一.数据库语言部分1. SQL语言:关系数据库的标准语言2. PL/SQL:过程化语言Procedural Language3. SQL*Plus:简单的报表,操作系统接口 4. Oracle 8.0 ...
- SolrCloud环境配置
Solr是一个企业级搜索服务器,对外提供Web-Service接口,用户可以通过http请求,向搜索引擎提交xml或者json格式的数据,生成索引:然后可以通过http get请求查找,获取返回的xm ...
- ACM/ICPC 之 模拟 (HNUOJ 13391-换瓶模拟)
题意:汽水瓶有三个部分cap+plastic bottle+ label(瓶盖-瓶身-瓶底),给出数据:n为原瓶数,x,y,z为这三个部分可以用相应的数字换取新瓶子,求最大总瓶数. 模拟(暴力) // ...