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
76
77
78
79
80
81
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main {
static int m, n, k;
static boolean visited[][] = new boolean[101][101];
static int dx[] = {-1,1,0,0}, dy[] = {0,0,-1,1};
static int tmp = 0;
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st= new StringTokenizer(br.readLine());
m = Integer.parseInt(st.nextToken()); // 세로
n = Integer.parseInt(st.nextToken()); //가로
k= Integer.parseInt(st.nextToken()); //사각형의 개수
for (int i = 0; i < k; i++) {
st= new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
// pos[i] = new Pos(a, b, c,d);
for (int j = b; j < d; j++) {
for (int k = a; k < c; k++) {
visited[j][k] = true;
}
}
}
int cnt = 0;
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (!visited[i][j]) {
tmp = 1;
dfs(i, j);
list.add(tmp);
cnt++;
}
}
}
System.out.println(cnt);
for (int i = 0; i < cnt; i++) {
}
}
static void dfs(int x, int y) {
visited[x][y] = true;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || nx >= m || ny < 0 || ny >= n || visited[nx][ny] ) continue;
tmp++;
dfs(nx, ny);
}
}
static class Pos {
int a,b,c,d;
public Pos(int a, int b, int c, int d) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
BOJ/JAVA