728x90
320x100
반응형
📌 접근 방법
😱 쉬워보였지만 매우매우 어려웠다 😅
- N = 3일 경우 공백
(1, 1) - N=9일 경우 공백
(1,1), (1,4), (1,7)
(3,3), (3,4), (3,5)
(4,1), (4,3), (4,4), (4,5), (4,7)
(5,3), (5,4), (5,5)
➡️ 규칙
- 작은 공백은 (x%3==1)&&(y%3==1)의 조건을 만족할 때 공백이 생긴다는 것을 알 수 있었다.
- 큰 공백은 ((x/N)%3==1)&&((y/N)%3==1)이 만족되면 공백이 생긴다는 것을 알 수 있었다.
재귀적 반복을 이용하면 구할 수 있었다.
✅ Pass Code
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iterator>
#include<map>
#include<set>
#include<unordered_set>
#include <stack>
#include<queue>
#include<deque>
using namespace std;
void star(int n, int x, int y){
if((x/n)%3==1&&(y/n)%3==1){
cout<<" ";
}
else{
if(n/3==0){
cout<<"*";
}
else{
star(n/3, x, y);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin>>N;
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
star(N,i,j);
}
cout<<'\n';
}
return 0;
}
728x90
반응형
'Coding Test > Baekjoon' 카테고리의 다른 글
[BOJ/백준/C++] 15649번 (1) | 2024.01.29 |
---|---|
[BOJ/백준/C++] 11729번 하노이 탑 이동 순서 (0) | 2024.01.29 |
[BOJ/백준/C++] 17103번 골드바흐 파티션 (2) | 2024.01.28 |
[BOJ/백준/C++] 4779번 칸토어 집합 (0) | 2024.01.28 |
[BOJ/백준/C++] 24060번 알고리즘 수업 - 병합 정렬 1 (1) | 2024.01.28 |