CodeForces 22b_Bargaining Table_dp(暴力)
来源:互联网 发布:张清为何出卖老毕 知乎 编辑:程序博客网 时间:2024/05/16 05:29
题目大意
给出一个01矩阵求其中矩形的最大周长
思路
暴力枚举矩形左上角顶点在其基础上枚举右下角
用pre维护前几行最早出现第一个1之前的位置
给出一个01矩阵求其中矩形的最大周长
思路
暴力枚举矩形左上角顶点在其基础上枚举右下角
用pre维护前几行最早出现第一个1之前的位置
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#define INF 0x3f3f3f3f#define rep0(i, n) for (int i = 0; i < n; i++)#define rep1(i, n) for (int i = 1; i <= n; i++)#define rep_0(i, n) for (int i = n - 1; i >= 0; i--)#define rep_1(i, n) for (int i = n; i > 0; i--)#define MAX(x, y) (((x) > (y)) ? (x) : (y))#define MIN(x, y) (((x) < (y)) ? (x) : (y))#define mem(x, y) memset(x, y, sizeof(x))#define MAXN 30char g[MAXN][MAXN];using namespace std;int main(){ #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif // ONLINE_JUDGE int n, m; //mem(dp, 0); scanf("%d %d", &n, &m); rep0(i, n) scanf("%s", g[i]); int re = 0; rep0(i, n) { rep0(j, m) { if (g[i][j] == '1') continue; int flag = 0; int pre = INF; for (int a = i; a < n; a++) { if (flag) break; for (int b = j; b < m; b++) { if (g[a][b] == '1' && b == j) { flag = 1; //pre = -1; break; } else if (g[a][b] == '1') { pre = MIN(b - 1, pre); break; } if (b > pre) re = MAX(re, 2 + 2 * (b - j + 1)); else re = MAX(re, (a > i) ? 2 * (b - j + 1 + a - i + 1) : (2 + 2 * (b - j + 1))); } } } } printf("%d\n", re); return 0;}
阅读全文
0 0
- CodeForces 22b_Bargaining Table_dp(暴力)
- Codeforces 22B Bargaining Table【暴力+思维】
- Codeforces Team Olympiad(暴力)
- Codeforces 626D 暴力
- Codeforces 632D 暴力
- Codeforces 493C 暴力
- Codeforces Gym100531D Digits 暴力
- Codeforces 550B 【暴力】
- CodeForces 13A【暴力】
- CodeForces 665B【暴力】
- CodeForces 66B 暴力
- codeforces 734 (思维 暴力)
- Codeforces 835D【暴力】
- codeforces 837C(暴力)
- codeforces 900C(暴力)
- codeforces 903B(暴力)
- Codeforces 412C Pattern(暴力)
- codeforces 461C 暴力+BIT
- Codeforces 849 B Tell Your World
- 文章标题
- 04 Spring框架 依赖注入(一)
- Word 公式编辑器 上下标
- PAI的示例项目MNIST详解
- CodeForces 22b_Bargaining Table_dp(暴力)
- UVa 232 Crossword Answers
- 笔试复习_TCP/IP(二)
- 朴素贝叶斯分类器
- 闭包
- 泛型擦除
- 【拜小白opencv】26-图像噪声1——椒盐噪声
- 系统蓝屏日志MEMORY.DMP导出与分析
- 软件资源网