A15316 | Image
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You have an image file of size $2 \times 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?
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?
输入格式
The first line contains one integer $t$ ( $1 \le t \le 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.
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.
输出格式
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.
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted