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分析

解题思路

先按题目要求对所有物品排序,再按顺序模拟放入背包即可。

排序规则可以直接转成比较规则:

  1. 先按typetypetype优先级排序:equip>weapon>item>otherequip > weapon > item > otherequip>weapon>item>other
  2. 再按qualityqualityquality从大到小排序
  3. 最后按ididid从小到大排序

P4722.第2题-背包排序

    1000ms Tried: 57 Accepted: 23 Difficulty: 5 所属公司 : 网易
    算法与标签>模拟

题目内容

玩家小A现在有一个n×m n \times m n×m 个格子的背包(n n n 为高,m m m 为宽),有t t t 个物品,先按排序算法把物品进行排序,然后根据排序后的物品一一放入背包。

在放入背包时,优先选择行数最小的位置进行放置,其次选择列数最小的位置。如果当前行无法容纳物品,则继续查找下一行。如果整个背包都无法放下该物品,则跳过该物品。

最后输出背包是否放的下所有物品。并输出当前背包状态,用id id id 表示当前背包格子是什么物品,如果当前格子没有物品输出0 0 0。

每个物品都包含以下这些属性:id id id:物品唯一ID ID ID,每个物品各不相同。height∗width height * width height∗width:物品占用的格子数。(height height height为高,width width width为宽)物品不可以旋转放入背包。quality quality quality:物品的品质。数值越大品质越高。type type type:物品的种类。

排序规则如下:1、优先按照type type type排序,"equip" > "weapon" > "item" > "other"。2、品质高的优先。3、id id id 小的优先。

输入描述

第一行包含三个整数n n n (1≤n≤50 1 \leq n \leq 50 1≤n≤50),m m m (1≤m≤50 1 \leq m \leq 50 1≤m≤50),t t t (1≤t≤1000 1 \leq t \leq 1000 1≤t≤1000),分别表示背包的高,背包的宽,物品的数量。

接下来t t t 行,每行包含四个整数,id id id (1≤id≤10000 1 \leq id \leq 10000 1≤id≤10000),height height height (1≤height≤5 1 \leq height \leq 5 1≤height≤5),width width width (1≤width≤5 1 \leq width \leq 5 1≤width≤5),quality quality quality (1≤quality≤7 1 \leq quality \leq 7 1≤quality≤7),一个字符串type type type (type∈{"equip","weapon","item","other"} type \in \{"equip", "weapon", "item", "other"\} type∈{"equip","weapon","item","other"}),为物品包含的属性。

输出描述

第一行包含一个字符串 "YES" 表示为背包可以放下所有物品。"NO" 表示为有的物品放不进去背包。

接下来n n n 行,每行包含m m m 个整数,表示当前格子放着的物品id id id,如果当前格子没有物品则输出0 0 0。

样例1

输入

4 3 3
1 1 3 7 other
2 3 1 2 equip
3 2 2 4 other

输出

YES
2 3 3
2 3 3
2 0 0
1 1 1

说明

排序后顺序:2 1 3 2\ 1\ 3 2 1 3。按顺序放入即可。

样例2

输入

4 4 6
6 2 1 3 weapon
1 2 3 1 equip
3 2 1 4 item
5 3 3 3 weapon
2 2 2 3 other
4 2 1 3 item

输出

NO
1 1 1 6
1 1 1 6
3 4 2 2
3 4 2 2

登录后即可使用 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 1, 40ms
  3. Powered by Hydro v5.0.0-beta.18 Community
CLOSE


ScanQRCodePrompt

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

Forgot password or username?