CodeForces 370D Broken Monitor
来源:互联网 发布:手机淘宝店铺关注链接 编辑:程序博客网 时间:2024/05/23 23:37
#include <cstdlib>#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>using namespace std;#define N 2005char ch[N][N];int judge(int top, int bottom, int left, int right){ int flag = 1; for(int i = top+1; i<=bottom-1; i++) { for(int j=left+1; j<=right-1; j++) { if(ch[i][j]=='w') {flag = 0; break;} } } return flag;} int main() { int n,m; int top = 2001, bottom = -1, left = 2001, right = -1, tempi = 0, tempj = 0; scanf("%d%d",&n,&m); getchar(); for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { ch[i][j] = getchar(); if(ch[i][j]=='w') { top = top > i ? i : top; bottom = bottom < i ? i : bottom; left = left > j ? j : left; right = right < j ? j : right; } } getchar(); } int flag = 0, flag1 = 1; int temph = right - left + 1, tempv = bottom - top + 1; if(temph == tempv) { for(int i=top+1; i<=bottom-1; i++) for(int j=left+1; j<=right-1; j++) { if(ch[i][j]=='w'){flag = 1; break;} } } else { if(temph > tempv) { int temp = temph - tempv; for(int i=top - temp; i<=top; i++) { if(i<1) continue; if(i+temph-1>n) break; if(judge(i,i+temph-1,left,right)) { top = i; bottom = i+temph-1; flag1 = 0; break; } } flag = flag1; } else if(temph < tempv) { int temp = tempv - temph; for(int i=left - temp; i<=left; i++) { if(i<1) continue; if(i+tempv-1>m) break; if(judge(top,bottom,i,i+tempv-1)) { left = i; right = i + tempv - 1; flag1 = 0; break; } } flag = flag1; } } if(flag==1) printf("-1\n"); else { for(int i=top; i<=bottom; i++) { if(ch[i][left]!='w') ch[i][left] = '+'; if(ch[i][right]!='w') ch[i][right]='+'; } for(int i=left; i<=right; i++) { if(ch[top][i]!='w') ch[top][i]='+'; if(ch[bottom][i]!='w') ch[bottom][i]='+'; } for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) printf("%c",ch[i][j]); printf("\n"); } } return 0;}
0 0
- CodeForces 370D Broken Monitor
- CodeForces-171D Broken checker
- Codeforces 797D Broken BST dfs+模拟
- Educational Codeforces Round 19-D. Broken BST
- Codeforces-846D:Monitor(二维线段树)
- CodeForces 24D Broken robot(三对角矩阵)
- CodeForces 24D Broken robot (概率DP)
- CodeForces 24D Broken robot(概率dp+三对角矩阵)
- codeforces 258D Little Elephant and Broken Sorting
- Codeforces 258D Little Elephant and Broken Sorting
- codeforces 171D Broken checker (多次尝试)
- Codeforces 846D Monitor(二维前缀和)
- Educational Codeforces Round 28 D. Monitor 二维rmq
- codeforces 846D (二分+二维前缀和)Monitor
- D - A Broken Calculator
- 797D Broken BST
- D. Broken BST
- Broken robot CodeForces
- Java编程思想学习笔记(五) 第6章 访问权限控制
- redis3.2.2单机集群搭建
- Lync 2013边缘服务器部署4—生成证书申请文件
- 近实时运算的利器---presto在公司实践
- Lync 2013边缘服务器部署3—安装LYNC边缘
- CodeForces 370D Broken Monitor
- Lync 2013边缘服务器部署2—配置拓扑
- Lync 2013边缘服务器部署1—系统环境准备
- 反调试-通过手动添加TLS回调函数
- 投资什么,收益最高?
- js输出
- Controller与View数据传递(多表数据) ViewModel方式
- C++理解拷贝控制成员和构造函数
- Locale