编程介的小学生 2017-02-28 12:02 采纳率: 20.5%
浏览 1008
已采纳

Direct Subtraction

Statement of the Problem
Some algorithms on image processing are more efficient when applied to small patterns, such as 3 x 3 matrices. One way of decomposing a given figure into small components is to apply the operation of direct subtraction, which is described in the following.

Given a 0/1 matrix Amxm and a 0/1 matrix B3x3 we define the matrix C(m-2)x(m-2) = A - B obtained in the following way:

We call matrix C a valid direct subtraction of B from A if for every aij = 1 in matrix A, there is a 1 in matrix C which results from a subtraction of B from a submatrix of A containing aij, and the element of B which is subtracted from aij is equal to 1.

Example: Given matrices A and B,

the direct subtraction C = A - B is valid and is given by

Now, given matrices A and B,

The direct subtraction C = A - B is not valid and is given by

The objective of this problem is to determine if a matrix A can be transformed into a 3 x 3 matrix through a sequence of valid direct subtractions of, possibly different, 3 x 3 matrices.

Input Format

Several input instances are given. Each instance begins with the dimension 0 < n < 20 of the matrix to be decomposed. The following n lines describe the rows of that matrix, as a sequence of n 0's and 1's, with no blank spaces between them. The input ends with a line with a single 0.

Output Format

For each input instance your program must identify it by printing Instance i: (where i is the number of the instance) and, in the next line a message Yes or No for the case, resp. that the matrix is (resp. is not) decomposable.

Sample Input

5
01010
11111
01111
00111
00010
5
10001
00000
00100
00000
10001
0

Sample Output

Instance 1:
Yes
Instance 2:
No

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-06 15:15
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