CodeForces 22B Bargaining Table
1497 단어 codeforces간단한 문제
제목의 의미
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;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces Round #715 Div. 2C The Sports Festival: 구간 DP전형구간 DP의 초전형. 이하, 0-indexed. 입력을 정렬하여 어디서나 시작하고 최적으로 좌우로 계속 유지하면 좋다는 것을 알 수 있습니다. {2000})$의 주문이 된다. 우선, 입력을 소트하여 n개의 요소를 $...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.