CF1921B.Arranging Cats

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

In order to test the hypothesis about the cats, the scientists must arrange the cats in the boxes in a specific way. Of course, they would like to test the hypothesis and publish a sensational article as quickly as possible, because they are too engrossed in the next hypothesis about the phone's battery charge.

Scientists have nn boxes in which cats may or may not sit. Let the current state of the boxes be denoted by the sequence b1,…,bnb_1, \dots, b_n: bi=1b_i = 1 if there is a cat in box number ii, and bi=0b_i = 0 otherwise.

Fortunately, the unlimited production of cats has already been established, so in one day, the scientists can perform one of the following operations:

  • Take a new cat and place it in a box (for some ii such that bi=0b_i = 0, assign bi=1b_i = 1).
  • Remove a cat from a box and send it into retirement (for some ii such that bi=1b_i = 1, assign bi=0b_i = 0).
  • Move a cat from one box to another (for some i,ji, j such that bi=1,bj=0b_i = 1, b_j = 0, assign bi=0,bj=1b_i = 0, b_j = 1).

It has also been found that some boxes were immediately filled with cats. Therefore, the scientists know the initial position of the cats in the boxes s1,…,sns_1, \dots, s_n and the desired position f1,…,fnf_1, \dots, f_n.

Due to the large amount of paperwork, the scientists do not have time to solve this problem. Help them for the sake of science and indicate the minimum number of days required to test the hypothesis.

为了验证关于猫的假设,科学家必须以特定方式将猫安排在盒子中。当然,他们希望尽快验证该假设并发表一篇轰动性的文章,因为他们已全身心投入到下一个关于手机电池电量的假设中。

科学家共有 nn 个盒子,每个盒子中可能有猫,也可能没有猫。设当前盒子的状态用序列 b1,…,bnb_1, \dots, b_n 表示:若第 ii 个盒子中有猫,则 bi=1b_i = 1;否则 bi=0b_i = 0。

幸运的是,猫的无限量产技术已经实现,因此科学家每天最多可执行以下三种操作之一:

  • 取一只新猫放入某个空盒子中(即对某个满足 bi=0b_i = 0 的 ii,令 bi=1b_i = 1);
  • 将某只盒中的猫移出并使其“退休”(即对某个满足 bi=1b_i = 1 的 ii,令 bi=0b_i = 0);
  • 将一只猫从一个盒子移动到另一个空盒子中(即对某对满足 bi=1b_i = 1 且 bj=0b_j = 0 的 i,ji, j,令 bi=0b_i = 0 且 bj=1b_j = 1)。

此外,研究人员发现某些盒子已被猫立即占据。因此,科学家已知猫的初始分布 s1,…,sns_1, \dots, s_n 和目标分布 f1,…,fnf_1, \dots, f_n。

由于大量文书工作,科学家们无暇解决此问题。请为科学事业提供帮助,指出验证该假设所需的最少天数。

输入格式

Each test consists of several test cases. The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. This is followed by descriptions of the test cases.

Each test case consists of three lines.

The first line of each test case contains a single integer nn (1≤n≤1051 \le n \le 10^5) — the number of boxes.

The second line of each test case contains a string ss of nn characters, where the ii-th character is '1' if there is a cat in the ii-th box and '0' otherwise.

The third line of each test case contains a string ff of nn characters, where the ii-th character is '1' if there should be a cat in the ii-th box and '0' otherwise.

It is guaranteed that in a test the sum of nn over all test cases does not exceed 10510^5.

每个测试包含若干测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例由三行组成。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5),表示盒子的数量。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss,其中第 ii 个字符为 '1' 表示第 ii 个盒子中有一只猫,为 '0' 则表示没有猫。

每个测试用例的第三行包含一个长度为 nn 的字符串 ff,其中第 ii 个字符为 '1' 表示第 ii 个盒子中应当有一只猫,为 '0' 则表示不应有猫。

保证在一个测试中,所有测试用例的 nn 值之和不超过 10510^5。

输出格式

For each test case, output a single integer on a separate line — the minimum number of operations required to obtain the desired position from the initial position. It can be shown that a solution always exists.

对于每个测试用例,在单独一行输出一个整数——从初始位置到达目标位置所需的最少操作次数。可以证明解总是存在的。

输入输出样例

  • 输入#1

    6
    5
    10010
    00001
    1
    1
    1
    3
    000
    111
    4
    0101
    1010
    3
    100
    101
    8
    10011001
    11111110

    输出#1

    2
    0
    3
    2
    1
    4

说明/提示

In the first test case, you can first move the cat from the first box to the fifth, and then remove the cat from the fourth box.

In the second test case, there is nothing to do — the only cat is already sitting in the correct box.

In the third test case of input data, it takes three days to place a cat in each box.

在第一个测试用例中,你可以先将第一只盒子中的猫移动到第五个盒子,然后从第四个盒子中移除猫。

在第二个测试用例中,无需任何操作——唯一的一只猫已经坐在正确的盒子中。

在输入数据的第三个测试用例中,需要三天时间才能使每个盒子中都有一只猫。

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

首页