题目描述:https://www.1point3acres.com/bbs/thread-225621-1-1.html

这道题是Bloomberg经典面试题,和LRU非常类似。维护一个list记录runner的顺序,一旦有runner经过sensor,我们就需要调整位置。本质其实就是要写一个 update(runner i, sensor j) 的函数。

注意C++中 list.splice 函数,由于对同一个list进行操作,指针不会失效,仍指向原来的list元素,runner2pos 也不用更新。

// https://www.1point3acres.com/bbs/thread-225621-1-1.htmlclass Marathon{int m, n; // m runner with id 1-m, n sensor with id 1-nlist<int> l; // record order of all runnersvector<list<int>::iterator> runner2pos; // runner_id -> the pos in listvector<int> passedSensor; // runner_id -> record how many sensors have been passedvector<int> firstPassed; // sensor_id -> the first runner who passed the sensorpublic:Marathon(int _m, int _n){m = _m;n = _n;runner2pos.resize(m+1);passedSensor.resize(m+1,0);firstPassed.resize(n+1,0);firstPassed[0] = 1; // at first in the order of 1~mfor (int i=1;i<=m;++i) l.push_back(i);for (auto it=l.begin();it!=l.end();++it){runner2pos[distance(l.begin(),it)+1]=it;// cout << distance(l.begin(),it)+1 << ' ' << *it << endl;
        }}void passMilestone(int runner_id){int sensor_id = ++passedSensor[runner_id];if (firstPassed[sensor_id]==0) firstPassed[sensor_id]=runner_id;// runner_id passed sensor_id, insert this runner to the front of previous sensorauto cur_pos=runner2pos[runner_id];auto new_pos=runner2pos[firstPassed[sensor_id-1]];l.splice(new_pos,l,cur_pos);}void printLeadBoard(){for (auto x:l) cout<<x<<' ';cout << endl;}
};int main() {Marathon m(3,2);m.passMilestone(3); // runner 3 passed sensor 1
    m.printLeadBoard();m.passMilestone(2); // runner 2 passed sensor 1
    m.printLeadBoard();m.passMilestone(2); // runner 2 passed sensor 2
    m.printLeadBoard();return 0;
}

转载于:https://www.cnblogs.com/hankunyan/p/11566707.html

Marathon Ranking相关推荐

  1. Marathon 0.15: 更稳定 更多数据 更易用

    Marathon 是数据中心操作系统(DCOS)上的原生容器编排和应用管理平台,正式推出的0.15版增加了许多新功能,并进一步提升了性能.监控和用户界面等方面的表现. 数人云基于Mesos技术,使用M ...

  2. 一文理解Ranking Loss/Margin Loss/Triplet Loss

    点击蓝字  关注我们 作者丨土豆@知乎 来源丨https://zhuanlan.zhihu.com/p/158853633 本文已获授权,未经作者许可,不得二次转载. 前言 Ranking loss在 ...

  3. 《Revisiting Salient Object Detection! Simultaneous Detection, Ranking, and Subitizing of Multiple Sa

    <Revisiting Salient Object Detection! Simultaneous Detection, Ranking, and Subitizing of Multiple ...

  4. Ranking relevance in yahoo search (2016)论文阅读

    文章链接 https://www.kdd.org/kdd2016/papers/files/adf0361-yinA.pdf abstract 点击特征在长尾query上的稀疏性问题 基础相关性三大技 ...

  5. mesos+marathon平台搭建

    2019独角兽企业重金招聘Python工程师标准>>> mesos+marathon平台搭建 博客分类: 虚拟化 mesos 一.安装jdk和maven 修改/etc/profile ...

  6. Crawling - Computing Ranking 很长时间, 怎么办?

    MOSS中遇到爬网状态保持Crawling - Computing Ranking不变. 你可以尝试编写SharePoint Object Model的代码来解决这个问题. 关键代码如下: Micro ...

  7. 论文笔记之:End-to-End Localization and Ranking for Relative Attributes

    End-to-End Localization and Ranking for Relative Attributes arXiv Paper  摘要:本文提出一种 end-to-end 的属性识别方 ...

  8. POJ 3275 Ranking the Cows (floyd传递闭包)

    Ranking the Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2248   Accepted: 1045 ...

  9. centos7 安装配置mesos+marathon+zookeeper

    2019独角兽企业重金招聘Python工程师标准>>> 1,mesos介绍 Mesos诞生于UC Berkeley的一个研究项目,现已成为Apache Incubator中的项目.M ...

最新文章

  1. DAY7-Python学习笔记
  2. linux重启后出现control+D错误的解决
  3. Linux服务器tomcat部署war包
  4. java简单计算机程序_JAVA程序编的简单计算器程序??
  5. c 站点下html页面拦截器,HTML内容拦截器「HTML Content Blocker」
  6. 动态照片制作html模板
  7. 【C语言】(指针) 将两个数排序
  8. 公式太多,读不懂? 一文带你领略KNN近邻算法~简单易懂
  9. 一个拖拽的效果类和dom-drag.js
  10. JS重要知识点总结-不完善
  11. SQL中char、varchar、nvarchar、text 的区别
  12. U-Net源码上实现自己数据集的分割任务
  13. 如何快速实现直播美颜功能 - 接入美颜SDK详解
  14. 如何报考华为网络工程师?
  15. MPP(无主备)环境搭建
  16. 分页 在mybatis执行SQL语句之前进行拦击处理实例
  17. 关于‘go list‘ failed with: error obtaining VCS status error obtaining VCS status: exit status 128问题的解决
  18. Spring基础学习(一)
  19. 设计出python_《设》字意思读音、组词解释及笔画数 - 新华字典 - 911查询
  20. 台式计算机cpu允许温度,台式cpu温度多少正常呢?老司机科普一下CPU常见问题

热门文章

  1. AlibabaProtect.exe如何删除、卸载
  2. 长江流向图_是长江水流向汉江 还是汉江水流向长江?
  3. 经验之谈,关于HOG调参:对matlab和opencv作对比
  4. Web前端:Bootstrap最强总结 附详细代码 (带常用案例!)
  5. 软件著作权侵权的裁判要点
  6. 腾讯计划推出搜狗输入法鸿蒙版;全球首款Web3手机售价2.38万起,全球预约人数超20万|极客头条
  7. 【观察】华为:新一代楼宇网络,使能绿建智慧化
  8. oracle查回收站大小,ORACLE回收站
  9. 杂志停刊通知计算机光盘,国家级计算机期刊《计算机光盘软件与应用》约稿
  10. Windows之间如何进行文件共享?