Codeforces Round #601 (Div. 2) D. Feeding Chicken(构造)

time limit per test

1.5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Copy

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

Copy

11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789

Note

These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.

In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 00.

Codeforces Round #601 (Div. 2) D. Feeding Chicken(构造)_第1张图片

In the second test case, there are 44 chickens with 33 cells of rice, and 22 chickens with 22 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3−2=13−2=1.

Codeforces Round #601 (Div. 2) D. Feeding Chicken(构造)_第2张图片

In the third test case, each chicken has 33 cells with rice.

Codeforces Round #601 (Div. 2) D. Feeding Chicken(构造)_第3张图片

In the last test case, since there are 6262 chicken with exactly 6262 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.

题意:现在有个n * m的格子,k只鸡。然后格子里如果输入的是R就代表有米,然后鸡要吃米

但是对于每只鸡分配的米必须要是联通的才能吃,问你怎么分配使得分到米最多的跟分到米

最少的差值最小,每只鸡最少分配1个米。

思路:使用坤坤的蛇形养鸡法即可。这个差值肯定要么为0要么为1,统计下地图中R的个数然

后平均分给这k只鸡,每只鸡要么分R / k, 要么分到R / k + 1只。直接扫一遍地图,蛇形分配

即可。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#ifdef LOCAL
#define debug(x) cout << "[" __FUNCTION__ ": " #x " = " << (x) << "]\n"
#define TIME cout << "RuningTime: " << clock() << "ms\n", 0
#else
#define TIME 0
#endif
#define hash_ 1000000009
#define Continue(x) { x; continue; }
#define Break(x) { x; break; }
ll fpow(ll a, int b, int mod) { ll res = 1; for (; b > 0; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res % mod; }
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
#define gc p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
inline int read(){ static char buf[1000000], *p1 = buf, *p2 = buf; register int x = false; register char ch = gc; register bool sgn = false; while (ch != '-' && (ch < '0' || ch > '9')) ch = gc; if (ch == '-') sgn = true, ch = gc; while (ch >= '0'&& ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc; return sgn ? -x : x; }
char s[110][110];
int n, m, k;
int a[N];
string ans;
int main()
{
#ifdef LOCAL
	freopen("D:/input.txt", "r", stdin);
#endif
	ans = " ";
	for (int i = 0; i < 10; i++)
		ans.push_back('0' + i);
	for (int i = 0; i < 26; i++)
		ans.push_back('a' + i);
	for (int i = 0; i < 26; i++)
		ans.push_back('A' + i);
	int t;
	cin >> t;
	while (t--)
	{
		int x = 0;
		scanf("%d%d%d", &n, &m, &k);
		for (int i = 1; i <= n; i++)
		{
			scanf("%s", s[i] + 1);
			for (int j = 1; j <= m; j++)
				if (s[i][j] == 'R')
					x++;
		}
		int MX = x / k;
		int la = x - MX * k;
		for (int i = 1; i <= k; i++)
		{
			a[i] = MX;
			if (la)
				a[i]++, la--;
		}
		int idx = 1;
		int cnt = 0;
		for (int i = 1; i <= n; i++, cout << endl)
		{
			if (i % 2)
			{
				for (int j = 1; j <= m; j++)
				{
					putchar(ans[idx]);
					if (s[i][j] == 'R')
						++cnt;
					if (cnt == a[idx] && idx != k)
						idx++, cnt = 0;
				}
			}
			else
			{
				string w;
				for (int j = m; j >= 1; j--)
				{
					w.push_back(ans[idx]);
					if (s[i][j] == 'R')
						++cnt;
					if (cnt == a[idx] && idx != k)
						idx++, cnt = 0;
				}
				reverse(w.begin(), w.end());
				cout << w;
			}
		}
	}
	return TIME;
}

 

你可能感兴趣的:(Codeforces,思维,模拟)