Algorithm, Data structure/Solved Algorithmic Problem

BAEKJOON 1030 - 프렉탈 평면

JaykayChoi 2016. 8. 13. 12:17

문제: https://www.acmicpc.net/problem/1030


값을 미리 배열에 모두 넣어두면 편할테지만 메모리 문제로 규칙을 찾아 값을 얻는 방법을 사용했습니다.



my solving

c++

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <fstream>
#include <iostream>
#include <cstring>
#include <climits>
#include <algorithm>
 
using namespace std;
 
int s, n, k;
int length;
 
int getColor(int y, int x)
{
    if (y == 1)
        int temp = 0;
    int unit = length / n;
    int border = (n - k) / 2;
    while (unit > 0)
    {
        if (y / unit >= border && y / unit <= n - - border && x / unit >= border && x / unit <= n - - border)
            return 1;
        
        if (y >= unit)
            y %= unit;
        if (x >= unit)
            x %= unit;
        unit /= n;
    }
    return 0;
}
 
int main()
{
    int r1, r2, c1, c2;
    cin >> s >> n >> k >> r1 >> r2 >> c1 >> c2;
 
    length = pow(n, s);
 
    for (int y = r1; y <= r2; y++)
    {
        for (int x = c1; x <= c2; x++)
            cout << getColor(y, x);
        
        cout << endl;
    }
 
    return 0;
}
cs