CF1721A.Image
入门
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have an image file of size 2×2, consisting of 4 pixels. Each pixel can have one of 26 different colors, denoted by lowercase Latin letters.
You want to recolor some of the pixels of the image so that all 4 pixels have the same color. In one move, you can choose no more than two pixels of the same color and paint them into some other color (if you choose two pixels, both should be painted into the same color).
What is the minimum number of moves you have to make in order to fulfill your goal?
你有一张大小为 2×2 的图像文件,共包含 4 个像素。每个像素可以呈现 26 种不同颜色之一,用小写拉丁字母表示。
你想对图像中的一些像素重新着色,使得全部 4 个像素具有相同的颜色。每次操作中,你可以选择至多两个颜色相同的像素,并将它们涂成某种其他颜色(若选择两个像素,则两者必须涂成同一种颜色)。
为达成目标,你至少需要执行多少次操作?
输入格式
The first line contains one integer t (1≤t≤1000) — the number of test cases.
Each test case consists of two lines. Each of these lines contains two lowercase letters of Latin alphabet without any separators, denoting a row of pixels in the image.
第一行包含一个整数 t(1≤t≤1000)—— 表示测试用例的数量。
每个测试用例由两行组成。每行包含两个无分隔符的小写拉丁字母,表示图像中的一行像素。
输出格式
For each test case, print one integer — the minimum number of moves you have to make so that all 4 pixels of the image have the same color.
对于每个测试用例,输出一个整数——使图像中全部 4 个像素颜色相同的最少移动次数。
输入输出样例
输入#1
5 rb br cc wb aa aa ab cd yy xx
输出#1
1 2 0 3 1
说明/提示
Let's analyze the test cases of the example.
In the first test case, you can paint the bottom left pixel and the top right pixel (which share the same color) into the color r, so all pixels have this color.
In the second test case, two moves are enough:
- paint both top pixels, which have the same color c, into the color b;
- paint the bottom left pixel into the color b.
In the third test case, all pixels already have the same color.
In the fourth test case, you may leave any of the pixels unchanged, and paint all three other pixels into the color of that pixel in three moves.
In the fifth test case, you can paint both top pixels into the color x.
我们来分析示例中的测试用例。
在第一个测试用例中,你可以将左下角像素和右上角像素(二者颜色相同)涂成颜色 r,从而使所有像素都变为该颜色。
在第二个测试用例中,只需两步操作即可完成:
- 将两个顶部像素(二者颜色均为
c)涂成颜色b; - 将左下角像素涂成颜色
b。
在第三个测试用例中,所有像素原本就具有相同的颜色。
在第四个测试用例中,你可以任选一个像素保持不变,然后在三步操作内将其余三个像素全部涂成该像素的颜色。
在第五个测试用例中,你可以将两个顶部像素都涂成颜色 x。
输入解题思路,AI测评打分。不知道怎么写?