LeetCode #855. Exam Room

18、知识表示与学习范式 本文探讨了智能系统中的核心组成部分——知识表示与学习范式。从基础知识到实际应用,详细解析了符号表示、框架表示、语义网络和本体表示等知识表示方法,并介绍了监督学习、无监督学习、半监督学习和强化学习等学习范式。此外,还深入分析了这些技术在自然语言处理、图像识别和推荐系统等领域的具体应用及操作步骤。最后,展望了未来可能的技术发展方向。 阅读详情

题目描述:

In an exam room, there are N seats in a single row, numbered 0, 1, 2, ..., N-1.

When a student enters the room, they must sit in the seat that maximizes the distance to the closest person.  If there are multiple such seats, they sit in the seat with the lowest number.  (Also, if no one is in the room, then the student sits at seat number 0.)

Return a class ExamRoom(int N) that exposes two functions: ExamRoom.seat() returning an int representing what seat the student sat in, and ExamRoom.leave(int p) representing that the student in seat number p now leaves the room.  It is guaranteed that any calls to ExamRoom.leave(p) have a student sitting in seat p.

Example 1:

Input: ["ExamRoom","seat","seat","seat","seat","leave","seat"], [[10],[],[],[],[],[4],[]]
Output: [null,0,9,4,2,null,5]
Explanation:
ExamRoom(10) -> null
seat() -> 0, no one is in the room, then the student sits at seat number 0.
seat() -> 9, the student sits at the last seat number 9.
seat() -> 4, the student sits at the last seat number 4.
seat() -> 2, the student sits at the last seat number 2.
leave(4) -> null
seat() -> 5, the student sits at the last seat number 5.
​​​​​Note:
  1. 1 <= N <= 10^9
  2. ExamRoom.seat() and ExamRoom.leave() will be called at most 10^4 times across all test cases.
  3. Calls to ExamRoom.leave(p) are guaranteed to have a student currently sitting in seat number p.
class ExamRoom {
public:
    ExamRoom(int N) {
        n=N;
    }
    
    int seat() {
        if(s.empty())
        {
            s.insert(0);
            return 0;
        }
        bool first=s.count(0);
        bool last=s.count(n-1);
        int pre=0, result=0, max_dist=0;
        // 遍历set时,需要单独考虑两个端点,当它们没有占用时可以考虑
        // 而且计算两个端点到其他点的距离时不需要除二
        for(const int& i:s)
        {
            int dist=(pre==0&&!first)?i-pre:(i-pre)/2;
            if(dist>max_dist)
            {
                max_dist=dist;
                if(pre==0&&!first) result=0;
                else result=(i+pre)/2;
            }
            pre=i;
        }
        if(n-1-pre>max_dist&&!last) result=n-1;
        s.insert(result);
        return result;
    }
    
    void leave(int p) {
        s.erase(p);
    }

private:
    int n;
    set<int> s;
};

 

iStoreOS等软路由插件卸载的残留?分享一款软路由高级卸载工具,自定义卸载,轻松解决卸载残留问题 iStoreOS用户看过来!👀 还在被插件包残留困扰吗?本文分享一款“高级卸载”的插件,助你深度清理iStoreOS系统,彻底解决软件卸载不净的痛点,告别频繁恢复出厂设置的烦恼!🚀 阅读详情

相关推荐

【HDLBits实战】从真值表到最优电路:SOP与POS形式在ECE241考题中的精妙应用

本文以HDLBits平台上的ECE241考题为例,详细讲解了如何从真值表出发,利用卡诺图化简技术,推导出最优的积之和(SOP)与和之积(POS)逻辑表达式。文章重点剖析了如何处理“无关项”以简化电路,并通过Verilog代码实现对比,阐述了SOP与POS形式在数字电路设计中的精妙应用与实战价值。

z2a3b4c5d的博客 214

LeetCode解析------855.考场就座

题目: 在考场里,一排有 N 个座位,分别编号为 0, 1, 2, …, N-1 。 当学生进入考场后,他必须坐在能够使他与离他最近的人之间的距离达到最大化的座位上。如果有多个这样的座位,他会坐在编号最小的座位上。(另外,如果考场里没有人,那么学生就坐在 0 号座位上。) 返回 ExamRoom(int N) 类,它有两个公开的函数:其中,函数 ExamRoom.seat() 会返回一个 int...

weixin_44337475的博客 655

Sigmastar平台WDR调试实战:从参数解析到鬼影消除的完整指南

