Codeforce 1255 Round #601 (Div. 2)D. Feeding Chicken (模拟)
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;
}
Codeforce 1255 Round #601 (Div. 2)D. Feeding Chicken (模拟)的更多相关文章
- Codeforce 1255 Round #601 (Div. 2) C. League of Leesins (大模拟)
Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the L ...
- Codeforce 1255 Round #601 (Div. 2)B. Fridge Lockers(思维)
Hanh lives in a shared apartment. There are nn people (including Hanh) living there, each has a priv ...
- Codeforce 1255 Round #601 (Div. 2) A. Changing Volume (贪心)
Bob watches TV every day. He always sets the volume of his TV to bb. However, today he is angry to f ...
- Codeforces Round #601 (Div. 2) D Feeding Chicken
//为了连贯,采取一条路形式,从第一行开始 也就是s型 #include <bits/stdc++.h> using namespace std; ; char str[MAXN][MAX ...
- Codeforces Round #601 (Div. 2)D(蛇形模拟)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; vector<char>an ...
- 【cf比赛记录】Codeforces Round #601 (Div. 2)
Codeforces Round #601 (Div. 2) ---- 比赛传送门 周二晚因为身体不适鸽了,补题补题 A // http://codeforces.com/contest/1255/p ...
- Codeforces Round #601 (Div. 2)
传送门 A. Changing Volume 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/19 22:37:33 */ #include ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- codeforce Codeforces Round #201 (Div. 2)
cf 上的一道好题: 首先发现能生成所有数字-N 判断奇偶 就行了,但想不出来,如何生成所有数字,解题报告 说是 所有数字的中最大的那个数/所有数字的最小公倍数,好像有道理:纪念纪念: #incl ...
随机推荐
- OS-DOS/CMD/Windows/各类软件快捷键等使用总结
一.快捷键 很多软件的快捷键使用相通,在不确定的情况下,先试试其他软件的快捷键的使用方法 Windows电脑快捷键 HP惠普笔记本 win+E 打开文件管器 win+D 显示桌面 win+L 锁计算机 ...
- python3(十六) sorted
# sorted()函数list进行排序: L = sorted([36, 5, -12, 9, -21]) print(L) # [-21, -12, 5, 9, 36] # 可以看到默认是按照升序 ...
- Linq中带有迭代索引的Select扩展方法,为啥知道的人不多呢?
一:背景 昨天在看C#函数式编程这本书的时候,有一处让我干着急,需求是这样: 给多行文字加上数字列表项. 针对这个需求你会如何快捷高效的给每个项目加上数字编号呢? 我看书中是这样实现的,如下代码 pu ...
- Netty服务端接收的新连接是如何绑定到worker线程池的?
更多技术分享可关注我 前言 原文:Netty服务端接收的新连接是如何绑定到worker线程池的? 前面分析Netty服务端检测新连接的过程提到了NioServerSocketChannel读完新连接后 ...
- BFC的理解与应用
什么是BFC(Block formatting contexts) BFC的通俗理解: 首先BFC是一个名词,是一个独立的布局环境,我们可以理解为一个箱子(实际上是看不见摸不着的),箱子里面物品的摆放 ...
- 跳转语句break与continue的使用环境
break:改变程序控制流 常用于do-while.while.for .switch循环中,终止某个循环,程序跳转到循环块外的下一条语句 continue:跳出本次循环,进入下一次循环
- SVG案例:动态去创建元素createElementNS
案例一: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...
- java多线程3:原子性,可见性,有序性
概念 在了解线程安全问题之前,必须先知道为什么需要并发,并发给我们带来什么问题. 为什么需要并发,多线程? 时代的召唤,为了更充分的利用多核CPU的计算能力,多个线程程序可通过提高处理器的资源利用率来 ...
- 如何在非 sudo 用户下运行 docker 命令?
当我们在一台 Linux 系统中安装了 Docker 后, 有时候会遇到下面这样的错误, 我们在运行 docker 的命令时必须加上 sudo, 例如: sudo docker ps, 但是我们其实更 ...
- 常问的MySQL面试题整理
char.varchar 的区别是什么? varchar是变长而char的长度是固定的.如果创建的列是固定大小的,你会得到更好的性能 truncate 和 delete 的区别是什么? delete ...