CF2166A.Same Difference

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string ss of length nn, consisting of lowercase letters.

In one operation, you can select an integer ii such that 1≤i<n1\leq i \lt n and change sis_i into si+1s_{i+1}.

What is the minimum number of operations needed to make every character the same? It can be proved that this is always possible.

给你一个长度为 nn 的字符串 ss,其中仅包含小写字母。

在一次操作中,你可以选择一个整数 ii,满足 1≤i<n1 \leq i < n,并将 sis_i 修改为 si+1s_{i+1}。

使字符串中所有字符都相同的最少操作次数是多少?可以证明该目标总能实现。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤201 \le t \le 20). The description of the test cases follows.

The first line of each test case contains an integer nn (2≤n≤1002\le n\le 100) — the length of the string.

The following line contains a string ss of length nn, consisting of lowercase letters.

It is guaranteed that the sum of nn over all test cases does not exceed 100100.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤201 \le t \le 20)。随后是测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1002\le n\le 100)—— 字符串的长度。

接下来的一行包含一个长度为 nn 的字符串 ss,由小写字母组成。

保证所有测试用例的 nn 之和不超过 100100。

输出格式

For each test case, output a single integer — the minimum number of operations needed to make every character the same.

对于每个测试用例,输出一个整数——使所有字符相同所需的最少操作次数。

输入输出样例

  • 输入#1

    5
    3
    qwq
    2
    aa
    4
    test
    5
    abbac
    6
    abcabc

    输出#1

    1
    0
    2
    4
    4

说明/提示

In the first test case, you can change s2s_2 to s3s_3 using 11 operation to reach the goal.

In the third test case, you can change s3s_3 to s4s_4 and then change s2s_2 to s3s_3, using 22 operations in total. It can be proved that the answer is not less than 22.

在第一个测试用例中,你可以通过 11 次操作将 s2s_2 改为 s3s_3,从而达成目标。

在第三个测试用例中,你可以先将 s3s_3 改为 s4s_4,再将 s2s_2 改为 s3s_3,总共需要 22 次操作。可以证明答案不小于 22。

输入解题思路,AI测评打分。不知道怎么写?

首页