当前位置: 首页 > article >正文

855. 考场就座

855. 考场就座


题目链接:855. 考场就座

代码如下:

class ExamRoom 
{
public:
    ExamRoom(int n) :n(n) {}

    int seat() 
    {
        if (num.size() == 0)
        {
            num.insert(0);
            return 0;
        }

        int l = -1, r = 0, max = 0, insetNum = 0; //初始化左右节点,最大距离和要插入的值
        if (*num.begin() != 0) { max = *num.begin(); }
        for (auto it = num.begin();it != num.end();it++)
        {
            r = *it;
            if (max < (r - l) / 2)
            {
                max = (r - l) / 2;
                insetNum = l + (r - l) / 2;
            }
            l = r;
        }
        if (r != n - 1)
        {
            if (max < n - 1 - r)
            {
                insetNum = n - 1;
            }
        }
        num.insert(insetNum);
        return insetNum;
    }

    void leave(int p) 
    {
        num.erase(p);
    }

private:
    std::set<int> num;
    int n;
};

/**
 * Your ExamRoom object will be instantiated and called as such:
 * ExamRoom* obj = new ExamRoom(n);
 * int param_1 = obj->seat();
 * obj->leave(p);
 */

http://www.kler.cn/a/465713.html

相关文章:

  • 线性代数自学资源推荐我的个人学习心得
  • Java 代码审计入门-07】SQL关键字
  • HTML5新特性|05 CSS3边框CSS3背景
  • 每天40分玩转Django:Django性能优化
  • wpf 国际化 try catch comboBox
  • C# 设计模式(结构型模式):享元模式
  • 如何在iOS 11 中禁用高效图像格式 (HEIF)
  • 【Vim Masterclass 笔记01】Section 1:Course Overview + Section 2:Vim Quickstart
  • 适用不同业务场景的6种销售预测模型
  • WPF自定义任务栏缩略图
  • CSS进阶和SASS
  • halcon三维点云数据处理(二)
  • 《向量数据库指南》混合检索系统的深度探索与实践:从POC到生产级解决方案的构建
  • 毕设中所学
  • MCA:用于图像识别的深度卷积神经网络中的多维协同注意力
  • MAC录屏QuikTimePlayer工具录屏声音小免费解决方案
  • 机器学习之模型评估——混淆矩阵,交叉验证与数据标准化
  • PyQt下载M3U8文件
  • TK730 不允许更改资源库或跨客户端定制
  • JavaEE 初阶:线程(2)