본문 바로가기
알고리즘/문제

[백준] 16180. New House <C++>

by 코드 이야기 2020. 8. 11.
728x90

https://www.acmicpc.net/problem/16180

 

16180번: New House

Johan wants to build a new house and he wants his house as large as it can. Given an N x N grid land, find the largest square size that fit in the free area. 

www.acmicpc.net

 

ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2009 F번

 

 

적당한 난이도의 문제였던 것 같다.

 

영어라 그런지 푼 사람이 적었다.

 

여러가지 놓친 부분들이 많아서 3번이나 틀렸다.

 

앞으로는 문제에서 놓친 부분은 없을지 잘 확인해보자.

 

 

#include <iostream>
using namespace std;
char arr[11][11];
int t, n, cnt;

int boooool() {
	int f = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (arr[i][j] == '#') f = 1;
		}
	}
	return f;
}

int S12(int size, int x, int y) {
	for (int i = x; i < x + size; i++) {
		for (int j = y; j < y + size; j++) {
			if (i >= n || j >= n) return 0;
			if (arr[i][j] == '#') return 0;
		}
	}
	return 1;
}

int S(int x, int y) {
	for (int i = 1; i <= n; i++) {
		if (S12(i, x, y)) continue;
		else return i - 1;
	}
	return 1;
}

int main() {

	int max;

	cin >> t;

	while (t--) {
		max = 0;

		cin >> n;
		for (int i = 0; i < n; i++)
			cin >> arr[i];

		if (boooool()) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (arr[i][j] == '.') {
						cnt = S(i, j);
						max = cnt > max ? cnt : max;
					}
				}
			}
		}
		else max=n;

		cout << max << '\n';
	}
}

 

728x90

댓글