📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 4
跳转到指定楼层
上一主题 下一主题
收起左侧

A solution to 2 sigma OA problem

全局:

2016(1-3月) 码农类General 本科 全职@2 sigma - 网上海投 - 其他  | | Other | 其他

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
This is my solution to a problem posted in

apologize in advance if you disagree that I should open a new post. I want to know some feedbacks too and this way is easier to find out.

So assuming you already passed in all the paremeters, here  is a solution. it assume all clusters are new and empty. The questio
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
tions[i]+1)>leastMax){
                                        leastMax = a[i]/(distributions[i]+1);
                                        j=i;
                                }
                        }
                        b--;
                        distributions[j]++;
                }
                return distributions;
        }
       


上一篇:Salesforce电面面经
下一篇:Google MTV campus选组求助
🔗
ruiqin 2016-6-18 06:39:19 | 只看该作者
全局:
这个和用max heap做的思路一样的把   都是找load最高的cluster  加一个machine进去
heap的bigO还要快一点    但是要写个class包含clusterid, load, machineNum之类的
不知道heap和楼主这样暴力做哪个实际run起来会快一点    就怕会超时
回复

使用道具 举报

🔗
 楼主| andrewmasj 2016-6-18 08:22:11 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
 楼主| andrewmasj 2016-6-18 08:23:39 | 只看该作者
全局:
looking forward to better solutions ...
回复

使用道具 举报

🔗
TonyLic 2016-7-4 07:21:30 | 只看该作者
全局:
贴个C++的,思路和上面的一样,用max heap,始终给最大的average load的cluster加一个machine,更新其average load,再放入heap中
Time complexty: O(KlogN)
  1. class cluster
  2. {
  3. public:
  4.         cluster(int p1, int p2, int p3, int p4) : work_load(p1), avg_load(p2), index(p3), num_machine(p4) {}
  5.         int work_load;
  6.         int avg_load;
  7.         int index;
  8.         int num_machine;
  9. };

  10. struct mycmp
  11. {
  12.         bool operator()(cluster& c1, cluster& c2) { return c1.avg_load < c2.avg_load; }
  13. };
  14. vector<int> loadBalance(vector<int>& loads, int b)
  15. {
  16.         vector<int> res(loads.size());
  17.         if (b < loads.size()) return res;
  18.         priority_queue < cluster, vector < cluster >, mycmp> pq;
  19.         for (int i = 0; i < loads.size(); ++i)
  20.                 pq.emplace(loads[i], loads[i], i, 1);
  21.         b -= loads.size();
  22.         while (b--)
  23.         {
  24.                 auto temp = pq.top();
  25.                 pq.pop();
  26.                 temp.num_machine++;
  27.                 temp.avg_load = temp.work_load / temp.num_machine;
  28.                 pq.push(temp);
  29.         }
  30.         while (!pq.empty())
  31.         {
  32.                 auto temp = pq.top();
  33.                 pq.pop();
  34.                 res[temp.index] = temp.num_machine;
  35.         }
  36.         return res;
  37. }

  38. int main()
  39. {
  40.         vector<int> loads = { 200, 450 };
  41.         auto res = loadBalance(loads, 7);
  42.         printVector(res);
  43.         return 0;
  44. }
复制代码
回复

使用道具 举报

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

本版积分规则

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