欢迎光临散文网 会员登陆 & 注册

CF 1736A - Make A Equal to B

2023-06-23 13:52 作者:您是打尖儿还是住店呢  | 我要投稿

You are given two arrays a and b of n elements, each element is either 0 or 1.

You can make operations of 2 kinds.

Pick an index i and change ai to 1−ai.

Rearrange the array a however you want.

Find the minimum number of operations required to make a equal to b.

Input

Each test contains multiple test cases. The first line contains a single integer t (1≤t≤400) — the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer n (1≤n≤100) — the length of the arrays a and b.

The second line of each test case contains n space-separated integers a1,a2,…,an (ai is 0 or 1), representing the array a.

The third line of each test case contains n space-separated integers b1,b2,…,bn (bi is 0 or 1), representing the array b.

Output

For each test case, print the minimum number of operations required to make a equal to b.

Example

------------------------------------------------------

中文:

给定两个包含 n 个元素的数组 a 和 b,每个元素不是 0 就是 1。

您可以进行 2 种操作。

选择一个索引 i 并将 ai 更改为 1−ai。

根据需要重新排列数组 a。

求使 a 等于 b 所需的最少运算次数。

输入

每个测试包含多个测试用例。 第一行包含一个整数 t (1≤t≤400) — 测试用例的数量。 测试用例的描述如下。

每个测试用例的第一行包含一个整数 n (1≤n≤100) — 数组 a 和 b 的长度。

每个测试用例的第二行包含n个空格分隔的整数a1,a2,…,an(ai为0或1),代表数组a。

每个测试用例的第三行包含n个空格分隔的整数b1,b2,…,bn(bi为0或1),代表数组b。

输出

对于每个测试用例,打印使 a 等于 b 所需的最少操作数。

例子

就是先判断2个数组之间的差异数量,然后 将2个数组排序,看差异的数量+1,2个取最小值即可;

下面是代码:


CF 1736A - Make A Equal to B的评论 (共 条)

分享到微博请遵守国家法律