CF 1736A - Make A Equal to B
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 個元素的數(shù)組 a 和 b,每個元素不是 0 就是 1。
您可以進行 2 種操作。
選擇一個索引 i 并將 ai 更改為 1?ai。
根據(jù)需要重新排列數(shù)組 a。
求使 a 等于 b 所需的最少運算次數(shù)。
輸入
每個測試包含多個測試用例。 第一行包含一個整數(shù) t (1≤t≤400) — 測試用例的數(shù)量。 測試用例的描述如下。
每個測試用例的第一行包含一個整數(shù) n (1≤n≤100) — 數(shù)組 a 和 b 的長度。
每個測試用例的第二行包含n個空格分隔的整數(shù)a1,a2,…,an(ai為0或1),代表數(shù)組a。
每個測試用例的第三行包含n個空格分隔的整數(shù)b1,b2,…,bn(bi為0或1),代表數(shù)組b。
輸出
對于每個測試用例,打印使 a 等于 b 所需的最少操作數(shù)。
例子
就是先判斷2個數(shù)組之間的差異數(shù)量,然后 將2個數(shù)組排序,看差異的數(shù)量+1,2個取最小值即可;
下面是代碼: