FB面经prepare: Task Schedule
每种task都有冷却时间,比如task1执行后,要经过interval时间后才能再次执行,求总共所需时间。
用HashMap保存每一个task的下一次可以开始执行的最早时间
package TaskSchedule;
import java.util.*; public class Solution {
public int schedule(int[] str, int recover) {
if (str==null || str.length==0) return 0;
if (recover == 0) return str.length;
int pos = 0;
int time = 0;
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
for (; pos<str.length; pos++) {
int cur = str[pos];
if (!map.containsKey(cur)) {
map.put(cur, time+recover+1);
}
else {
int lastApr = map.get(cur);
if (time >= lastApr) {
map.put(cur, time);
}
else {
pos--;
}
}
time++;
}
return time;
} /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Solution sol = new Solution();
System.out.println(sol.schedule(new int[]{1, 2, 3, 1, 2, 3}, 3)); } }
FB面经prepare: Task Schedule的更多相关文章
- FB面经prepare: task schedule II
followup是tasks是无序的. 一开始是有序的,比如说1, 1, 2, 1,一定要先执行第一个task1,然后等task1恢复,再执行第2个task1,再执行task2..... follow ...
- FB面经 Prepare: Task Schedule
tasks has cooldown time, give an input task id array, output finish time input: AABCA A--ABCA output ...
- [BestCoder Round #3] hdu 4907 Task schedule (模拟简单题)
Task schedule Problem Description 有一台机器,而且给你这台机器的工作表.工作表上有n个任务,机器在ti时间运行第i个任务,1秒就可以完毕1个任务. 有m个询问,每一个 ...
- HDU 3572 Task Schedule(拆点+最大流dinic)
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Task schedule 分类: 比赛 HDU 查找 2015-08-08 16:00 2人阅读 评论(0) 收藏
Task schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU3572 Task Schedule 【最大流】
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU4907——Task schedule(BestCoder Round #3)
Task schedule Description有一台机器,并且给你这台机器的工作表,工作表上有n个任务,机器在ti时间执行第i个任务,1秒即可完成1个任务.有m个询问,每个询问有一个数字q,表示如 ...
- hdu 3572 Task Schedule
Task Schedule 题意:有N个任务,M台机器.每一个任务给S,P,E分别表示该任务的(最早开始)开始时间,持续时间和(最晚)结束时间:问每一个任务是否能在预定的时间区间内完成: 注:每一个任 ...
- hdoj 3572 Task Schedule【建立超级源点超级汇点】
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- endsWith和startsWith同样效果其他形式的写法(2016.1.12)
//判断以什么开始startWith str = "abcdef"; //用其他的形式写的startsWith if(str.indexOf("abc")==0 ...
- Image Formats
http://www.html5rocks.com/en/tutorials/speed/img-compression/ https://developers.google.com/speed/we ...
- Spark 2.0
Apache Spark 2.0: Faster, Easier, and Smarter http://blog.madhukaraphatak.com/categories/spark-two/ ...
- 如何在html中插入视频
如何在html中插入视频 1,插入优酷视频: 在优酷分享界面有个html代码,直接复制放入body中,定义div的align居中即可 2.插入本地视频:用video属性 用mp4格式 <vid ...
- Abstract Algebra chapter 7
7.7:Encrypt each of the following RSA messages x so that x is divided into blocks of integers of len ...
- jquery mobile 方法收集.
1.在列表项和按钮上禁用文本截断 如果你的列表项或者按钮上是一个很长的文本,它将会被jQuery Mobile自动截断,要禁用这个截断设置,需要在CSS选择器上添加属性"white- ...
- 【Android测试】【随笔】与 “美丽说” 测试同事交流
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5405432.html 分享者简介 雪晗,3年+测试经验,现 ...
- ArcGIS API for Silverlight 调用GP服务加载等值线图层
原文:ArcGIS API for Silverlight 调用GP服务加载等值线图层 第二篇.Silverlight客户端调用GP服务 利用ArcGIS API for Silverlight实现G ...
- [LeetCode]题解(python):053-Maximum Subarray
题目来源 https://leetcode.com/problems/maximum-subarray/ Find the contiguous subarray within an array (c ...
- Introduction to Project Management(II)
Introduction The purpose of this paper is to gain an understanding of project management and to give ...