-
Notifications
You must be signed in to change notification settings - Fork 15
/
1254-A.cpp
66 lines (55 loc) · 1.74 KB
/
1254-A.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
/*
ad-hoc > implementation
difficulty: medium
date: 25/Nov/2019
by: @brpapa
*/
#include <iostream>
using namespace std;
string chickens = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
char farm[101][101];
char ans[101][101];
int main() {
int T;
cin >> T;
while (T--) {
int R, C, K;
cin >> R >> C >> K;
char tmp;
int qtyRiceCells = 0;
for (int r = 0; r < R; r++)
for (int c = 0; c < C; c++) {
cin >> tmp;
farm[r][c] = tmp;
if (tmp == 'R')
qtyRiceCells++;
}
int more_qtyChickens = qtyRiceCells % K;
int more_qtyCells = qtyRiceCells/K + 1;
// cout << more_qtyChickens << " galinhas recebem " << more_qtyCells << " células" << endl;
int less_qtyChickens = K - more_qtyChickens;
int less_qtyCells = qtyRiceCells/K;
// cout << less_qtyChickens << " galinhas recebem " << less_qtyCells << " células" << endl;
int k = 0; // galinha atual
int qty = 0; // quantas celulas de arroz a galinha atual recebeu
for (int r = 0; r < R; r++) {
bool rEven = r%2 == 0;
for (int c = rEven? 0:C-1; rEven? c < C:c >= 0; c += rEven? 1:-1) {
int qtyCells = (k < more_qtyChickens)? more_qtyCells : less_qtyCells; // as more_qtyChickens primeiras galinhas são as que recebem more_qtyCells células
if (farm[r][c] == 'R') {
if (++qty > qtyCells) {
qty = 1;
k++;
}
}
ans[r][c] = chickens[k];
}
}
for (int r = 0; r < R; r++) {
for (int c = 0; c < C; c++)
cout << ans[r][c];
cout << endl;
}
}
return 0;
}