题目链接

Problem Statement

At Quora, we run all our unit tests across many machines in a test cluster on every code push.

One day, we decided to see if we could optimize our test cluster for cost efficiency by using only one machine to run all N tests.

Suppose we know two things about each test: the time needed to run this test, Ti, and the probability that this test will pass, Pi.

Given these as input, come up with the minimum expected time (based on the optimal ordering of the tests) of getting “go or no go” feedback on the code push, i.e. the expected time when we understand that either i) at least one test has failed, or that ii) all tests have passed.

Constraints

  • Accuracy threshold for evaluating floats: 10−6
  • 1≤N≤100
  • 1≤Ti≤100
  • 0≤Pi≤1

Input Format

Line 1: One integer N

Line 2..N+1: One integer Ti and one float Pi separated by one space.

Output Format

Line 1: One float, the minimum expected time

Sample Input

3
3 0.1
7 0.5
9 0.2

Sample Output

4.04

很久之前看的一道题,标签是easy可就是想不到如何做。

问了woshilalala之后,才豁然开朗。对于这种题我就是束手无策。

这种贪心的题目,首先可以假设n = 2. 从而总结出他们之间的关系。然后推广到多个的情况。

附上代码:

 #include <cstdio>
#include <algorithm>
using namespace std; int t[], id[];
double p[]; bool cmp(int i, int j) {
return (t[i] * (1.0 - p[j]) < t[j] * (1.0 - p[i]));
} int main(void) {
int N, i;
scanf("%d", &N); for (i = ; i < N; i++) {
scanf("%d %lf", t + i, p + i);
id[i] = i;
} sort(id, id + N, cmp); double ans = 0.0, c = 1.0;
int s = 0.9;
for (i = ; i < N - ; i++) {
s += t[id[i]];
ans += c * ( - p[id[i]]) * s;
c *= p[id[i]];
}
s += t[id[N-]];
ans += c * s; printf("%.17f\n", ans); return ;
}

Schedule(Hackerrank Quora Haqathon)的更多相关文章

  1. CI Weekly #7 | Instgram/Quora 等大公司如何做持续部署?

    终于,你们期待的 flow.ci iOS 项目持续集成 开始公测了.在这几个工作日, flow.ci 做了些许「功能优化」与「问题修复」,性能和体验都在持续优化中.比如: iOS 快速入门文档更新: ...

  2. [LeetCode] Course Schedule II 课程清单之二

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

  3. [LeetCode] Course Schedule 课程清单

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

  4. POJ 1325 Machine Schedule——S.B.S.

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13731   Accepted: 5873 ...

  5. Spring Schedule 任务调度实现

    我们都知道任务调度可以用Quartz,但对于简单的定时任务,可以直接用Spring内置的Schedule来实现.可以由两种方式,注释+XML配置 注解方式: 注解也要先在sping.xml配置文件中配 ...

  6. HDU 3572 Task Schedule(拆点+最大流dinic)

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. 日常小测:颜色 && Hackerrank Unique_colors

    题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...

  8. Spring Shedule Task之注解实现 (两次启动Schedule Task 的解决方案)

    在spring 中的新引入的task 命名空间.可以部分取代 quartz 功能,配置和API更加简单,并且支持注解方式. 第一步: 在Spring的相关配置文件中(applicationContex ...

  9. Schedule 学习

    现在做的项目都有用到Schedule,现在用一点时间来总结. 一.首先要到Nuget中下载Quartz.net. 二.下载下来了,你需要对它进行配置,使它能给你正常的使用. 三.在Global.asa ...

随机推荐

  1. 常用css初始化样式(淘宝)

    最简单粗暴的css初始化样式就是:*{padding:0:margin:0}(不推荐) 淘宝的样式初始化: body, h1, h2, h3, h4, h5, h6, hr, p, blockquot ...

  2. CF 1063B Labyrinth

    传送门 解题思路 看上去很简单,\(bfs\)写了一发被\(fst\)...后来才知道好像一群人都被\(fst\)了,这道题好像那些每个点只经过一次的传统\(bfs\)都能被叉,只需要构造出一个一块一 ...

  3. js文件操作之——导出Excel (js-xlsx)

    前阵子跟server同学讨论一个Excel导出的需求,我说JS搞不定,需要server来做,被server同学强行打脸. 今天研究了下,尼玛,不光可以,还很强大了! 总结:经验是害人的,尤其是在发展迅 ...

  4. 第六篇:fastJson常用方法总结

    1.了解json json就是一串字符串 只不过元素会使用特定的符号标注. {} 双括号表示对象 [] 中括号表示数组 "" 双引号内是属性或值 : 冒号表示后者是前者的值(这个值 ...

  5. Activiti流程图查看

    1.测试用例查看图片 public void viewImage() throws Exception { // 创建仓库服务对对象 RepositoryService repositoryServi ...

  6. No packages marked for update

    问题:用yum安装docker,更新yum存储时,报以下错误,导致yum坏了 [root@localhost yum.repos.d]# vi docker.repo [root@localhost ...

  7. CycloneII lcell_comb 和 lcell_FF 的结构

    1,lcell_comb结构 2,lcell_FF结构 from : cycloneii_eda_fd.pdf

  8. Linux命令查看文件内容

    cat:一次性顺序显示文件所有内容和 cat filename tac:一次性倒序显示文件所有内容和 tac filename head:显示文件开头的若干行内容 head -n filename t ...

  9. JOIN方法也是连贯操作方法之一

    JOIN方法也是连贯操作方法之一,用于根据两个或多个表中的列之间的关系,从这些表中查询数据. 大理石平台规格 join通常有下面几种类型,不同类型的join操作会影响返回的数据结果. INNER JO ...

  10. wget: command not found 解决方案

    wget: command not found 解决方案 wget command not found 解决方案 问题分析 解决方案 方法一yum安装wget 方法二rpm安装 问题分析 安装的是Ce ...