【CodeForces 1255D --- Feeding Chicken】

Description

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 r rows and c columns. Some of these cells contain rice, others are empty. k 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) and (u,v) are assigned to the same chicken, this chicken is able to walk from (x,y) to (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 T (1≤T≤2⋅104). Description of the test cases follows.

The first line of each test case contains three integers r, c and k (1≤r,c≤100,1≤k≤62), representing the size of Long’s farm and the number of chickens Long has.

Each of the next r lines contains c 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⋅c over all test cases does not exceed 2⋅104.

Output

For each test case, print r lines with c 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.

Sample 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

Sample Output

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

AC代码:

#include <bits/stdc++.h>
using namespace std;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define endl '\n'
const int MAXN = 106;
char str[MAXN][MAXN];
vector<char> ch;void init()
{for(char i='0';i<='9';i++) ch.emplace_back(i);for(char i='A';i<='Z';i++) ch.emplace_back(i);for(char i='a';i<='z';i++) ch.emplace_back(i);
}int main()
{SIS;int T;init();cin >> T;while(T--){int r,c,k,cnt=0;cin >> r >> c >> k;for(int i=1;i<=r;i++){for(int j=1;j<=c;j++){cin >> str[i][j];if(str[i][j]=='R') cnt++;}}int x=cnt/k,y=cnt%k,cht=0;int xx=x;if(y) xx++,y--;for(int i=1;i<=r;i++){if(i&1){for(int j=1;j<=c;j++){if(str[i][j]=='R') xx--,cnt--;str[i][j]=ch[cht];if(!cnt){str[i][j]=ch[cht];continue;}if(!xx){if(y) xx=x+1,y--;else xx=x;cht++;}}}else{for(int j=c;j>=1;j--){if(str[i][j]=='R') xx--,cnt--;str[i][j]=ch[cht];if(!cnt){str[i][j]=ch[cht];continue;}if(!xx){if(y) xx=x+1,y--;else xx=x;cht++;}}}}for(int i=1;i<=r;i++){            for(int j=1;j<=c;j++) cout << str[i][j];cout << endl;}}return 0;
}

【CodeForces 1255D --- Feeding Chicken】相关推荐

  1. CodeForces - 1255D Feeding Chicken(贪心+构造+模拟)

    题目链接:点击查看 题目大意:给出一个n*m的农场,其中'.'代表空地,'R'代表大米,现在有k只鸡需要分布在这个农场之中,需要满足以下条件: 每个方格都要被鸡占领 每只鸡至少占领一个方格 每只鸡占领 ...

  2. 【CodeForces 332B --- Maximum Absurdity】递推

    [CodeForces 332B --- Maximum Absurdity]递推 题目来源:点击进入[CodeForces 332B - Maximum Absurdity] Description ...

  3. 【CodeForces 1255B --- Fridge Lockers】

    [CodeForces 1255B --- Fridge Lockers] Description Hanh lives in a shared apartment. There are n peop ...

  4. 【CodeForces 1257C --- Dominated Subarray】

    [CodeForces 1257C --- Dominated Subarray] Description Let's call an array t dominated by value v in ...

  5. 【CodeForces 1253C --- Sweets Eating】DP

    [CodeForces 1253C --- Sweets Eating]DP Description Tsumugi brought n delicious sweets to the Light M ...

  6. 【Codeforces #167 Div1 Div2】Solutions

    [A. Dima and Friends] http://www.codeforces.com/contest/272/problem/A 题目大意:n+1个人出手指头,加起来再做类似约瑟夫的出圈,问 ...

  7. 【Codeforces Gym - 101635C Macarons 】【矩阵快速幂+状压】【dfs时间换空间】

    [链接] http://codeforces.com/gym/101635/attachments [题意] 求用1*1,1*2的方格填n*m的矩阵的方法数 [知识点] 状压dfs+矩阵快速幂 [分析 ...

  8. 【Codeforces Round #438 C】 Qualification Rounds

    [链接]h在这里写链接 [题意] 给你n个问题,每个人都知道一些问题. 然后让你选择一些问题,使得每个人知道的问题的数量,不超过这些问题的数量的一半. [题解] 想法题. 只要有两个问题. 这两个问题 ...

  9. 【Codeforces Global Round 23】B. Rebellion

    Codeforces Global Round 23中B. Rebellion Codeforces比赛记录 文章目录 题目链接: 一.B. Rebellion 题目意思: 上思路: 总结 B. Re ...

最新文章

  1. 程序员不仅能迅速脱单,还能用Python更加优雅的帮你脱单
  2. 详谈Javascript中的深拷贝和浅拷贝
  3. 万能门店小程序_门店小程序起名如何快速引流?
  4. iOS - UnitTests 单元测试
  5. Office 2010 Multi-language Pack download
  6. 使用IBM Blockchain Platform extension开发你的第一个fabric智能合约
  7. BootStrapJS——modal弹出框
  8. 别把数学想得太难,数学是一场游戏
  9. aspnetdb生成
  10. jRating五星评级
  11. ORA-27300错误
  12. ICML2018论文公布!一文了解机器学习最新热议论文和研究热点
  13. PHP获取一个数组的深度
  14. 全国耳鼻喉科 医院排名
  15. Too Files - 免费无限空间网络硬盘
  16. 基因组选择中如何清洗基因组数据
  17. 百度网盘 备份mysql数据库_利用百度云免费备份SQL数据库
  18. OSI七层网络模型概念
  19. 安装MikTeX-latex
  20. 第十届服务外包创新创业大赛总结

热门文章

  1. 我的世界服务器背景音乐修改,我的世界修改音乐方法
  2. 浅谈BCrypt密码加解密的使用
  3. 【人物专访】FreeICQ的CTO龙云飞[1001]访谈
  4. 物联网 | HASS+MQTT+树莓派室内监测小型物联网系统
  5. squirrelSql小松鼠数据库连接工具的安装以及连接informix(系列3,squirrelSql作为客户端连接)
  6. CCPC-Wannafly Comet OJ 夏季欢乐赛(2019)E.飞行棋(期望dp+矩阵快速幂)
  7. 博客相关 | 如何获取图片主题色并修改字体颜色
  8. [MATLAB]常微分方程数值求解(ode45 ode15s ode23 solver)
  9. HDU2066-一个人的旅行
  10. Android签名aab文件