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 ...
随机推荐
- jtable插件api
官网2016-03-15 事例图: 一.客户端配置 1. paging boolean default:false 配置是否分页,果断改为true. 2. pageList string defaul ...
- django ATOMIC_REQUESTS
在数据库配置中,如果配置了此属性为True,如下: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.xxx', 'NAME': '', ...
- EXT Grid 默认展开所有行
grid.getStore().load({ //默认展开所有行. callback:function() { var expander = grid.plugins[0]; var count = ...
- Postman
Postman功能(https://www.getpostman.com/features) 主要用于模拟网络请求包 快速创建请求 回放.管理请求 快速设置网络代理 安装 下载地址:https://w ...
- 【Other】最近正在看的
待看: https://my.oschina.net/yunfound/blog/141222 https://www.zhihu.com/question/22925358 http://study ...
- C# 毕业证书打印《一》
最近一直在做证书打印的项目,好久都没写日志了.今天将代码整理了一下,希望将自己做证书打印的一些心得写出来,也希望能和大家一起交流. 首先,证书打印必须实现打印的功能.了解打印功能是怎么实现的,打印关键 ...
- zpf 路由功能
2015-4-11 20:51:06 又搞了一天, 解决了一堆bug, 重新规划了类文件夹, 改善自动加载功能 最新的特性就是支持子域名路由了 因为整个框架还在完善当中, 而且里边有好多接口有我自己申 ...
- ALV 输入数据时数字缩小一千倍的问题解决
这个字段后面有三位小数 我输入 1 一回车 就变成了0.001 了 解决方法 DATA: wa_fieldcatalog TYPE lvc_s_fcat, "显示数据列内表工作 ...
- Effective C++ -----条款02:尽量以const, enum, inline替换 #define
class GamePlayer{private: static const int NumTurns = 5; int scores[NumTurns]; ...}; 万一你的编译器(错误地)不允许 ...
- nyoj814_又见拦截导弹_DP
又见拦截导弹 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 大家对拦截导弹那个题目应该比较熟悉了,我再叙述一下题意:某国为了防御敌国的导弹袭击,新研制出来一种导弹拦 ...