<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- MyFirstUnitAd -->
<ins class="adsbygoogle"
     style="display:inline-block;width:970px;height:250px"
     data-ad-client="ca-pub-5778386704669218"
     data-ad-slot="1503492166"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>






<style type="text/css">
      <!--
        body { font-size: 12pt; font-family: Monospaced }
        pre { font-size: 12pt; font-family: Monospaced }
      -->
    </style>
<style type="text/css">
      <!--
        body { font-size: 12pt; font-family: Monospaced }
        pre { font-size: 12pt; font-family: Monospaced }
      -->
    </style> <style type="text/css">
      <!--
        body { font-size: 12pt; font-family: Monospaced }
        pre { font-size: 12pt; font-family: Monospaced }
      -->
    </style>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document"><title>top coder practice room(practice room1-16)(2001 invi-semi)</title>

<style>
<!--
table.MsoTableGrid
	{border:1.0pt solid windowtext;
	text-align:justify;
	text-justify:inter-ideograph;
	font-size:10.0pt;
	font-family:"Times New Roman";
	}
 li.MsoNormal
	{mso-style-parent:"";
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";
	margin-left:0cm; margin-right:0cm; margin-top:0cm}
-->
</style>
<style type="text/css">
      <!--
        body { font-family: Monospaced; font-size: 12pt }
        pre { font-family: Monospaced; font-size: 12pt }
      -->
    </style><style type="text/css">
      <!--
        body { font-family: Monospaced; font-size: 12pt }
        pre { font-family: Monospaced; font-size: 12pt }
      -->
    </style><style type="text/css">
      <!--
        body { font-size: 12pt; font-family: Monospaced }
        pre { font-size: 12pt; font-family: Monospaced }
      -->
    </style></head><body rightmargin="1" bottommargin="1" marginheight="1" marginwidth="1">



<p align="left"><span lang="en-ca"><font color="#ff0000" size="6"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
TopCoder practice room (purely for fun)</b></font></span></p><br>
Problem Statement<br>
&nbsp;&nbsp;&nbsp; <br>
Manao is building a new house. He already purchased a rectangular area
where he will place the house. The basement of the house should be
built on a level ground, so Manao will have to level the entire area.
The area is leveled if the difference between the heights of its lowest
and highest square meter is at most 1. Manao wants to measure the
effort he needs to put into ground leveling.&nbsp; You are given a
vector &lt;string&gt; area. Each character in area denotes the height
at the corresponding square meter of Manao's area. Using 1 unit of
effort, Manao can change the height of any square meter on his area by
1 up or down. Return the minimum total effort he needs to put to obtain
a leveled area.<br>
Definition<br>
&nbsp;&nbsp;&nbsp; <br>
Class:<br>
HouseBuilding<br>
Method:<br>
getMinimum<br>
Parameters:<br>
vector &lt;string&gt;<br>
Returns:<br>
int<br>
Method signature:<br>
int getMinimum(vector &lt;string&gt; area)<br>
(be sure your method is public)<br>
Limits<br>
&nbsp;&nbsp;&nbsp; <br>
Time limit (s):<br>
2.000<br>
Memory limit (MB):<br>
64<br>
Constraints<br>
-<br>
area will contain between 1 and 50 elements, inclusive.<br>
-<br>
Each element of area will be between 1 and 50 characters long, inclusive.<br>
-<br>
All elements of area will be of the same length.<br>
-<br>
Each element of area will contain digits ('0'-'9') only.<br>
Examples<br>
0)<br>
<br>
&nbsp;&nbsp;&nbsp; <br>
{"10",<br>
&nbsp;"31"}<br>
Returns: 2<br>
The given area is not leveled, because the minimum height is 0 and the
maximum height is 3. Manao needs to reduce the height of lower left
square by 2.<br>
1)<br>
<br>
&nbsp;&nbsp;&nbsp; <br>
{"54454",<br>
&nbsp;"61551"}<br>
Returns: 7<br>
In the optimal solution each square will have height either 4 or 5. To
reach such a configuration, Manao should reduce the height of one
square from 6 to 5, and increase the heights of two other squares from
1 to 4.<br>
2)<br>
<br>
&nbsp;&nbsp;&nbsp; <br>
{"989"}<br>
Returns: 0<br>
The area is already leveled.<br>
3)<br>
<br>
&nbsp;&nbsp;&nbsp; <br>
{"90"}<br>
Returns: 8<br>
<br>
4)<br>
<br>
&nbsp;&nbsp;&nbsp; <br>
{"5781252",<br>
&nbsp;"2471255",<br>
&nbsp;"0000291",<br>
&nbsp;"1212489"}<br>
Returns: 53<br>
<br>
This problem statement is the exclusive and proprietary property of
TopCoder, Inc. Any unauthorized use or reproduction of this information
without the prior written consent of TopCoder, Inc. is strictly
prohibited. (c)2003, TopCoder, Inc. All rights reserved.<br>
<br>
//////////////////////////////////////////////////////////////////////////////////<br>#include &lt;vector&gt;<br>
#include &lt;string&gt;<br>
<br>
using namespace std;<br>
<br>
<br>
class HouseBuilding<br>
{<br>
public:<br>
&nbsp;&nbsp;&nbsp; int getMinimum(vector&lt;string&gt; area)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int current = 199999999;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (char ch = '0'; ch &lt; '9'; ch ++)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int sum = 0;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (size_t i = 0; i &lt; area.size(); i ++)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (size_t j = 0; j &lt; area[i].size(); j ++)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbs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&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (sum &lt; current)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; current = sum;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return current;<br>
&nbsp;&nbsp;&nbsp; }<br>
};<br>
<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;</p>

</body></html>