9방향을 다 체크해본다.

무식한 방법이다.

#include <iostream>

using namespace std;

int map[10][10];

bool letmego(int go, int x, int y, int depth, int counter,int blank) {
	if (depth > 4) {
		return false;
	}
	if (depth == 4) {
		if ((counter == 4 && blank == 1) || counter==5) {
			return true;
		}
	}
	if (go == 0 && x > 0 && y > 0) {
		if (map[x - 1][y - 1] == 1) {
			return letmego(go, x - 1, y - 1, depth + 1, counter + 1, blank);
		}
		else if (map[x - 1][y - 1] == 2) return false;
		else {
			return letmego(go, x - 1, y - 1, depth + 1, counter, blank+1);
		}
	}
	else if (go == 1 && y > 0) {
		if (map[x][y - 1] == 1) {
			return letmego(go, x, y - 1, depth + 1, counter + 1, blank);
		}
		else if (map[x][y - 1] == 2) return false;
		else {
			return letmego(go, x, y - 1, depth + 1, counter, blank+1);
		}
	}
	else if (go == 2 && x < 9 && y > 0) {
		if (map[x + 1][y - 1] == 1) {
			return letmego(go, x + 1, y - 1, depth + 1, counter + 1, blank);
		}
		else if (map[x + 1][y - 1] == 2) return false;
		else {
			return letmego(go, x + 1, y - 1, depth + 1, counter, blank+1);
		}
	}
	else if (go == 3 && x > 0) {
		if (map[x - 1][y] == 1) {
			return letmego(go, x - 1, y, depth + 1, counter + 1, blank);
		}
		else if (map[x - 1][y] == 2) return false;
		else {
			return letmego(go, x - 1, y, depth + 1, counter, blank+1);
		}
	}
	else if (go == 4 && x < 9) {
		if (map[x + 1][y] == 1) {
			return letmego(go, x + 1, y, depth + 1, counter + 1, blank);
		}
		else if (map[x + 1][y] == 2) return false;
		else {
			return letmego(go, x + 1, y, depth + 1, counter, blank+1);
		}
	}
	else if (go == 5 && x > 0 && y < 9) {
		if (map[x - 1][y + 1] == 1) {
			return letmego(go, x - 1, y + 1, depth + 1, counter + 1, blank);
		}
		else if (map[x - 1][y + 1] == 2) return false;
		else {
			return letmego(go, x - 1, y + 1, depth + 1, counter, blank+1);
		}
	}
	else if (go == 6 && y < 9) {
		if (map[x][y + 1] == 1) {
			return letmego(go, x, y + 1, depth + 1, counter + 1, blank);
		}
		else if (map[x][y + 1] == 2) return false;
		else {
			return letmego(go, x, y + 1, depth + 1, counter, blank+1);
		}
	}
	else if (go == 7 && x < 9 && y < 9) {
		if (map[x + 1][y + 1] == 1) {
			return letmego(go, x + 1, y + 1, depth + 1, counter + 1, blank);
		}
		else if (map[x + 1][y + 1] == 2) return false;
		else {
			return letmego(go, x + 1, y + 1, depth + 1, counter, blank+1);
		}
	}
	return false;
}

int main() {
	int a = 0, b = 0;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			char temp;
			cin >> temp;
			if (temp == 'X') {
				map[i][j] = 1;
				a++;
			}
			else if (temp == 'O') {
				map[i][j] = 2;
				b++;
			}
			else if (temp == '.') map[i][j] = 0;
		}
	}
	if (a != b) {
		exit(0);
	}
	bool flag = false;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if(map[i][j] == 1){
				for (int k = 0; k < 8; k++) {
					if (letmego(k, i, j, 0, 1, 0))	flag = true;
				}
			}
		}
	}
	if (flag) {
		cout << 1<<endl;
	}
	else {
		cout << 0 << endl;
	}
}

'컴퓨터 > 문제 풀기' 카테고리의 다른 글

백준 4948번 베르트랑 공준  (0) 2019.05.20
백준 1946번 신입 사원  (0) 2019.05.20
10799번 쇠막대기  (0) 2019.05.13
2413번 비슷한 순열  (1) 2019.05.13
2309번 일곱 난쟁이  (0) 2019.05.13

+ Recent posts