zoukankan      html  css  js  c++  java
  • Schedule(Hackerrank Quora Haqathon)

    题目链接

    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: 106
    • 1N100
    • 1Ti100
    • 0Pi1

    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. 从而总结出他们之间的关系。然后推广到多个的情况。

    附上代码:

     1 #include <cstdio>
     2 #include <algorithm>
     3 using namespace std;
     4 
     5 int t[100], id[100];
     6 double p[100];
     7 
     8 bool cmp(int i, int j) {
     9     return (t[i] * (1.0 - p[j]) < t[j] * (1.0 - p[i]));
    10 }
    11 
    12 int main(void) {
    13     int N, i;
    14     scanf("%d", &N);
    15 
    16     for (i = 0; i < N; i++) {
    17             scanf("%d %lf", t + i, p + i);
    18             id[i] = i;
    19     }
    20 
    21     sort(id, id + N, cmp);
    22 
    23     double ans = 0.0, c = 1.0;
    24     int s = 0.9;
    25     for (i = 0; i < N - 1; i++) {
    26         s += t[id[i]];
    27         ans += c * (1 - p[id[i]]) * s;
    28         c *= p[id[i]];
    29     }
    30     s += t[id[N-1]];
    31     ans += c * s;
    32 
    33     printf("%.17f
    ", ans);
    34 
    35     return 0;
    36 }
  • 相关阅读:
    MVC3中输出Html标签的方法
    Server.MapPath 出现未将对象引用设置到对象的实例
    谈谈网站静态化
    WCF 服务应用程序与 服务库之间的区别
    插入中国所有省和市的SQL语句--以后用
    KiCad 元件值 F4NNIU 规范 (2020-04-30)[31.98%]
    FastAdmin 安装后点登录没有反应怎么办?
    笔记:读英国老太太的复仇计划 (2019-10-15)
    KiCad 工程用 Git 管理需要忽略哪些文件?
    关于 SSD 的接口和相关名词(2019-09-10)
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/4237130.html
Copyright © 2011-2022 走看看