<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scheduling Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/scheduling/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/scheduling/</link>
	<description></description>
	<lastBuildDate>Thu, 19 Apr 2018 15:30:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>Scheduling Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/scheduling/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 621. Task Scheduler</title>
		<link>https://zxi.mytechroad.com/blog/greedy/leetcode-621-task-scheduler/</link>
					<comments>https://zxi.mytechroad.com/blog/greedy/leetcode-621-task-scheduler/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sat, 28 Oct 2017 18:36:53 +0000</pubDate>
				<category><![CDATA[Greedy]]></category>
		<category><![CDATA[Medium]]></category>
		<category><![CDATA[Scheduling]]></category>
		<category><![CDATA[task]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=706</guid>

					<description><![CDATA[<p>题目大意：给你一些用字母表示的任务，执行每个任务需要单位时间的CPU。对于相同的任务，CPU需要n个单位时间的冷却时间，期间可以执行其他不相同的任务。问最少多少时间可以完成所有任务。 Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/greedy/leetcode-621-task-scheduler/">花花酱 LeetCode 621. Task Scheduler</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><iframe width="500" height="375" src="https://www.youtube.com/embed/YCD_iYxyXoo?feature=oembed" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe></p>
<p>题目大意：给你一些用字母表示的任务，执行每个任务需要单位时间的CPU。对于相同的任务，CPU需要n个单位时间的冷却时间，期间可以执行其他不相同的任务。问最少多少时间可以完成所有任务。</p>
<p>Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one task or just be idle.</p>
<p>However, there is a non-negative cooling interval <b>n</b> that means between two <b>same tasks</b>, there must be at least n intervals that CPU are doing different tasks or just be idle.</p>
<p>You need to return the <b>least</b> number of intervals the CPU will take to finish all the given tasks.</p>
<p><b>Example 1:</b></p><pre class="crayon-plain-tag">Input: tasks = [&quot;A&quot;,&quot;A&quot;,&quot;A&quot;,&quot;B&quot;,&quot;B&quot;,&quot;B&quot;], n = 2
Output: 8
Explanation: A -&amp;gt; B -&amp;gt; idle -&amp;gt; A -&amp;gt; B -&amp;gt; idle -&amp;gt; A -&amp;gt; B.</pre><p><strong>N</strong><b>ote:</b></p>
<ol>
<li>The number of tasks is in the range [1, 10000].</li>
<li>The integer n is in the range [0, 100].</li>
</ol>
<p><strong>Idea:</strong></p>
<p>Counting</p>
<p>Time complexity: O(n)</p>
<p>Space complexity: O(1)</p>
<p>&nbsp;</p><pre class="crayon-plain-tag">// Author: Huahua
// Runtime: 56 ms
class Solution {
public:
    int leastInterval(vector&lt;char&gt;&amp; tasks, int n) {
        vector&lt;int&gt; count(26, 0);        
        for (const char task : tasks) 
            ++count[task - 'A'];
        const int max_count = *max_element(count.begin(), count.end());
        size_t ans = (max_count - 1) * (n + 1);
        ans += count_if(count.begin(), count.end(),
                        [max_count](int c){ return c == max_count; });
        return max(tasks.size(), ans);
    }
};</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/greedy/leetcode-621-task-scheduler/">花花酱 LeetCode 621. Task Scheduler</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/greedy/leetcode-621-task-scheduler/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
