102972: [Atcoder]ABC297 C - PC on the Table
Description
Score : $300$ points
Problem Statement
Planning to place many PCs in his room, Takahashi has decided to write a code that finds how many PCs he can place in his room.
You are given $H$ strings $S_1,S_2,\ldots,S_H$, each of length $W$, consisting of .
and T
.
Takahashi may perform the following operation any number of times (possibly zero):
- Choose integers satisfying $1\leq i \leq H$ and $1 \leq j \leq W-1$ such that the $j$-th and $(j+1)$-th characters of $S_i$ are both
T
. Replace the $j$-th character of $S_i$ withP
, and $(j+1)$-th withC
.
He tries to maximize the number of times he performs the operation. Find possible resulting $S_1,S_2,\ldots,S_H$.
Constraints
- $1\leq H \leq 100$
- $2\leq W \leq 100$
- $H$ and $W$ are integers.
- $S_i$ is a string of length $W$ consisting of
.
andT
.
Input
The input is given from Standard Input in the following format:
$H$ $W$ $S_1$ $S_2$ $\vdots$ $S_H$
Output
Print a sequence of strings, $S_1,S_2,\ldots,S_H$, separated by newlines, possibly resulting from maximizing the number of times he performs the operation.
If multiple solutions exist, print any of them.
Sample Input 1
2 3 TTT T.T
Sample Output 1
PCT T.T
He can perform the operation at most once.
For example, an operation with $(i,j)=(1,1)$ makes $S_1$ PCT
.
Sample Input 2
3 5 TTT.. .TTT. TTTTT
Sample Output 2
PCT.. .PCT. PCTPC
Input
题意翻译
给你一个二维的字符矩阵,如果在同一行上出现 `TT`,将其更改为 `PC`,输出最终的矩阵。Output
分数:300分
问题描述
计划在他的房间里放置许多台式机,高桥决定编写一个代码,以找出他可以在他的房间里放置多少台式机。
给你$H$个字符串$S_1,S_2,\ldots,S_H$,每个长度为$W$,由.
和T
组成。
高桥可以执行任意次数(包括零次)以下操作:
- 选择满足$1\leq i \leq H$和$1 \leq j \leq W-1$的整数,使得$S_i$的第$j$个和第$(j+1)$个字符都是
T
。 将$S_i$的第$j$个字符替换为P
,并将第$(j+1)$个字符替换为C
。
他试图最大化执行该操作的次数。 找出可能的结果字符串$S_1,S_2,\ldots,S_H$。
约束
- $1\leq H \leq 100$
- $2\leq W \leq 100$
- $H$和$W$是整数。
- $S_i$是一个长度为$W$的字符串,由
.
和T
组成。
输入
输入从标准输入以以下格式给出:
$H$ $W$ $S_1$ $S_2$ $\vdots$ $S_H$
输出
以换行符分隔的字符串序列$S_1,S_2,\ldots,S_H$,可能是通过最大化执行该操作的次数得出的结果。
如果有多个解决方案,打印其中任何一个。
样例输入1
2 3 TTT T.T
样例输出1
PCT T.T
他最多可以执行一次操作。
例如,选择$(i,j)=(1,1)$的操作会使$S_1$变为PCT
。
样例输入2
3 5 TTT..