本文提供了Sigmastar平台宽动态(WDR)技术的实战调试指南。针对逆光、运动场景下的核心痛点,系统性地解析了从多曝光采集、HDR融合到色调映射的完整管线,并重点阐述了如何通过调整曝光比、运动阈值与调整曲线等关键参数,有效消除运动鬼影、平衡暗部噪声与细节,最终实现清晰稳定的图像效果。

Jerry的专栏 926

leetcode | go | 第855题 | 考场就坐

考场就坐

iCling的博客 548

若依RuoYi文件上传漏洞实战:如何安全配置/profile/upload路径(附避坑指南)

本文深入解析若依RuoYi框架中/profile/upload路径的文件上传漏洞,提供详细的安全配置方案和实战指南。通过权限修正、输入验证强化和存储隔离等多层防御策略,有效防范未授权访问和恶意文件上传风险,保障系统安全。

pink的博客 776

从零到一:RF-DETR如何通过神经架构搜索重塑实时目标检测的边界

RF-DETR通过创新的权重共享神经架构搜索(NAS)机制,重新定义了实时目标检测的技术边界。这项技术在COCO等基准测试中表现卓越,成为首个AP超过60的实时检测器,同时保持跨领域稳定性和高效推理速度。RF-DETR的动态架构调整能力使其能够适应从嵌入式设备到云端服务器的各种硬件环境,为工业质检、自动驾驶等场景提供灵活解决方案。

weixin_29061531的博客 467

Leetcode855:考场就座

