310217: CF1797B. Li Hua and Pattern

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

Description

Li Hua and Pattern

题意翻译

李华有一个大小为 $n\times n$ 的图案,每个格子为蓝色或红色。他可以进行**恰好 $k$ 次**操作。每一次操作,他选择一个格子并改变其颜色(红变蓝,蓝变红)。每个格子可以被选择任意多次。是否可能使得操作后的图案中心对称? 假如你是李华,请解决这一问题。 ([全场中文题面](https://www.cnblogs.com/ruierqwq/p/CF1797-CHN-statement.html))

题目描述

Li Hua has a pattern of size $ n\times n $ , each cell is either blue or red. He can perform exactly $ k $ operations. In each operation, he chooses a cell and changes its color from red to blue or from blue to red. Each cell can be chosen as many times as he wants. Is it possible to make the pattern, that matches its rotation by $ 180^{\circ} $ ? Suppose you were Li Hua, please solve this problem.

输入输出格式

输入格式


The first line contains the single integer $ t $ ( $ 1 \le t \le 100 $ ) — the number of test cases. The first line of each test case contains two integers $ n,k $ ( $ 1\le n\le 10^3,0\le k \le 10^9 $ ) — the size of the pattern and the number of operations. Each of next $ n $ lines contains $ n $ integers $ a_{i,j} $ ( $ a_{i,j}\in\{0,1\} $ ) — the initial color of the cell, $ 0 $ for blue and $ 1 $ for red. It's guaranteed that sum of $ n $ over all test cases does not exceed $ 10^3 $ .

输出格式


For each set of input, print "YES" if it's possible to make the pattern, that matches its rotation by $ 180^{\circ} $ after applying exactly $ k $ of operations, and "NO" otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

输入输出样例

输入样例 #1

3
4 0
1 1 1 1
0 0 0 1
1 0 1 0
1 1 1 1
4 3
1 0 1 1
1 0 0 0
0 1 0 1
1 1 0 1
5 4
0 0 0 0 0
0 1 1 1 1
0 1 0 0 0
1 1 1 1 1
0 0 0 0 0

输出样例 #1

NO
YES
YES

说明

In test case 1, you can't perform any operation. The pattern after rotation is on the right. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1797B/debd4989c6daceeecb5305f7cb7ec257866c6bf5.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1797B/187295f499fcefe17d924d6eb93da50e9773c4d3.png)In test case 2, you can perform operations on $ (2,1),(3,2),(3,4) $ . The pattern after operations is in the middle and the pattern after rotation is on the right. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1797B/0c0aed7c9c5dddd78137bdc2f8654231a7026420.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1797B/3b36bd2af8c0789e62f808d71f3af4107dad02c2.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1797B/3b36bd2af8c0789e62f808d71f3af4107dad02c2.png)

Input

题意翻译

李华有一个大小为 $n\times n$ 的图案,每个格子为蓝色或红色。他可以进行**恰好 $k$ 次**操作。每一次操作,他选择一个格子并改变其颜色(红变蓝,蓝变红)。每个格子可以被选择任意多次。是否可能使得操作后的图案中心对称? 假如你是李华,请解决这一问题。 ([全场中文题面](https://www.cnblogs.com/ruierqwq/p/CF1797-CHN-statement.html))

Output

**题目大意**:

李华有一个大小为 $n \times n$ 的图案,每个格子为蓝色或红色。他可以进行**恰好 $k$ 次**操作。每一次操作,他可以选择一个格子并改变其颜色(红变蓝,蓝变红)。每个格子可以被选择任意多次。需要判断是否可能通过这些操作使得操作后的图案中心对称。

**输入输出数据格式**:

- **输入格式**:
- 第一行包含一个整数 $t$($1 \le t \le 100$)——测试用例的数量。
- 每个测试用例的第一行包含两个整数 $n, k$($1 \le n \le 10^3, 0 \le k \le 10^9$)——图案的大小和操作次数。
- 接下来的 $n$ 行,每行包含 $n$ 个整数 $a_{i,j}$($a_{i,j} \in \{0,1\}$)——格子的初始颜色,$0$ 表示蓝色,$1$ 表示红色。
- 保证所有测试用例的 $n$ 之和不超过 $10^3$。

- **输出格式**:
- 对于每个测试用例,如果可能通过恰好 $k$ 次操作使得图案中心对称,则输出 "YES",否则输出 "NO"。
- 输出答案时大小写不敏感,例如 "yEs"、"yes"、"Yes" 和 "YES" 都会被认为是肯定的回答。**题目大意**: 李华有一个大小为 $n \times n$ 的图案,每个格子为蓝色或红色。他可以进行**恰好 $k$ 次**操作。每一次操作,他可以选择一个格子并改变其颜色(红变蓝,蓝变红)。每个格子可以被选择任意多次。需要判断是否可能通过这些操作使得操作后的图案中心对称。 **输入输出数据格式**: - **输入格式**: - 第一行包含一个整数 $t$($1 \le t \le 100$)——测试用例的数量。 - 每个测试用例的第一行包含两个整数 $n, k$($1 \le n \le 10^3, 0 \le k \le 10^9$)——图案的大小和操作次数。 - 接下来的 $n$ 行,每行包含 $n$ 个整数 $a_{i,j}$($a_{i,j} \in \{0,1\}$)——格子的初始颜色,$0$ 表示蓝色,$1$ 表示红色。 - 保证所有测试用例的 $n$ 之和不超过 $10^3$。 - **输出格式**: - 对于每个测试用例,如果可能通过恰好 $k$ 次操作使得图案中心对称,则输出 "YES",否则输出 "NO"。 - 输出答案时大小写不敏感,例如 "yEs"、"yes"、"Yes" 和 "YES" 都会被认为是肯定的回答。

加入题单

算法标签: