楼主: novac812
跳转到指定楼层
上一主题 下一主题
收起左侧

AMAZON OA2 新的一个coding题!!!

 
🔗
vieri3221 2015-12-4 01:56:44 | 只看该作者
全局:
dwl1222 发表于 2015-12-4 00:51
。。。自言自语

哈哈哈。。。今天oa2 due....  着实很着急。。  谢谢你的code!
另外 请问你其它oa2 的code么? 能否发我一下,非常感谢🙏
回复

使用道具 举报

🔗
dwl1222 2015-12-4 23:57:42 | 只看该作者
全局:
vieri3221 发表于 2015-12-4 01:56
哈哈哈。。。今天oa2 due....  着实很着急。。  谢谢你的code!
另外 请问你其它oa2 的code么? 能否发 ...

不好意思。我才看到。但是我并没有做过oa。就是看了楼主po的这道题做一下
回复

使用道具 举报

🔗
zeehw 2015-12-17 09:07:48 | 只看该作者
全局:
DWill008 发表于 2015-11-16 10:30
我是这么理解的,有不对的地方请指出
我拿贴子里面给出的例子来说明下吧。
【0,1,4】 【5,2,3】 q  ...

最重要的就是 “请注意,这时候的q被重新设置过了”    谢谢楼主!
回复

使用道具 举报

🔗
Sense 2015-12-19 07:04:37 | 只看该作者
全局:
我来写个C++版本的,请大家看看对不对
// round-robin.cpp
#include <iostream>
#include <queue>
using namespace std;
class process{
public:
        int arrive;
        int execute;
        process(int arr, int exec){
                arrive = arr, execute = exec;
        }
};

double roundRobin(int* arrive, int* execute, int numOfProcess, int q){
        queue<process*> myqueue;
        int currentTime = 0, procCounter = 0, totalWait = 0, clock;
        process* currentProcess = NULL;
        for(; 1; currentTime++){
                if(currentProcess != NULL){ // change current process status
                        totalWait += (myqueue.size());// all processes in queue have to wait such time
                        currentProcess->execute--;// execute time reduce 1
                        if(currentProcess->execute == 0){// current process finished.
                                if(!myqueue.empty()){
                                        clock = currentTime;
                                        currentProcess = myqueue.front();
                                        myqueue.pop();
                                }
                                else break;// all processes finished
                        }
                        else{// current not finished
                                if(currentTime - clock == q){// time quantum finished, top process in queue pop out
                                        clock = currentTime;
                                        myqueue.push(currentProcess);
                                        currentProcess = myqueue.front();
                                        myqueue.pop();
                                }
                        }
                }
                if(procCounter < numOfProcess && arrive[procCounter] == currentTime){// new process pushed into queue
                        process* temp = new process(arrive[procCounter], execute[procCounter]);
                        myqueue.push(temp);
                        procCounter++;
                }
                if(currentProcess == NULL && !myqueue.empty()){// only for first process
                        currentProcess = myqueue.front();
                        myqueue.pop();
                        clock = currentTime;
                }
        }
        return (double)totalWait / (double)numOfProcess;
}


补充内容 (2015-12-19 07:23):
有一个地方理解有点问题,从testcase来看在一个time quantum 结束同时,如果有新process进队列的话,是新process先进队列,time quantum结束时的原运行进程后进队列,所以三个if顺序要变一下
回复

使用道具 举报

全局:
不是non-pre...真的么...
回复

使用道具 举报

🔗
yyoung 2016-3-1 09:36:29 | 只看该作者
全局:
楼主您好,请问第一张round robin的图还在吗?怎么没有看见呢?
回复

使用道具 举报

🔗
GGplayer 2016-3-12 12:46:40 | 只看该作者
全局:
马上要做OA2 了  学习下!
回复

使用道具 举报

🔗
baoxiaoxzz 2016-10-15 00:02:48 | 只看该作者
全局:
求问楼主,124楼的图好像没看见。。。
回复

使用道具 举报

🔗
 楼主| novac812 2018-8-25 00:35:45 | 只看该作者
全局:
这个是我3年前的帖子,图我记得当时都发在这里了。。。不知道为啥现在只有一个图了。我现在真的没有图了。。。sorry。。。。
回复

使用道具 举报

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

本版积分规则

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