题目详情

初级程序员,章节练习,基础复习,案例精选

初级程序员,章节练习,基础复习,案例精选

正确答案及解析

正确答案
解析

(1 )k=0

(2) J<=N

(3) k=k+1或k++ ,或者其他等价形式

(4) d[i]+6 ,或者其他等价形式

(5)0(N)

该题是一个应用型的算法分析题,主要考查考生对贪心算法的理解以及对程序流程图的掌握;做题的关键是对分析清楚题意,并明确流程图中的贪心条件。

该题可转化为求解能覆盖所有房子的基站部署方案的问题,即通过一系列选择求最优解的问题。不难发现,该问题具有最优子结构,并且具有贪心选择性质,可以用贪心法来求解。

贪心法是一种不求最优解,只求满意解的算法。首先初始化, k=0 ;若两房间的距离不超过12公立,则不建基站。否则建基站。算法思想:问题的规模为N。从第一个房子 (最左端)开始部署基站.把第一个基站放置在该房子右方的6公里处,这时,该基站会覆盖从第一个房子到其右方12公里的直线的长度上的所有房子。假设覆盖了N:个房子。此时问题规模编程了N-N1。把第一个基站覆 盖的房子去掉,再从N-N;中选择第一个 (最左端)房子开始布局基站,将第二个基站放置在该房子右方的6公里处。以此类推,直至所有的房子被覆盖。在该算法中包含两个循环,但实际上只是遍历所有房子次,所以算法的时间复杂度为0(N)。

你可能感兴趣的试题

单选题

Advancements in ( )have contributed to the growth of the automotive industry through the creation and evolution of self-driving vehicles.

  • A.Artificial Intelligence
  • B.Cloud Computing
  • C.Internet of Things
  • D.Big Data
查看答案
单选题

In project human resource management , ( )is not a source of power for the project manager.

  • A.referent power
  • B.expert power
  • C.reward power
  • D.audit power
查看答案
单选题

At the project establishment stage , the feasibility study mainly includes techinical feasibility analysis , ( ), operation environment feasibility analysis and other aspects of feasibility analysis.

  • A.detail feasibility analysis
  • B.opportunity analysis
  • C.economic feasibility analysis
  • D.risk analysis
查看答案
单选题

( )is a grid that shows the project resources assigned to each work package.

  • A.Stakeholder engagement assessment matrix
  • B.Requirements traceability matrix
  • C.Probability and impact matrix
  • D.Responsibility assignment matrix
查看答案
单选题

Xinhua News Agency reported in January 2022,Chian will further promote the developmet of a digital economy during the 14th Five-Year Plan eriod(2021-2025). The plan also emphasized industrial ( )transformation.

  • A.digital
  • B.networking
  • C.intelligentize
  • D.informatization
查看答案

相关题库更多 +