Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with rr rows and cc columns. Some of these cells contain rice, others are empty. kk chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
- Each cell of the farm is assigned to exactly one chicken.
- Each chicken is assigned at least one cell.
- The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x,y)(x,y) and (u,v)(u,v) are assigned to the same chicken, this chicken is able to walk from (x,y)(x,y) to (u,v)(u,v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases TT (1≤T≤2⋅1041≤T≤2⋅104). Description of the test cases follows.
The first line of each test case contains three integers rr, cc and kk (1≤r,c≤100,1≤k≤621≤r,c≤100,1≤k≤62), representing the size of Long's farm and the number of chickens Long has.
Each of the next rr lines contains cc characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r⋅cr⋅c over all test cases does not exceed 2⋅1042⋅104.
Output
For each test case, print rr lines with cc characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4 3 5 3 ..R.. ...R. ....R 6 4 6 R..R R..R RRRR RRRR R..R R..R 5 5 4 RRR.. R.R.. RRR.. R..R. R...R 2 31 62 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122 22223 33333 aacc aBBc aBBc CbbA CbbA CCAA 11114 22244 32444 33344 33334 abcdefghijklmnopqrstuvwxyzABCDE FGHIJKLMNOPQRSTUVWXYZ0123456789
这题,我觉得比C题简单好像,假设鸡有X个,输入的时候统计大米的数量为Y个,那么设每只鸡至少拿Num=Y/X个,那么由于Y%X可能不能为0,所以有剩余,那么就会有Y%X只鸡拿了Num+1个,剩下的X-Y%X的都是拿Num个,然后蛇形转,访问到第Num个就换字符,知道访问X-Y%X个,然后按照上面的方法访问Y%X的Num+1;完事了就这么简单,放D题,小题大做。代码无,实现非常简单,不想写了。
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, k;
char s[N][N];
char ans[N][N];
int Max, Min;
int need, num;
char Get(int x)
{
if(x < 26)
return x + 'a';
x -= 26;
if(x < 26)
return x + 'A';
x -= 26;
return x + '0';
}
void go(int x, int y, int cnt, int d)
{
if(y == m + 1)
{
++x;
y = m;
d = -1;
}
if(y == 0)
{
++x;
y=d= 1;
}
if(x > n)
return;
if(s[x][y] == 'R')
--cnt;
if(cnt == -1)
++num;
ans[x][y] = Get(num);
if(cnt == -1)
{
if(--need >= 0)
go(x, y + d, Max - 1, d);
else
go(x, y + d, Min - 1, d);
return;
}
go(x, y + d, cnt, d);
}
int main()
{
int T;
cin >> T;
while(T--)
{
cin >> n >> m >> k;
int tot = 0;
for(int i = 1; i <= n; i++)
{
cin >> (s[i] + 1);
for(int j = 1; j <= m; j++)
{
if(s[i][j] == 'R')
++tot;
}
}
Min = tot / k, Max = tot / k + 1;
need = tot - k * Min;
num = 0;
if(--need >= 0)
go(1, 1, Max, 1);
else
go(1, 1, Min, 1);
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
cout << ans[i][j];
}
cout << '\n';
}
}
return 0;
}