Notice
Recent Posts
Recent Comments
Link
«   2026/05   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

mo1lusca의 블로그

[백준] 2447 별 찍기 - 10 - C 본문

PS

[백준] 2447 별 찍기 - 10 - C

mo1lusca 2025. 5. 1. 11:32

 

 

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

 


 

n*n 사이즈의 배열에서 공백이 들어가야 할 부분만 값을 바꾸는 방법을 사용하였다.

 

#include <stdio.h>

int map[6500][6500];

void star(int x, int y, int n) {
	if (n == 1) { //n==1일때는 식이 다름
		if (x % 3 == 1 && y % 3 == 1) {
			map[y][x] = 1;
		}
		return;
	}
	else {
		star(x, y, n / 3);
		if (x / n % 3 == 1 && y / n % 3 == 1) {
			map[y][x] = 1;
		}
		return;
	}
	star(x, y, n / 3);
	return;
}

int main() {

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			star(j, i, n);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (map[i][j]) {
				printf(" ");
			}
			else {
				printf("*");
			}
		}
		printf("\n");
	}
	return 0;
}

 

n==1일때는 x%3==1일때만 공백이 나오고, 그 외의 n값에 대해서는 x/n%3==1일떄만 공백이 나온다는 것을 찾았다.

 

별찍기 문제는 그림으로 그려보는게 규칙 이해에 도움이 되는 것 같다.