📣 黑五网一特惠|VIP一年通行证5折,蓝莓、Offer多多同步特惠
12
返回列表 发新帖
楼主: wxr.dal
跳转到指定楼层
上一主题 下一主题
收起左侧

集中讨论一下RoundRobin的问题

🔗
 楼主| wxr.dal 2015-11-26 12:30:06 | 只看该作者
全局:
ay-pythonista 发表于 2015-11-26 12:26
那我觉得很简单啊 用一个list记录所有执行时间大于q的任务的等待时间 然后一个variable 记录所有执行时间 ...

小于q的任务也有可能排在队尾等很久,并不知道哪个是最小时间。
回复

使用道具 举报

🔗
ay-pythonista 2015-11-26 12:40:06 | 只看该作者
全局:
wxr.dal 发表于 2015-11-26 12:30
小于q的任务也有可能排在队尾等很久,并不知道哪个是最小时间。

每次累加等待时间的时候和当前最小时间比较一下就好了啊
回复

使用道具 举报

🔗
 楼主| wxr.dal 2015-11-26 12:42:39 | 只看该作者
全局:
ay-pythonista 发表于 2015-11-26 12:40
每次累加等待时间的时候和当前最小时间比较一下就好了啊

"然后一个variable 记录所有执行时间小于q的最大和最小时间" 我没看懂,你这个是要怎么记录
回复

使用道具 举报

🔗
ay-pythonista 2015-11-26 12:42:40 | 只看该作者
全局:
wxr.dal 发表于 2015-11-26 12:30
小于q的任务也有可能排在队尾等很久,并不知道哪个是最小时间。

还有请问你能把看到这个问题的帖子链接发一下吗 谢啦
回复

使用道具 举报

🔗
 楼主| wxr.dal 2015-11-26 12:43:58 | 只看该作者
全局:
ay-pythonista 发表于 2015-11-26 12:42
还有请问你能把看到这个问题的帖子链接发一下吗 谢啦

这个要去翻帖子了,慢慢翻吧…… 我一时半会儿也找不到
回复

使用道具 举报

🔗
chuxidemeng 2015-11-28 03:59:36 | 只看该作者
全局:
对求最大最小时间没什么好的思路,求大神们指点!!
回复

使用道具 举报

🔗
ay-pythonista 2015-11-28 04:25:27 | 只看该作者
全局:
chuxidemeng 发表于 2015-11-28 03:59
对求最大最小时间没什么好的思路,求大神们指点!!

一个hash table 应该就解决了吧 用index记录process ID, value是积累的等待时间
回复

使用道具 举报

🔗
returning 2015-11-28 15:58:53 | 只看该作者
全局:
ay-pythonista 发表于 2015-11-26 12:42
还有请问你能把看到这个问题的帖子链接发一下吗 谢啦

同问,云里雾里,看不懂啊。。。
回复

使用道具 举报

🔗
leonidas1573 2015-12-4 14:27:30 | 只看该作者
全局:
http://www.1point3acres.com/bbs/thread-142143-1-1.html 我的C++解法.
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;

  4. float roundRobin(int* Atime, int len, int* Etime, int q) {
  5.         if (len < 2) return 0;
  6.         queue< pair<int, int> > qq;        // execution time, insert time.
  7.         int currenttime = 0, stackhead = 0, currenttask = 0, totalwaittime = 0;
  8.         bool killcurrenttask = 0;
  9.         while (qq.size() || stackhead != len || killcurrenttask) {
  10.                 while (stackhead < len && Atime[stackhead] <= currenttime) {
  11.                         qq.push(make_pair(Etime[stackhead], Atime[stackhead]));
  12.                         stackhead++;
  13.                 }
  14.                 if (killcurrenttask) {
  15.                         qq.push(make_pair(currenttask - q, currenttime));
  16.                 }
  17.                 if (!qq.size())
  18.                         currenttime = Atime[stackhead];
  19.                 else {
  20.                         currenttask = qq.front().first;
  21.                         totalwaittime += currenttime - qq.front().second;
  22.                         qq.pop();
  23.                         killcurrenttask = currenttask > q;
  24.                         currenttime += ((q < currenttask) ? q : currenttask);
  25.                 }
  26.         }
  27.        
  28.         return totalwaittime / (double)(len);
  29. }

  30. int main() {
  31.         // int Atime[] = { 0, 1, 3, 9 };
  32.         // int Etime[] = { 2, 1, 7, 5 };
  33.         // int q = 2;

  34.         // int Atime[] = { 0, 1, 4 };
  35.         // int Etime[] = { 5, 2, 3 };
  36.         // int q = 3;

  37.         int Atime[] = { 0, 4, 8 };
  38.         int Etime[] = { 1, 1, 1 };
  39.         int q = 3;

  40.         cout << roundRobin(Atime, sizeof(Atime) / sizeof(int), Etime, q);

  41.         // your code goes here
  42.         return 0;
  43. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表