-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cpp
83 lines (72 loc) · 1.14 KB
/
Source.cpp
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
82
83
#include <iostream>
int mindex(int, int, int, int);
int main()
{
int M, N, K;
scanf_s("%d %d %d", &M, &N, &K);
int* M_Dim = new int[M];
for (int i = 0; i < M; i++)
{
scanf_s("%d", &M_Dim[i]);
M_Dim[i] = i > 0 ? M_Dim[i] + M_Dim[i - 1] : M_Dim[i];
}
int* matrix = new int[N * K];
for (int i = 0; i < N * K; i++)
{
scanf_s("%d", &matrix[i]);
}
int mC = 0;
int counter = 1;
int* rooms = new int[N * K / M + 1];
int rooms_index = 0;
bool flag = true;
for (size_t y = 0; y < N; y++)
{
for (size_t x = 0; x < K; x++)
{
int index = mindex(x, y, N, K);
if (x < M_Dim[mC])
{
flag = flag && !matrix[index];
}
else
{
mC++;
if (flag)
{
rooms[rooms_index++] = counter;
}
flag = true;
counter++;
x--;
}
}
if (flag)
{
rooms[rooms_index++] = counter;
}
flag = true;
counter++;
mC = 0;
}
rooms[rooms_index] = -1;
int c = 0;
printf("%d\n", rooms_index);
while (rooms[c] != -1)
{
printf("%d ", rooms[c++]);
}
return 0;
}
int mindex(int x, int y, int N, int K)
{
return x + (N - 1 - y) * K;
}
/*
3 4 6
3 2 1
0 0 0 1 0 1
0 0 1 0 1 0
1 0 1 0 0 1
0 1 0 1 0 0
*/