查看: 2500| 回复: 2
跳转到指定楼层
上一主题 下一主题
收起左侧

1465. Order Of Tasks 这题目什么意思?

全局:

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

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

x
[b]
[/b][b]
[/b]LintCode上的这道题目题意是什么,大家有看懂吗?


1465. Order Of Tasks
[color=rgba(0, 0, 0, 0.65098)]

[b]Description[/b]
[color=rgba(0, 0, 0, 0.65098)]
There are n different tasks, the execution time of tasks are t[], and the probability of success are p[]. When a task is completed or all tasks fail, the operation ends. Tasks are performed in a different order, and it is expected that the time to stop the action is generally different. Please answer in what order to perform the task in order to make the end of the expected action the shortest time? If the expected end time of the two task sequences is the same, the lexicographic minimum order of tasks is returned.



[color=rgba(0, 0, 0, 0.65098)]
  • 1≤n≤50,1≤ti≤10,0≤pi≤11≤n≤50,1≤ti≤10,0≤pi≤1
  • nn is a positive integer, titi is a positive integer, pipi is a floating-point number




[color=rgba(0, 0, 0, 0.65098)]Have you met this question in a real interview?  Yes
[color=rgba(0, 0, 0, 0.65098)][b]Example[/b]
Given n=1, t=[1], p=[1.0], return [1].
Explanation:The shortest expected action end time is 1.0*1+(1.0-1.0)*1=1.0
Given n=2, t=[1,2], p=[0.3, 0.7], return [2,1].
Explanation:The shortest expected action end time is 0.7*2+(1.0-0.7)*0.3*(2+1)+(1.0-0.7)*(1.0-0.3)*(2+1)=2.3

贴一个提交的代码:


class Solution {public:    /**     * @param n: The number of tasks     * @param t: The time array t     * @param p: The probability array p     * @return: Return the order     */    struct node    {        int id, t;        double p;        node()        {}        node(int id, int t, double p) : id(id), t(t), p(p)        {}    };    static bool comp(node &l, node &r)    {        return l.p * r.t > r.p * l.t || abs(l.p * r.t - r.p * l.t) < 1e-4 && l.id < r.id;    }    vector<int> getOrder(int n, vector<int> &t, vector<double> &p) {        // Write your code here        vector<node> a(n);        for(int i = 0; i < n; i++)            a[i] = node(i + 1, t[i], p[i]);        sort(a.begin(), a.end(), comp);        vector<int> res;        for(auto &it: a)            res.push_back(it.id);        return res;    }};





上一篇:lintcode 打卡贴
下一篇:刷题 打卡
🔗
 楼主| Saavedra 2018-8-20 00:21:58 | 只看该作者
全局:
吴亦几 发表于 2018-8-19 08:11
这题昨天lintcde测试了, 我有点后悔当时看了这个帖没细想。skrrrrrrr

我题也是看了才明白的, 他意思是 ...

这么一说那就明白了,多谢啦。
回复

使用道具 举报

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

本版积分规则

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