## D. Feeding Chicken(Codeforces Round #601 (Div. 2))(思维)

D. Feeding Chicken(Codeforces Round #601 (Div. 2))(思维)

题目链接
在这里插入图片描述

inputCopy

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

outputCopy

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 0 0 0.

在这里插入图片描述

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

在这里插入图片描述

In the third test case, each chicken has 3 3 3 cells with rice.
在这里插入图片描述
In the last test case, since there are 62 62 62 chicken with exactly 62 62 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.

题意

这里有一片田地,有的格子上有大米,你必须尽可能地均匀地分配这些有大米的玉米地给 n n n 只鸡,而且分给同一只鸡的玉米地必须是一个连通块。

按照S形枚举,把路径上的地分给同一只鸡即可

代码

#include <iostream>
#include <algorithm>
#include <cstring>
#define maxn 100
#define _for(i, a) for(int i = 0; i < (a); ++i)
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;

char a[maxn][maxn];
int n, m, k;
int sum;
char b[maxn][maxn];
char cc[62];

void init() {
	mem(b, 0);
	sum = 0;
	_for(i, 10) cc[i] = '0' + i;
	_for(i, 26) cc[10 + i] = 'a' + i;
	_for(i, 26) cc[36 + i] = 'A' + i;
}

void sol() {
	init();
	cin >> n >> m >> k;
	_for(i, n) cin >> a[i];
	_for(i, n) {
		_for(j, m) {
			if (a[i][j] == 'R') {
				sum++;
			}
		}
	}
	int tem = 0, cur = 0;
	_for(i, n) {
		if (i & 1) {
			_for(j, m) {
				if ((a[i][j] == 'R') + cur > (tem < sum % k ? sum / k + 1 : sum / k)) {
					tem++;
					cur = 0;
				}
				if (a[i][j] == 'R') cur++;
				b[i][j] = cc[tem];
			}
		}
		else {
			for (int j = m - 1; j >= 0; j--) {
				if ((a[i][j] == 'R') + cur > (tem < sum % k ? sum / k + 1 : sum / k)) {
					tem++;
					cur = 0;
				}
				if (a[i][j] == 'R') cur++;
				b[i][j] = cc[tem];
			}
		}
	}
	_for(i, n) {
		_for(j, m) {
			cout << b[i][j];
		}
		cout << "\n";
	}
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);

	int T;
	cin >> T;
	_for(i, T) {
		sol();
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值