309572: CF1701A. Grass Field

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Grass Field

题意翻译

给出一个 $2 \times 2$ 的矩阵,矩阵的值都是 $0$ 和 $1$,定义一次操作:选择一个点,将其所在的行和列的点的值全部修改为 $0$,求最少几次操作将整个矩阵修改为 $0$。 by @Leonador

题目描述

There is a field of size $ 2 \times 2 $ . Each cell of this field can either contain grass or be empty. The value $ a_{i, j} $ is $ 1 $ if the cell $ (i, j) $ contains grass, or $ 0 $ otherwise. In one move, you can choose one row and one column and cut all the grass in this row and this column. In other words, you choose the row $ x $ and the column $ y $ , then you cut the grass in all cells $ a_{x, i} $ and all cells $ a_{i, y} $ for all $ i $ from $ 1 $ to $ 2 $ . After you cut the grass from a cell, it becomes empty (i. e. its value is replaced by $ 0 $ ). Your task is to find the minimum number of moves required to cut the grass in all non-empty cells of the field (i. e. make all $ a_{i, j} $ zeros). You have to answer $ t $ independent test cases.

输入输出格式

输入格式


The first line of the input contains one integer $ t $ ( $ 1 \le t \le 16 $ ) — the number of test cases. Then $ t $ test cases follow. The test case consists of two lines, each of these lines contains two integers. The $ j $ -th integer in the $ i $ -th row is $ a_{i, j} $ . If $ a_{i, j} = 0 $ then the cell $ (i, j) $ is empty, and if $ a_{i, j} = 1 $ the cell $ (i, j) $ contains grass.

输出格式


For each test case, print one integer — the minimum number of moves required to cut the grass in all non-empty cells of the field (i. e. make all $ a_{i, j} $ zeros) in the corresponding test case.

输入输出样例

输入样例 #1

3
0 0
0 0
1 0
0 1
1 1
1 1

输出样例 #1

0
1
2

Input

题意翻译

给出一个 $2 \times 2$ 的矩阵,矩阵的值都是 $0$ 和 $1$,定义一次操作:选择一个点,将其所在的行和列的点的值全部修改为 $0$,求最少几次操作将整个矩阵修改为 $0$。 by @Leonador

Output

**题目大意:**
题目要求对于一个 $2 \times 2$ 的矩阵,矩阵中的每个元素值为 $0$ 或 $1$,定义一个操作:选择一个点,将这个点所在的行和列的所有元素值都修改为 $0$,需要求出最少的操作次数,使得整个矩阵的所有元素值都变为 $0$。

**输入输出数据格式:**
- **输入格式:**
- 第一行包含一个整数 $t$($1 \le t \le 16$),表示测试用例的数量。
- 接下来 $t$ 个测试用例,每个测试用例由两行组成,每行包含两个整数。第 $j$ 个整数在第 $i$ 行表示矩阵中元素 $a_{i, j}$ 的值。如果 $a_{i, j} = 0$,则表示单元格 $(i, j)$ 为空;如果 $a_{i, j} = 1$,则表示单元格 $(i, j)$ 含有草。
- **输出格式:**
- 对于每个测试用例,输出一行,包含一个整数,表示将该测试用例中的矩阵所有非空单元格的草割掉所需的最少操作次数(即使所有 $a_{i, j}$ 变为 $0$)。

**输入输出样例:**
- **输入样例 #1:**
```
3
0 0
0 0
1 0
0 1
1 1
1 1
```
- **输出样例 #1:**
```
0
1
2
```**题目大意:** 题目要求对于一个 $2 \times 2$ 的矩阵,矩阵中的每个元素值为 $0$ 或 $1$,定义一个操作:选择一个点,将这个点所在的行和列的所有元素值都修改为 $0$,需要求出最少的操作次数,使得整个矩阵的所有元素值都变为 $0$。 **输入输出数据格式:** - **输入格式:** - 第一行包含一个整数 $t$($1 \le t \le 16$),表示测试用例的数量。 - 接下来 $t$ 个测试用例,每个测试用例由两行组成,每行包含两个整数。第 $j$ 个整数在第 $i$ 行表示矩阵中元素 $a_{i, j}$ 的值。如果 $a_{i, j} = 0$,则表示单元格 $(i, j)$ 为空;如果 $a_{i, j} = 1$,则表示单元格 $(i, j)$ 含有草。 - **输出格式:** - 对于每个测试用例,输出一行,包含一个整数,表示将该测试用例中的矩阵所有非空单元格的草割掉所需的最少操作次数(即使所有 $a_{i, j}$ 变为 $0$)。 **输入输出样例:** - **输入样例 #1:** ``` 3 0 0 0 0 1 0 0 1 1 1 1 1 ``` - **输出样例 #1:** ``` 0 1 2 ```

加入题单

算法标签: