CF1701A.Grass Field
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a field of size 2×2. Each cell of this field can either contain grass or be empty. The value ai,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 ax,i and all cells ai,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 ai,j zeros).
You have to answer t independent test cases.
有一个大小为 2×2 的场地。该场地的每个格子要么长有草,要么为空。若格子 (i,j) 中有草,则其值 ai,j 为 1;否则为 0。
在一次操作中,你可以选择一行和一列,并割掉该行与该列中的所有草。换言之,你选定行 x 和列 y,然后割掉所有格子 ax,i(其中 i=1,2)以及所有格子 ai,y(其中 i=1,2)中的草。一旦某格子中的草被割掉,该格子即变为空(即其值变为 0)。
你的任务是求出割掉场地上所有非空格子中草所需的最少操作次数(即令所有 ai,j=0)。
你需要回答 t 个相互独立的测试用例。
输入格式
The first line of the input contains one integer t (1≤t≤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 ai,j. If ai,j=0 then the cell (i,j) is empty, and if ai,j=1 the cell (i,j) contains grass.
输入的第一行包含一个整数 t(1≤t≤16),表示测试用例的数量。随后是 t 个测试用例。
每个测试用例由两行组成,每行包含两个整数。第 i 行的第 j 个整数为 ai,j。若 ai,j=0,则单元格 (i,j) 为空;若 ai,j=1,则单元格 (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,j zeros) in the corresponding test case.
对于每个测试用例,输出一个整数——即在对应测试用例中,将田地中所有非空单元格的草全部割完(即令所有 ai,j 变为 0)所需的最少移动次数。
输入输出样例
输入#1
3 0 0 0 0 1 0 0 1 1 1 1 1
输出#1
0 1 2
输入解题思路,AI测评打分。不知道怎么写?