题目链接

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. 0929CSP-S模拟测试赛后总结

    70分31名滚粗. 赛后发现赛时得到的分数全都是暴力分…… T2打的三分跑都没跑……边界设错了……赛后稍微调了调多了15分…… 据说有15分的暴力分,那么另外15分就是只有一种选择的情况了…… (如果 ...

  2. duilib教程之duilib入门简明教程13.复杂控件介绍

    首先将本节要介绍的控件全部拖到界面上,并调整好位置,如图:  然后将Name属性改成其他名字,         不能是[控件名+UI+数字]这种,因为这是DuiDesigner默认的名字,它不会实际写 ...

  3. 关于maven工程将model删除重建之后变为灰色的问题的解决

    问题描述: IDEA中的maven工程中有时候将model或者子model建错,删除之后,子模块在maven在侧栏的maven projects中是灰色的,而且是并没有依赖父工程 在网上搜了搜解决办法 ...

  4. Andriod Fragment 的作用和基本用法

    1.什么是Fragment: Fragment (片段)在Google Android 开发指南中的解释是:片段是Activity中的一部分,一个Activity中可以有多个Fragment.一个Fr ...

  5. tcp通信,解决断包、粘包的问题

    1.TCP和UDP的区别 TCP(transport control protocol,传输控制协议)是面向连接的,面向流的,提供高可靠性服务.收发两端(客户端和服务器端)都要有一一成对的socket ...

  6. 学SpringBoot一篇就够了

    1.SpringBoot概述 Spring 框架对于很多 Java 开发人员来说都不陌生.自从 2002 年发布以来,Spring 框架已经成为企业应用开发领域非常流行的基础框架.有大量的企业应用基于 ...

  7. 一文教会你用Python实现最有效的剪切板实时监控

    前言 上网浏览网页的时候,看见好的内容免不了要使用复制粘贴,但是我们看到的内容.心里想要的内容和实际粘贴后的内容往往不一致.数据的获取始于复制,终于粘贴,那么问题来了,在这中间系统做了哪些操作,我们怎 ...

  8. 开发环境、测试环境、生产环境、UAT环境、仿真环境详解

    版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/WYX15011474269/article ...

  9. C++命令行多文件编译(g++)

    在刚开始学Java时用命令行进行编译代码.而C++一直在用IDE, 这次尝试下命令行编译.vs下也可以用cl.exe.link.exe等命令来进行编译 但这次是通过安装MinGW来学习命令编译,主要用 ...

  10. linux流量监控iftop命令安装详解

    iftop跟nload差不多,也是捕获网卡流量的命令,nload的安装见之前发布的教程:http://www.cnblogs.com/catlee/p/5703541.html 开始安装.本文以cen ...