-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFractalPlane.java
More file actions
75 lines (63 loc) · 2.05 KB
/
FractalPlane.java
File metadata and controls
75 lines (63 loc) · 2.05 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
new FractalPlane();
}
}
class FractalPlane{
int S;
int N;
int K;
int R1, R2, C1, C2;
public FractalPlane() throws IOException {
inputData();
boolean result[][] = new boolean[C2-C1+1][R2-R1+1];
for(int i = C1; i<=C2; i++){
for(int j = R1; j<=R2; j++){
result[i-C1][j-R1] = isMiddle(i,j, S);
}
}
for(int i =0; i<(R2-R1+1); i++){
for(int j = 0; j<(C2-C1+1); j++){
if(result[j][i]){
System.out.print(1);
}else{
System.out.print(0);
}
}
System.out.println();
}
}
private boolean isMiddle(long i, long j, long s) {
if (s<=0)return false;
long pow = (long) Math.pow(N,s-1);
if(range(N*pow, K*pow, i, j)){
return true;
}else{
return isMiddle(i%pow, j%pow, s-1);
}
}
private void inputData() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
S = Integer.parseInt(st.nextToken());
N = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
R1 = Integer.parseInt(st.nextToken());
R2 = Integer.parseInt(st.nextToken());
C1 = Integer.parseInt(st.nextToken());
C2 = Integer.parseInt(st.nextToken());
}
public boolean range(long N, long K, long x, long y){
return (N%2==0)?evenRange(N,K,x)&&evenRange(N,K,y):oddRange(N,K,x)&&oddRange(N,K,y);
}
private boolean oddRange(long N, long K, long i) {
return N/2-K/2<=i&&i<=N/2+K/2;
}
public boolean evenRange(long N, long K, long i){
return N/2 - K/2 <= i&&i<=N/2 + K/2-1;
}
}