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: 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)的更多相关文章
- CI Weekly #7 | Instgram/Quora 等大公司如何做持续部署?
终于,你们期待的 flow.ci iOS 项目持续集成 开始公测了.在这几个工作日, flow.ci 做了些许「功能优化」与「问题修复」,性能和体验都在持续优化中.比如: iOS 快速入门文档更新: ...
- [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 ...
- [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 ...
- POJ 1325 Machine Schedule——S.B.S.
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13731 Accepted: 5873 ...
- Spring Schedule 任务调度实现
我们都知道任务调度可以用Quartz,但对于简单的定时任务,可以直接用Spring内置的Schedule来实现.可以由两种方式,注释+XML配置 注解方式: 注解也要先在sping.xml配置文件中配 ...
- HDU 3572 Task Schedule(拆点+最大流dinic)
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 日常小测:颜色 && Hackerrank Unique_colors
题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...
- Spring Shedule Task之注解实现 (两次启动Schedule Task 的解决方案)
在spring 中的新引入的task 命名空间.可以部分取代 quartz 功能,配置和API更加简单,并且支持注解方式. 第一步: 在Spring的相关配置文件中(applicationContex ...
- Schedule 学习
现在做的项目都有用到Schedule,现在用一点时间来总结. 一.首先要到Nuget中下载Quartz.net. 二.下载下来了,你需要对它进行配置,使它能给你正常的使用. 三.在Global.asa ...
随机推荐
- 树形dp经典换根法——cf1187E
假设以u为根时结果是tot,现在转换到了以u的儿子v为根,那么结果变成了tot-size[v]+(sizetot-size[v]) 根据这个转移方程,先求出以1为根的tot,然后dfs一次转移即可 # ...
- Ubuntu下github pages+hexo搭建自己的博客
hexo 是一个基于Node.js的静态博客程序,可以方便的生成静态网页托管在github上.Hexo简单优雅, 而且风格多变, 适合搭建个人博客,而且支持多平台的搭建. 平台 Ubuntu14.04 ...
- (转) Mac下面的SecureCRT(附破解方案) 更新到最新的7.3.7
Mac下面的SecureCRT(附破解方案) 更新到最新的7.3.7 转自 http://blog.csdn.net/skykingf/article/details/17450561 http:// ...
- python三元运算符公式/出错怎么看
成功 if 条件 else 失败 Tip:问题要从下往上看,出问题的是最底下的问题,
- scrapy爬虫框架爬取招聘网站
目录结构 BossFace.py文件中代码: # -*- coding: utf-8 -*-import scrapyfrom ..items import BossfaceItemimport js ...
- Markdown使用语法
一.标题 一级标题为#号后加空格再加标题内容 二级标题为两个 # 号后加空格再加标题内容 以此类推,支持六级标题 二.字体 1. 加粗 在需要加粗的文字两侧分别用两个 * 包起来 2.斜体 在需要倾斜 ...
- WPF基础之Grid面板
一.显示 Grid的线条,设置ShowGridLiens="True".
- CSDN的验证码,真得很糟糕
这是以三种不同的高度来分割各字符 第一张图片是以宽度3来分割,可以看得出,验证码元素保存完好,但 Y 和 9 仍然连在一起 第二张图片是以宽度4来分割,看到了,N已经断了,肉眼虽然仍看得出来是N,但是 ...
- 2019-5-29-Roslyn-让-VisualStudio-急速调试底层库方法
title author date CreateTime categories Roslyn 让 VisualStudio 急速调试底层库方法 lindexi 2019-5-29 20:2:9 +08 ...
- Linux 下 Nand Flash 调用关系
Nand Flash 设备添加时数据结构包含关系 struct mtd_partition partition_info[] --> struct s3c2410_nand_set ...