当学生进入考场后,他必须坐在离最近的人最远的座位上。如果有多个这样的座位,他会坐在编号最小的座位上。(另外,如果考场里没有人,那么学生就坐在。个座位排成一行,编号为。设计一个模拟所述考场的类。

m0_67598823的博客 390

基于XGBoost的混凝土力学性能预测系统

本文介绍了一个基于XGBoost算法的混凝土力学性能预测系统。该系统通过模拟生成3000组混凝土配合比数据(包含水灰比、水泥用量和龄期三个关键特征),利用XGBoost强大的非线性建模能力预测混凝土抗压强度。研究背景源于传统混凝土性能测试方法耗时耗力的痛点,该系统可显著减少实验次数,优化配合比设计。系统实现包括:数据生成与特征工程(模拟真实工程数据并添加噪声和异常值)、XGBoost模型构建、以及预测性能评估。XGBoost算法因其处理非线性关系能力强、鲁棒性好等优势被选用,可为智能建造和数字化施工提供技术

huanghm88的专栏 128

LeetCode:855. 考场就座(TreeSet Java)

TreeSet ts:这是一个自定义比较器的TreeSet,用来存储表示座位区间的数组。比较器的逻辑是先比较区间的 “距离”(通过dist方法计算,距离的定义与区间两端的情况有关),如果距离相等则按照区间左端点的大小来排序。其目的是方便快速找到最合适的空闲座位区间来分配座位。

Cosmoshhhyyy的博客 719

基于嵌入式Linux设计的智能车库(GEC6818)

随着城市化进程的加快,传统停车管理方式存在效率低下、人工成本高、车主体验差等问题。为解决这些问题,本项目基于嵌入式Linux技术,设计并实现了一套智能车库管理系统。该系统采用GEC6818开发板作为核心控制器,运行Qt应用程序,并结合USB免驱摄像头进行车牌识别,RFID模块完成刷卡支付,SQLite数据库存储车主信息和停车记录。系统提供车主注册、用户管理、出入库管理、停车费结算、车辆查询等功能,并具备语音播报提示,提高用户体验。通过本系统,停车场管理更加高效、智能,有助于提升停车服务质量,减少人工干预,适

441

CD-SSB和NCD-SSB相关内容

NR中,PSS/SSS 和PBCH总是绑定的,因此也称为SSB block。频域由下往上,第121个SC(k = 120)的中心频率,就是SSB的GSCN对应的SSREF(同步参考频率)的出处如上,同步栅格映射到SSB 的RE位置是10个PRB的位置,然后指向RE index 0,即第121个子载波的中心频率;UE获得N_offset_GSCN后,即可结合当前SSB的GSCN推算下一个SSB的GSCN =N_Reference_GSCN(当前SSB的GSCN) + N_offset_GSCN。

asd199086的博客 3425

LeetCode·每日一题·855.考场就座·有序集合+模拟

有序集合+模拟

m0_64560763的博客 318

外部PLC触发VisionMaster多流程运行

上一讲,介绍了海康VisionMaster与西门子PLC1200进行S7通信。在前一讲的基础上,讲解如何通过PLC触发,实现VisionMaster的多流程运行。

haier123888的博客 4652

LeetCode每日一题(855. Exam Room)

There is an exam room with n seats in a single row labeled from 0 to n - 1. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the lowest

wangjun861205的博客 191

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

【LeetCode】855. Exam Room 解题报告(Python)

作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/exam-room/description/ 题目描述: In an exam room, there are N seats in a single row, numbered 0, 1, 2, ......

负雪明烛 2523

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Leetcode.855考场就坐

Leetcode每日一题

感觉画质不如...原神的博客 304

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

LeetCode 855. Exam Room

LeetCode 855. Exam Room 传送门 题目分析 In an exam room, there are N seats in a single row, numbered 0, 1, 2, ..., N-1. When a student enters the room, they must sit in the seat that maximizes t...

博客 2918

855. 考场就座

在考场里,一排有 N 个座位,分别编号为 0, 1, 2, ..., N-1 。当学生进入考场后,他必须坐在能够使他与离他最近的人之间的距离达到最大化的座位上。如果有多个这样的座位,他会坐在编号最小的座位上。(另外,如果考场里没有人,那么学生就坐在 0 号座位上。)返回 ExamRoom(int N) 类,它有两个公开的函数:其中,函数 ExamRoom.seat() 会返回一个 int (整型数...

Do not mess it up 610

[leetcode] 855. Exam Room

Description In an exam room, there are N seats in a single row, numbered 0, 1, 2, …, N-1. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. ...

Learning from the mistakes 678

LeetCode之855_考场就座

本专栏单纯记录自己刷题过程,便于后续重复刷题更新迭代自己对于同一道题的认知和方法。有好的刷题方法和思路,可以评论区交流,感谢~ 1.但凡遇到在动态过程中取最值得要求,肯定要使用有序数据结构,常用的数据结构就是二叉堆和平衡二叉搜索树了。 set<int> s; s.empty() s.insert(0); s.erase(p); 集合(set)。每个元素的值必须唯一;而且系统会根据该值来自动将数据排序;内部结构采用红黑树的平衡二叉树。 class ExamR...

sinat_29634715的博客 469

【LeetCode - 855】考场就座

【中等】设计、有序集合

学哥斌的博客 418

LeetCode 838 Push Dominoes

LeetCode 838 Push Dominoes 传送门 题目分析 There are N dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to th...

博客 1470

leetcode-855. 考场就座

思路: 使用set(有序集合)记录seat的位置。 如果set为空,放入索引为0的位置。 遍历set,记录两个人之间距离的一半(pre+这个距离就是中点),如果这个距离比最大距离大,则记录pos和更新最大距离。因为1/2=0。所以将maxDist的初始值设为0。pre设为-1(表示第一元素钱前面没有元素)。pre表示cur前面的那个元素。 最后判断如果放在n-1的位置上,距离是不是会大(n-1-pre>maxDsit),如果大就更新pos。 得到pos后,将pos插入set,返回pos。 cla.

大灰狼吃树皮 268

Exam Room leetcode

In an exam room, there are N seats in a single row, numbered 0, 1, 2, ..., N-1.When a student enters the room, they must sit in the seat that maximizes the distance to the closest person.  If there ar...

sysucph的专栏 712

LeetCode 582. 杀死进程(图的遍历)

文章目录1. 题目2. 解题2.1 DFS2.2 BFS 1. 题目 给 n 个进程,每个进程都有一个独一无二的 PID (进程编号)和它的 PPID (父进程编号)。 每一个进程只有一个父进程,但是每个进程可能会有一个或者多个孩子进程。 它们形成的关系就像一个树状结构。 只有一个进程的 PPID 是 0 ,意味着这个进程没有父进程。 所有的 PID 都会是唯一的正整数。 我们用两个序列来表示这些进程,第一个序列包含所有进程的 PID ,第二个序列包含所有进程对应的 PPID。 现在给定这两个序列和一个 P

Michael是个半路程序员 3112

Leetcode 855. Exam Room 考场就座:提供两种解法

Leetcode 855. Exam Room 考场就座: 提供两种解法855. Exam Room 考场就座(两种解法)题目描述示例:解答1代码1解答2代码2 855. Exam Room 考场就座(两种解法) 题目描述 In an exam room, there are N seats in a single row, numbered 0, 1, 2, …, N-1. When a stu...

importsys的博客 855
上一篇: LeetCode #1047. Remove All Adjacent Duplicates In String
下一篇: LeetCode #802. Find Eventual Safe States
LawFile
博客等级 码龄10年 5粉丝 627原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值