CF1701A.Grass Field

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is a field of size 2×22 \times 2. Each cell of this field can either contain grass or be empty. The value ai,ja_{i, j} is 11 if the cell (i,j)(i, j) contains grass, or 00 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 xx and the column yy, then you cut the grass in all cells ax,ia_{x, i} and all cells ai,ya_{i, y} for all ii from 11 to 22. After you cut the grass from a cell, it becomes empty (i. e. its value is replaced by 00).

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 ai,ja_{i, j} zeros).

You have to answer tt independent test cases.

有一个大小为 2×22 \times 2 的场地。该场地的每个格子要么长有草,要么为空。若格子 (i,j)(i, j) 中有草,则其值 ai,ja_{i, j} 为 11;否则为 00。

在一次操作中,你可以选择一行和一列,并割掉该行与该列中的所有草。换言之,你选定行 xx 和列 yy,然后割掉所有格子 ax,ia_{x, i}(其中 i=1,2i = 1, 2)以及所有格子 ai,ya_{i, y}(其中 i=1,2i = 1, 2)中的草。一旦某格子中的草被割掉,该格子即变为空(即其值变为 00)。

你的任务是求出割掉场地上所有非空格子中草所需的最少操作次数(即令所有 ai,j=0a_{i, j} = 0)。

你需要回答 tt 个相互独立的测试用例。

输入格式

The first line of the input contains one integer tt (1≤t≤161 \le t \le 16) — the number of test cases. Then tt test cases follow.

The test case consists of two lines, each of these lines contains two integers. The jj-th integer in the ii-th row is ai,ja_{i, j}. If ai,j=0a_{i, j} = 0 then the cell (i,j)(i, j) is empty, and if ai,j=1a_{i, j} = 1 the cell (i,j)(i, j) contains grass.

输入的第一行包含一个整数 tt(1≤t≤161 \le t \le 16),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例由两行组成,每行包含两个整数。第 ii 行的第 jj 个整数为 ai,ja_{i, j}。若 ai,j=0a_{i, j} = 0,则单元格 (i,j)(i, j) 为空;若 ai,j=1a_{i, j} = 1,则单元格 (i,j)(i, j) 中有草。

输出格式

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 ai,ja_{i, j} zeros) in the corresponding test case.

对于每个测试用例,输出一个整数——即在对应测试用例中,将田地中所有非空单元格的草全部割完(即令所有 ai,ja_{i, j} 变为 0)所需的最少移动次数。

输入输出样例

  • 输入#1

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

    输出#1

    0
    1
    2

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

首页