CodeForces 22B Bargaining Table

문제 유형
제목의 의미
n*m의 '0' 또는 '1'만 포함하는 문자 행렬 (1 < = n, m < = 25) 을 주십시오.' 0'으로만 구성된 행렬 중 둘레의 길이가 얼마나 되는지 물어보십시오.
문제풀이 방법
최종 매트릭스의 왼쪽 상단을 직접 폭력적으로 매거한 다음에 매거 매트릭스의 길이와 넓이를 매거한 후에 상응하는 매트릭스가'0'으로만 구성되었는지 판단하고 만약 업데이트 결과가 있다면
코드 참고. - 궁금한 거 있으면 댓글로 남겨주시면 빨리 답장해드릴게요.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long LL;

const int MAXN = 1e2 + 10;
const LL INF = 1LL<<62;

char str[MAXN][MAXN];

int main() {
  int n, m;
  while(scanf("%d%d", &n, &m) != EOF) {
    for( int i=0; i<n; i++ ) scanf("%s", str[i]);
    int res = 0;
    for( int i=0; i<n; i++ ) {
      for( int j=0; j<m; j++ ) {
        if(str[i][j] == '1') continue;
        for( int k=1; k<=n-i; k++ ) {
          for( int h=1; h<=m-j; h++ ) {
            if((k + h)*2 <= res) continue;
            bool flag = true;
            for( int ti=0; ti<k && flag; ti++ ) {
              for( int tj=0; tj<h; tj++ ) {
                if(str[i+ti][j+tj] == '1') {
                  flag = false;
                  break;
                }
              }
            }
            if(flag) {
              res = max(res, (k + h)*2);
            }
          }
        }
      }
    }
    printf("%d
", res); } return 0; }

좋은 웹페이지 즐겨찾기