알고리즘
[알고리즘] 백준 1030 - 프렉탈 평면 (C++)
blueberrysoda
2024. 12. 30. 22:18
[문제 링크] : https://www.acmicpc.net/problem/1030
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int S, N, K, Y1, X1, Y2, X2;
bool Arr[51][51];
void solve(int s, int y, int x){
if(s == 1){
return;
}
if(y > Y2 || y + s -1 < Y1 || x > X2 || x + s - 1 < X1){
return;
}
int start = s / N * (N - K) / 2;
int end = start + s / N * K - 1;
int y1 = max(Y1, start + y);
int x1 = max(X1, start + x);
int y2 = min(Y2, end + y);
int x2 = min(X2, end + x);
for(int i=y1; i<=y2; i++){
for(int j=x1; j<=x2; j++){
Arr[i-Y1][j-X1] = true;
}
}
for(int i=0; i<s; i+=s/N){
for(int j=0; j<s; j+=s/N){
if(i >= start && i <= start && j >= start && j <= end){
continue;
}
solve(s / N, y + i, x + j);
}
}
return;
}
int main(){
cin >> S >> N >> K >> Y1 >> Y2 >> X1 >> X2;
solve((int)pow(N, S), 0, 0);
for(int i=0; i<Y2-Y1+1; i++){
for(int j=0; j<X2-X1+1; j++){
if(Arr[i][j] == true){
cout << 1;
}
else{
cout << 0;
}
}
cout << "\n";
}
return 0;
}