﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Vontroy-随笔分类-贪心</title><link>http://www.cppblog.com/vontroy/category/15065.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 19 Jan 2013 07:58:14 GMT</lastBuildDate><pubDate>Sat, 19 Jan 2013 07:58:14 GMT</pubDate><ttl>60</ttl><item><title>HDU 3661 Assignments-2010 Harbin Regional</title><link>http://www.cppblog.com/vontroy/archive/2010/10/03/128409.html</link><dc:creator>Vontroy</dc:creator><author>Vontroy</author><pubDate>Sun, 03 Oct 2010 00:36:00 GMT</pubDate><guid>http://www.cppblog.com/vontroy/archive/2010/10/03/128409.html</guid><wfw:comment>http://www.cppblog.com/vontroy/comments/128409.html</wfw:comment><comments>http://www.cppblog.com/vontroy/archive/2010/10/03/128409.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/vontroy/comments/commentRss/128409.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/vontroy/services/trackbacks/128409.html</trackback:ping><description><![CDATA[<h1 style="color: #1a5cc8" align="center">Assignments</h1>
<p align="center"><font size="+0"><strong><span style="font-family: Arial; color: green; font-size: 12px; font-weight: bold">Time Limit: 4000/2000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)<br />Total Submission(s): 252&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 125<br /></span></strong></font><br /><br /></p>
<div class="panel_title" align="left"><strong>Problem Description</strong></div>
<div class="panel_content">In a factory, there are N workers to finish two types of tasks (A and B). Each type has N tasks. Each task of type A needs xi time to finish, and each task of type B needs yj time to finish, now, you, as the boss of the factory, need to make an assignment, which makes sure that every worker could get two tasks, one in type A and one in type B, and, what's more, every worker should have task to work with and every task has to be assigned. However, you need to pay extra money to workers who work over the standard working hours, according to the company's rule. The calculation method is described as follow: if someone&#8217; working hour t is more than the standard working hour T, you should pay t-T to him. As a thrifty boss, you want know the minimum total of overtime pay.</div>
<div class="panel_bottom">&nbsp;</div>
<br />
<div class="panel_title" align="left"><strong>Input</strong></div>
<div class="panel_content">There are multiple test cases, in each test case there are 3 lines. First line there are two positive Integers, N (N&lt;=1000) and T (T&lt;=1000), indicating N workers, N task-A and N task-B, standard working hour T. Each of the next two lines has N positive Integers; the first line indicates the needed time for task A1, A2&#8230;An (Ai&lt;=1000), and the second line is for B1, B2&#8230;Bn (Bi&lt;=1000).</div>
<div class="panel_bottom">&nbsp;</div>
<br />
<div class="panel_title" align="left"><strong>Output</strong></div>
<div class="panel_content">For each test case output the minimum Overtime wages by an integer in one line.</div>
<div class="panel_bottom">&nbsp;</div>
<br />
<div class="panel_title" align="left"><strong>Sample Input</strong></div>
<div class="panel_content">
<pre><div style="font-family: Courier New,Courier,monospace">2 5
4 2
3 5</div>
</pre>
</div>
<div class="panel_bottom">&nbsp;</div>
<br />
<div class="panel_title" align="left"><strong>Sample Output</strong></div>
<div class="panel_content">
<pre><div style="font-family: Courier New,Courier,monospace">4</div>
</pre>
</div>
<div class="panel_bottom">&nbsp;<br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><span style="color: #008000">//</span><span style="color: #008000">简单贪心</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1000</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">5</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;cmp(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b&nbsp;)<br /><img id="Codehighlighter1_142_162_Open_Image" onclick="this.style.display='none'; Codehighlighter1_142_162_Open_Text.style.display='none'; Codehighlighter1_142_162_Closed_Image.style.display='inline'; Codehighlighter1_142_162_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_142_162_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_142_162_Closed_Text.style.display='none'; Codehighlighter1_142_162_Open_Image.style.display='inline'; Codehighlighter1_142_162_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_142_162_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_142_162_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;a&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;b;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_176_620_Open_Image" onclick="this.style.display='none'; Codehighlighter1_176_620_Open_Text.style.display='none'; Codehighlighter1_176_620_Closed_Image.style.display='inline'; Codehighlighter1_176_620_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_176_620_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_176_620_Closed_Text.style.display='none'; Codehighlighter1_176_620_Open_Image.style.display='inline'; Codehighlighter1_176_620_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_176_620_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_176_620_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[maxn],&nbsp;b[maxn];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,&nbsp;t,&nbsp;ans&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;t&nbsp;)<br /><img id="Codehighlighter1_258_604_Open_Image" onclick="this.style.display='none'; Codehighlighter1_258_604_Open_Text.style.display='none'; Codehighlighter1_258_604_Closed_Image.style.display='inline'; Codehighlighter1_258_604_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_258_604_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_258_604_Closed_Text.style.display='none'; Codehighlighter1_258_604_Open_Image.style.display='inline'; Codehighlighter1_258_604_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_258_604_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_258_604_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;a[i];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;b[i];<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(&nbsp;a,&nbsp;a&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;n&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(&nbsp;b,&nbsp;b&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;n,&nbsp;cmp&nbsp;);<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;a[i]&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;b[i]&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;t&nbsp;)<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;a[i]&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;b[i]&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;t;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;ans&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;endl;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"  alt="" /></span></div></div><img src ="http://www.cppblog.com/vontroy/aggbug/128409.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/vontroy/" target="_blank">Vontroy</a> 2010-10-03 08:36 <a href="http://www.cppblog.com/vontroy/archive/2010/10/03/128409.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>