1. Job Roadmap
  2. Home
  3. Problem Set
  4. codenotelist
  5. Forum
  6. course
  7. Shore Share Sessions
  8. Record
  1. Login
  2. Sign Up
  3. Language
    1. English
    2. 한국어
    3. 简体中文
    4. 正體中文
    ZhContent TextSol AI分析

解题思路

本题需要模拟一个有限状态机(Finite State Machine, FSM)。我们将每个 RmAppAttempt 视为一个有状态对象,依据“当前状态 +(事件源, 事件)→ 下一状态”的确定性转移来更新。 核心做法:

  1. 用字典/哈希表保存每个 RmAppAttempt 的当前状态。
  2. 按输入顺序依次处理事件三元组:事件源|对象|事件(空格分隔多个事件)。
  3. 只实现题面允许的转移,并过滤非法输入(不输出)。
  4. 特殊规则:

P3825.第3题-状态机

    1000ms Tried: 115 Accepted: 12 Difficulty: 5 所属公司 : 荣耀
    算法与标签>模拟

题目内容

ApacheApacheApache HadoopHadoopHadoop YARNYARNYARN 是一种新的 HadoopHadoopHadoop 资源管理器,主要部件为 resourceresourceresource managermanagermanager 和 nodenodenode managermanagermanager 。 resourceresourceresource managermanagermanager 使用有限状态机维护有状态对象的生命周期。RmAppAttemptRmAppAttemptRmAppAttempt 是 resourceresourceresource managermanagermanager 中用于维护一个 ApplicationApplicationApplication 运行尝试的生命周期的数据结构,当某个事件发生时 RmAppAttemptRmAppAttemptRmAppAttempt 会根据当前状芯进行状态迁移,同时触发一个其他行为。RmAppAttempRmAppAttempRmAppAttemp 相关状态和事件简述如下:

1.RmAppRmAppRmApp 发送 startstartstart 事件创建 RmAppAttemptRmAppAttemptRmAppAttempt ,初始化后,状态迁移为 submittedsubmittedsubmitted。

2.RmAppAttemptRmAppAttemptRmAppAttempt 在 submittedsubmittedsubmitted 状态下收到资源调度器 (ResouceScheduler)(ResouceScheduler)(ResouceScheduler) 发来的 appappapp_acceptedacceptedaccepted 事件,状态迁移为 scheduledscheduledscheduled 。

3.RmAppAttemptRmAppAttemptRmAppAttempt 在 scheduledscheduledscheduled 状态下收到 ReContainerReContainerReContainer 发来的 containercontainercontainer_allocatedallocatedallocated 事件,状态迁移为 allocatedallocatedallocated 。

4.RmAppAttemptRmAppAttemptRmAppAttempt 在 scheduledscheduledscheduled 状态下收到 ApplicationMasterLauncherApplicationMasterLauncherApplicationMasterLauncher 发来的 launchedlaunchedlaunched 事件,状态迁移为 runningrunningrunning 。

5.RmAppAttemptRmAppAttemptRmAppAttempt 在 runningrunningrunning 状态下收到 ResouceSchedulerResouceSchedulerResouceScheduler 发来的 finishedfinishedfinished 事件,状态迁移为 finishedfinishedfinished 。

6.在 RmAppAttemptRmAppAttemptRmAppAttempt 运行过程中(不含 finishedfinishedfinished 状态),当收到来自客户端的杀死应用程序的命令时,RmAppRmAppRmApp 向 RmAppAttemptRmAppAttemptRmAppAttempt 发送 killkillkill 事件,RmAppattempRmAppattempRmAppattemp 收到后,状态迁移到 killedkilledkilled 状态。

请编写一段程序模拟实现 RmAppAttemptRmAppAttemptRmAppAttempt 状态机,接收一段连续事件输入,输出每个事件处理后 yamyamyam 中对应 RmAppAttemptRmAppAttemptRmAppAttempt 对象的状态。

输入描述

模拟 RmAppAttemptRmAppAttemptRmAppAttempt 状态机,接收一段连续事件输入

输入接口:(事件间用空格分隔)

事件源 ∣RmAppAttempt|RmAppAttempt∣RmAppAttempt 对象∣|∣ 事件

事件源:RmApp、ResouceScheduler、ApplicationMasterLauncher、RmContainerRmApp、ResouceScheduler、ApplicationMasterLauncher、RmContainerRmApp、ResouceScheduler、ApplicationMasterLauncher、RmContainer

事件:start、appstart、appstart、app_accepted、containeraccepted、containeraccepted、container _allocated、launched、finished、killallocated、launched、finished、killallocated、launched、finished、kill

输出描述

输出接口:(输出结果间用分号;分隔)

RmAppAttemptRmAppAttemptRmAppAttempt 对象 |状态

状态:submitted、scheduled、allocated、running、finished、killedsubmitted、scheduled、allocated、running、finished、killedsubmitted、scheduled、allocated、running、finished、killed

无效输入通过状态机过滤,不需要任何输出

样例1

输入

RmApp|RmAppAttempt_001|start RmApp|RmAppAttempt_002|start RmApp|RmAppAttempt_001|kill

输出

RmAppAttempt_001|submitted;RmAppAttempt_002|submitted;RmAppAttempt_001|killed;

登录后即可使用 AI 分析。

模式
倒计时时长
:

最长 10 小时 59 分;应用后按此时长重新开始。

提示:点击提交记录在左侧题面区域查看详情
题库
AI分析设置
留空使用官方API Key,每天有次数限制(自定义API Key仅限会员和管理员使用,不限次数)
会员和管理员可切换模型;切到 Kimi/智谱/通义/豆包时需填写对应供应商 API Key
升级会员,可将运行与提交冷却时间缩短至 1 秒起

Status

  • Judging Queue
  • Service Status

Development

  • Open Source

Support

  • Help
  • Contact Us

About

  • About
  • Privacy
  • Terms of Service
  • Copyright Complaint
  1. Language
    1. English
    2. 한국어
    3. 简体中文
    4. 正體中文
  2. Legacy mode
  3. Theme
    1. Light
    2. Dark
  1. 京ICP备2025123107号-1
  2. Worker 2, 32ms
  3. Powered by Hydro v5.0.0-beta.18 Community
CLOSE


ScanQRCodePrompt

请使用微信扫描下方二维码完成注册

Forgot password or username?