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 ...
随机推荐
- Vue 实战项目: 硅谷外卖(1)
第 1 章: 准备 1.1. 项目描述 1) 此项目为外卖 WebApp(SPA) 2) 包括商家, 商品, 购物车, 用户等多个子模块 3) 使用 Vue 全家桶+ES6+Webpack 等前端最新 ...
- 基础类封装-Requests库封装
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # @Time : 2020/03/18 23:37 # @Author : Tang Yiwei # @ ...
- POj3017 dp+单调队列优化
传送门 解题思路: 大力推公式:dp[i]=min(dp[k]+max(k+1,i)){k>=0&&k<i},max(j,i)记为max(a[h]){h>k& ...
- mysql截取函数常用方法 即mysql 字符串 截取-- - 最后带上java字符串截取规则比较
常用的mysql截取函数有:left(), right(), substring(), substring_index() 下面来一一说明一下: 1.左截取left(str, length) 说明:l ...
- Bat 脚本学习 (基础篇)
[转]Bat 脚本学习 2015-01-05 14:13 115人阅读 评论(0) 收藏 举报 基础部分: ============================================== ...
- python初学(三)
1.以软科中国最好大学排名为分析对象,基于requests库和bs4库编写爬虫程序,对2015年至2019年间的中国大学排名数据进行爬取,并按照排名先后顺序输出不同年份的前10位大学信息,要求对输出结 ...
- ADO.NET 事务控制
在ADO.NET 中,可以使用Connection 和Transaction 对象来控制事务.若要执行事务,请执行下列操作: 1.调用Connection 对象的BeginTransaction 方法 ...
- abp(net core)+easyui+efcore实现仓储管理系统——入库管理之九(四十五)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- MySQL不香吗,为什么还要有noSQL?
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是分布式专题的第14篇文章,我们一起来看看NoSQL数据库. 其实我很早就想写写分布式数据库相关的文章,既是我现在正在学习的,也是我很感 ...
- Spring Cloud 系列之 Sleuth 链路追踪(二)
本篇文章为系列文章,未读第一集的同学请猛戳这里:Spring Cloud 系列之 Sleuth 链路追踪(一) 本篇文章讲解 Sleuth 基于 Zipkin 存储链路追踪数据至 MySQL,Elas ...