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 ...
随机推荐
- HashMap(常用)方法个人理解
Hashmap的存值: public static void main(String[] args) { ///*Integer*/map.put("1", 1);//向map ...
- (转)Android 升级 ADT 之后报错之一 case语句 .
转:http://blog.csdn.net/wchinaw/article/details/7325641 下面文章大意是指:在一般的Android项目中,R类的常量都是用final定义的,但ADT ...
- 分类算法之朴素贝叶斯分类(Naive Bayesian classification)
分类算法之朴素贝叶斯分类(Naive Bayesian classification) 0.写在前面的话 我个人一直很喜欢算法一类的东西,在我看来算法是人类智慧的精华,其中蕴含着无与伦比的美感.而每次 ...
- JSON关联属性转换异常
问题:FastJSON在转换对象过程中,该对象还有关联属性,该属性还是一个对象,就出现栈溢出异常,会报一下错误,解决办法:在该属性类的一边加上@JSONField(serialize=false);有 ...
- codeforces 1100D-Dasha and Chess
传送门:QAQQAQ 题意:This is an interactive task. 999*999国际象棋棋盘中有一个王和666个车,玩家走王,电脑走车,玩家先走,玩家的目的是让对方的车将到自己的王 ...
- 20.multi_case06
# coding:utf-8 import asyncio # 通过create_task()方法 async def a(t): print('-->', t) await asyncio.s ...
- USACO 2009 Open Treasure Cave /// DFS||并查集 oj26215
题目大意: 输入 p,n,t :p为地点数 判断 t 能否回到源点1 接下来n行 每行输入 a b c: a能到达b和c Sample Input 13 6 76 7 82 3 410 11 128 ...
- 线性回归代码实现(matlab)
1 代价函数实现(cost function) function J = computeCost(X, y, theta) %COMPUTECOST Compute cost for linear r ...
- CVE-2016-0095提权漏洞分析
1 前言 瞻仰了k0shl和鹏哥 的漏洞分析,感慨万千,任重而道远. 2 系统环境和工具 windows 7 32旗舰版 windbg 3 poc 3.1poc复现 首先k0shl大佬给出的poc() ...
- T2980 LR棋盘【Dp+空间/时间优化】
Online Judge:未知 Label:Dp+滚动+前缀和优化 题目描述 有一个长度为1*n的棋盘,有一些棋子在上面,标记为L和R. 每次操作可以把标记为L的棋子,向左移动一格,把标记为R的棋子, ...