题目详情

阅读以下说明和算法,完善算法并回答问题,将解答写在答题纸的对应栏内。

【说明】

假设以二维数组G[1. . m, 1. . n]表示一幅图像各像素的颜色,则G[i, j]表示区域中点(i,j)处的颜色,颜色值为0到k的整数。

下面的算法将指定点(i0, j0)所在的同色邻接区域的颜色置换为给定的颜色值。约定所有与点(i0, j0)同色的上、下、左、右可连通的点组成同色邻接区域。

例如,一幅8*9像素的图像如图1-1所示。设用户指定点(3,5),其颜色值为0,此时其上方(2,5)、下方(4,5)、右方(3,6)邻接点的颜色值都为0,因此这些点属于点(3,5)所在的同色邻接区域,再从上、下、左、右四个方向进行扩展,可得出该同色邻接区域的其他点(见图1-1中的阴影部分)。将上述同色区域的颜色替换为颜色值7所得的新图像如图1-2所示。

初级程序员,章节练习,基础复习,案例分析

【算法】

输入:矩阵G,点的坐标(i0, j0),新颜色值newcolor。

输出:点(i0, j0)所在同色邻接区域的颜色置换为newcolor之后的矩阵G。

算法步骤(为规范算法,规定该算法只在第七步后结束):

第一步:若点(i0, j0,)的颜色值与新颜色值newcolor相同,则 (1) ;

第二步:点(i0, j0)的颜色值→oldcolor;创建栈S,并将点坐标(i0,j0)入栈;

第三步:若 (2) ,则转第七步;

第四步:栈顶元素出栈->(x, Y),并 (3) ;

第五步:1)若点(x, y-1)在图像中且G[x, y-1]等于oldcolor,则(x, y-1)入栈S;

2)若点(x, y+1)在图像中且G[x, y+1]等于oldcolor,则(x, Y+ I)入栈S;

3)若点(x-1, y)在图像中且G[x-1, y]等于oldcolor,则(x-1, y)入栈S;

4)若点(x+1, y)在图像中且G[x+l, y]等于oldcolor,则(x+1, y)入栈S;

第六步:转 (4) ;

第七步:算法结束。

【问题】

是否可以将算法中的栈换成队列?回答: (5) 。

正确答案及解析

正确答案
解析

初级程序员,章节练习,初级程序员真题卷

你可能感兴趣的试题

单选题

The Internet of( 1)(IoT) describes physical objects that are embedded with Sensor,processing abilities,softwares,and other technologies that connect with other devices and systems over the ( 2) or other communication and exchange data networks .Over the past few years, IoT has become one of the most important technologies of the ( 3 ) centuryWe can connect objects to the Internet via embedded devices. By means of( 4) computing, the cloud, big data, and mobile technologies, physical things can share and collect data with minimal human intervention. Traditional fields of embedded systems,wireless ( 5) networks (WSNs),control systems,automation, independently and collectively enable IoT.回答5处

  • A.sensor
  • B.searching
  • C.service
  • D.source
查看答案
单选题

The Internet of( 1)(IoT) describes physical objects that are embedded with Sensor,processing abilities,softwares,and other technologies that connect with other devices and systems over the ( 2) or other communication and exchange data networks .Over the past few years, IoT has become one of the most important technologies of the ( 3 ) centuryWe can connect objects to the Internet via embedded devices. By means of( 4) computing, the cloud, big data, and mobile technologies, physical things can share and collect data with minimal human intervention. Traditional fields of embedded systems,wireless ( 5) networks (WSNs),control systems,automation, independently and collectively enable IoT.回答4处

  • A.low-level
  • B.low-cost
  • C.high-cost
  • D.high-performance
查看答案
单选题

The Internet of( 1)(IoT) describes physical objects that are embedded with Sensor,processing abilities,softwares,and other technologies that connect with other devices and systems over the ( 2) or other communication and exchange data networks .Over the past few years, IoT has become one of the most important technologies of the ( 3 ) centuryWe can connect objects to the Internet via embedded devices. By means of( 4) computing, the cloud, big data, and mobile technologies, physical things can share and collect data with minimal human intervention. Traditional fields of embedded systems,wireless ( 5) networks (WSNs),control systems,automation, independently and collectively enable IoT.回答3处

  • A.19th
  • B.20th
  • C.21th
  • D.22th
查看答案
单选题

The Internet of( 1)(IoT) describes physical objects that are embedded with Sensor,processing abilities,softwares,and other technologies that connect with other devices and systems over the ( 2) or other communication and exchange data networks .Over the past few years, IoT has become one of the most important technologies of the ( 3 ) centuryWe can connect objects to the Internet via embedded devices. By means of( 4) computing, the cloud, big data, and mobile technologies, physical things can share and collect data with minimal human intervention. Traditional fields of embedded systems,wireless ( 5) networks (WSNs),control systems,automation, independently and collectively enable IoT.回答2处

  • A.path
  • B.Internet
  • C.route
  • D.switch
查看答案
单选题

The Internet of( 1)(IoT) describes physical objects that are embedded with Sensor,processing abilities,softwares,and other technologies that connect with other devices and systems over the ( 2) or other communication and exchange data networks .Over the past few years, IoT has become one of the most important technologies of the ( 3 ) centuryWe can connect objects to the Internet via embedded devices. By means of( 4) computing, the cloud, big data, and mobile technologies, physical things can share and collect data with minimal human intervention. Traditional fields of embedded systems,wireless ( 5) networks (WSNs),control systems,automation, independently and collectively enable IoT.回答1处

  • A.this
  • B.thing
  • C.think
  • D.things
查看答案

相关题库更多 +