<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Kosei::WebLog</title>
	<atom:link href="http://cou929.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://cou929.wordpress.com</link>
	<description>Daily life from Tokyo. Programming, Web, Technology, Music and so on.</description>
	<lastBuildDate>Tue, 03 May 2011 13:17:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='cou929.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Kosei::WebLog</title>
		<link>http://cou929.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://cou929.wordpress.com/osd.xml" title="Kosei::WebLog" />
	<atom:link rel='hub' href='http://cou929.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Move to Posterous</title>
		<link>http://cou929.wordpress.com/2011/05/03/move-to-posterous/</link>
		<comments>http://cou929.wordpress.com/2011/05/03/move-to-posterous/#comments</comments>
		<pubDate>Tue, 03 May 2011 13:12:24 +0000</pubDate>
		<dc:creator>Kosei</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://cou929.wordpress.com/?p=237</guid>
		<description><![CDATA[This blog move to posterous now. Bad Timing And my personal site I also migrate almost entries to posterous blog. Thanks.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=237&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This blog move to <a title="Bad Timing" href="http://blog.cou929.nu/">posterous</a> now.</p>
<p><a title="Bad Timing" href="http://blog.cou929.nu/">Bad Timing</a></p>
<p><a href="http://cou929.nu/">And my personal site</a></p>
<p>I also migrate almost entries to posterous blog.</p>
<p>Thanks.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cou929.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cou929.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cou929.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cou929.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cou929.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cou929.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cou929.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cou929.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cou929.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cou929.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cou929.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cou929.wordpress.com/237/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cou929.wordpress.com/237/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cou929.wordpress.com/237/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=237&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cou929.wordpress.com/2011/05/03/move-to-posterous/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f7647a55b45c08dc47d0c520ad0264c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cou929</media:title>
		</media:content>
	</item>
		<item>
		<title>SRM 462 div1</title>
		<link>http://cou929.wordpress.com/2010/02/18/srm-462-div1/</link>
		<comments>http://cou929.wordpress.com/2010/02/18/srm-462-div1/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 08:33:31 +0000</pubDate>
		<dc:creator>Kosei</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[TopCoder]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://cou929.wordpress.com/?p=231</guid>
		<description><![CDATA[Submitted 250 problem but challenged. The result was 0pt and rating was 1257. The rating slightly gained but I&#8217;m not satisfied the result. Also the result of the SRM had been 0pt in which recent 3 matches. Easy &#8211; AgeEncoding The algorithm for this problem is not so hard, this is just a problem for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=231&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Submitted 250 problem but challenged. The result was 0pt and rating was 1257. The rating slightly gained but I&#8217;m not satisfied the result. Also the result of the SRM had been 0pt in which recent 3 matches. </p>
<h3><a href="http://www.topcoder.com/stat?c=problem_statement&amp;pm=10589&amp;rd=14147">Easy &#8211; AgeEncoding</a></h3>
<p>The algorithm for this problem is not so hard, this is just a problem for searching the solution with binary search. However, the most difficult point is consideration for corner cases. According to problem statement, we should return -1 if there is no solution and -2 if there are multiple solution. And it was very hard to notice all cases of such conditions. Many coders had been challenged or failed system test. It seems that almost of them hadn&#8217;t noticed the case whose input are, for instance, age = 1 and candlesLine = &#8220;11111&#8243;. In this case the correct answer is -1, not 0, since return value must be &#8220;strictly positive&#8221;. </p>
<pre class="brush: cpp;">
class AgeEncoding {
public:
  double getRadix(int age, string candlesLine) {
    double ret = 0;
    int i, j;
    int n = candlesLine.size();
    int one_num = count(candlesLine.begin(), candlesLine.end(), '1');

    if (one_num == 0) return -1;
    if (candlesLine[n-1] == '1')
      if (age == 1)
        if (one_num == 1) return -2;
        else return -1;
      else
        if (one_num == 1) return -1;

    double left = 0, right = 100;
    for (i=0; i&lt;1000; i++) {
      ret = (left + right) * 0.5;
      double ans = 0;
      double B = 1;

      for (j=n-1; j&gt;=0; j--) {
        ans += (candlesLine[j] - '0') * B;
        B *= ret;
      }

      if (ans &gt; age)
        right = ret;
      else
        left = ret;
    }

    return ret;
  }
};
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cou929.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cou929.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cou929.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cou929.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cou929.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cou929.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cou929.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cou929.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cou929.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cou929.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cou929.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cou929.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cou929.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cou929.wordpress.com/231/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=231&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cou929.wordpress.com/2010/02/18/srm-462-div1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f7647a55b45c08dc47d0c520ad0264c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cou929</media:title>
		</media:content>
	</item>
		<item>
		<title>Modifying TZTester</title>
		<link>http://cou929.wordpress.com/2010/02/08/modifying-tztester/</link>
		<comments>http://cou929.wordpress.com/2010/02/08/modifying-tztester/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 02:53:56 +0000</pubDate>
		<dc:creator>Kosei</dc:creator>
				<category><![CDATA[TopCoder]]></category>

		<guid isPermaLink="false">http://cou929.wordpress.com/?p=210</guid>
		<description><![CDATA[TZTester is one of a great plugin for TopCoder SRM. It adds sample test cases of problem statements into the local code automatically (which is generated by CodeProcessor plugin, normally). This function encourages us to write the code as test-first, this is quite helpful to find bugs and fix it quickly. How to introduce these [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=210&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.topcoder.com/contest/classes/TZTester/TZTester.html">TZTester</a> is one of a great plugin for TopCoder SRM. It adds sample test cases of problem statements into the local code automatically (which is generated by <a href="http://www.topcoder.com/contest/classes/CodeProcessor/How%20to%20use%20CodeProcessor%20v2.htm">CodeProcessor</a> plugin, normally). This function encourages us to write the code as test-first, this is quite helpful to find bugs and fix it quickly. How to introduce these plugins is described here: </p>
<p><a href="https://www.topcoder.com/wiki/display/tc/How+to+install+The+Arena+plug-ins">How to install The Arena plug-ins &#8211; TopCoder Wiki</a></p>
<p>However, I had little two dissatisfaction about generated test cases of TZTester. </p>
<ol>
<li>There are no enough new lines in test cases. This makes little hard to add new own test cases.</li>
<li>I&#8217;d like to put more two cases into the tail of test cases. This intends that it enforce me to think about another tests for considering corner cases or worst cases.</li>
</ol>
<p>So I&#8217;ve tried to modify my TZTester. </p>
<h2>How to modify</h2>
<p>TZTester is written in Java. I&#8217;ve had a little experience for java development. So I&#8217;ve confused several times for modification. Because of this, this section is maybe so dully for java programmer.</p>
<h3>Step 1: Extract .jar file</h3>
<p>TZTester is distributed as .jar file format. &#8220;.jar&#8221; file is just a zip file. I don&#8217;t know about the difference between jar and zip. So don&#8217;t be afraid.If Java development environment has been set up on your system, perhaps there are &#8220;jar&#8221; command. In my case (Mac OSX), the command seems to be bundled. You can extract and compress jar file by this command. The interface of jar command is quite similar to tar command:</p>
<pre class="brush: plain; wrap-lines: false;">
// extracting
% jar -xvf foo.jar

// compressing
% jar -cvf foo.jar foo bar baz/
</pre>
<p>If you don&#8217;t have a jar command, try unzip command since jar file is just a zip file, again.Now let&#8217;s extract a TZTester.jar. If you type this command:</p>
<pre class="brush: plain; wrap-lines: false;">
% jar -xvf TZTester.jar
</pre>
<p>Then you will get these files:</p>
<ul>
<li>tangentz/
<ul>
<li>TZTester.java</li>
<li>TZTester.class</li>
<li>TZTester.html</li>
</ul>
</li>
<li>META-INF/</li>
</ul>
<p>The only important file is TZTester.java. This is a source code of TZTester. TZTester.class is a compiled file of TZTester.java, and TZTester.html is just a manual file. </p>
<h3>Step 2: Editting TZTester.java</h3>
<p>Now we could get a source code of TZTester. So only you have to do is editing this code. For instance, you&#8217;d like to modify test cases, these are generated by generate_test_case() or generate_parameter() method.</p>
<h3>Step 3: Compiling TZTester.java, and make TZTester.jar</h3>
<p>Before compiling, TZTester requires ContestApplet.jar file, so you need to get this jar. <a href="http://www.topcoder.com/contest/classes/ContestApplet.jar">ContestApplet.jar could be downloaded from here</a>. And then put the downloaded ContestApplet.jar file to same directory with tangentz/. ContestApplet.jar contains classes, which is used by TZTester. Also you need to pay attention to the directories, put the source code in tangetz/ directory, ContestApplet.jar and Makefile (describe later) in same directory with tangentz/ itself. </p>
<pre class="brush: plain; wrap-lines: false;">
your_working_dir/
| -- ContestApplet.jar
| -- Makefile
` -- tangentz/
     |-- TZTester.java
     `-- (TZTester.class)
</pre>
<p>For compiling, firstly just type this commands in &#8220;your_working_dir&#8221;:</p>
<pre class="brush: plain; wrap-lines: false;">
% javac -classpath ContestApplet.jar tangentz/TZTester.java
</pre>
<p>Then TZTester.class is generated. Next step, make jar file from .class file. </p>
<pre class="brush: plain; wrap-lines: false;">
% jar cvf TZTester.jar tangentz/TZTester.class
</pre>
<p>It&#8217;s convenient to make such Makefile and put it in &#8220;yoru_working_dir&#8221;:</p>
<pre class="brush: plain; wrap-lines: false;">
jar: class
        jar cvf TZTester.jar tangentz/TZTester.class
class:
        javac -classpath ContestApplet.jar tangentz/TZTester.java
</pre>
<p>The final step is just replacing your existing TZTester.jar by this new modified one. </p>
<h2>My modification</h2>
<p>I&#8217;ve pushed my TZTester.java code to my github repository. </p>
<p><a href="http://github.com/cou929/topcoder/blob/master/plugin/modify_TZTester/build/tangentz/TZTester.java">plugin/modify_TZTester/build/tangentz/TZTester.java at master from cou929&#8242;s topcoder &#8211; GitHub</a></p>
<p>I&#8217;ve modified these two points.</p>
<ul>
<li>Add new lines to test cases. Append &#8220;\t&#8221; to argument of Code.appen() in generate_test_code(), generate_test_case() and generate_parameter()</li>
<li>Append additional two test cases which contents are same to test case #0. Call generate_test_case() method two times more.</li>
</ul>
<h2>Other modifications</h2>
<p>There are another modifications. <a href="http://www.topcoder.com/tc?module=MemberProfile&amp;cr=10574855&amp;tab=alg">Petr</a> displays his TZTester:</p>
<p><a href="http://petr-mitrichev.blogspot.com/2008/10/screencast-and-challenging.html">Algorithm problems for dummies: Petr Mitrichev&#8217;s blog: Screencast and challenging</a></p>
<p>The TZTester.jar file itself is <a href="http://77.41.63.3/TZTester.jar">here</a>. This is modified for C# code generation.</p>
<p><a href="http://www.topcoder.com/tc?module=MemberProfile&amp;cr=22758647">cafelier</a> also shows his modification (in Japanese). </p>
<p><a href="http://topcoder.g.hatena.ne.jp/cafelier/20081203/1228315218">TZTester をどうにかする &#8211; cafelier@SRM &#8211; TopCoder部</a></p>
<p>The zipped file itself is <a href="http://www.kmonos.net/wlog/sub/CFLCustom2-TZTester.zip">here</a>. He did a lot of changes such as put the test codes in global, measure processing time and so on.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cou929.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cou929.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cou929.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cou929.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cou929.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cou929.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cou929.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cou929.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cou929.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cou929.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cou929.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cou929.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cou929.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cou929.wordpress.com/210/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=210&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cou929.wordpress.com/2010/02/08/modifying-tztester/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f7647a55b45c08dc47d0c520ad0264c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cou929</media:title>
		</media:content>
	</item>
		<item>
		<title>SRM 405 div2 (practice)</title>
		<link>http://cou929.wordpress.com/2010/02/03/srm-405-div2-practice/</link>
		<comments>http://cou929.wordpress.com/2010/02/03/srm-405-div2-practice/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 14:45:23 +0000</pubDate>
		<dc:creator>Kosei</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[TopCoder]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://cou929.wordpress.com/?p=208</guid>
		<description><![CDATA[Easy &#8211; FallingFactorialPower For implementing quickly, consider conditions (k 0), and calculate the answer respectively using the for loop. Medium &#8211; RelativePath Took a quick string processing-like approach. First of all, divide the two strings by &#8220;/&#8221; and store into two vectors. Check the vectors simultaneously to find an index that the first time two [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=208&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><a href="http://www.topcoder.com/stat?c=problem_statement&amp;pm=9761&amp;rd=12177">Easy &#8211; FallingFactorialPower</a></h3>
<p>For implementing quickly, consider conditions (k  0), and calculate the answer respectively using the for loop.</p>
<pre class="brush: cpp;">
class FallingFactorialPower {
public:
  double compute(int n, int k) {
    double ret = 1;

    if (k &lt; 0)
      for (int i=1; i&lt;=abs(k); i++)
        ret /= (double)(n + i);
    else if (k &gt; 0)
      for (int i=0; i&lt;k; i++)
        ret *= (double)(n - i);

    return ret;
  }
};
</pre>
<h3><a href="http://www.topcoder.com/stat?c=problem_statement&amp;pm=9760&amp;rd=12177">Medium &#8211; RelativePath</a></h3>
<p>Took a quick string processing-like approach. First of all, divide the two strings by &#8220;/&#8221; and store into two vectors. Check the vectors simultaneously to find an index that the first time two element of vectors are differ. Then append &#8220;../&#8221; to reach such index, and also append paths behind from such index.</p>
<pre class="brush: cpp;">
class RelativePath {
public:
  vector &lt;string&gt; split(const string _s, const string del) {
    vector &lt;string&gt; ret;
    string s = _s;

    while (!s.empty())
      {
        size_t pos = s.find(del);
        string sub = &quot;&quot;;
        sub = s.substr(0, pos);
        ret.push_back(sub);
        if (pos != string::npos)
          pos += del.size();
        s.erase(0, pos);
      }

    return ret;
  }

  string makeRelative(string path, string currentDir) {
    string ret;

    vector &lt;string&gt; p = split(path, &quot;/&quot;);
    vector &lt;string&gt; c = split(currentDir, &quot;/&quot;);

    int i = 0, n = min(p.size(), c.size());
    for (i=0; i&lt;n; i++)
      if (p[i] != c[i]) break;

    for (int j=0; j&lt;c.size() - i; j++)
      ret += &quot;../&quot;;
    for (int j=i; j&lt;p.size(); j++)
      ret += p[j] + &quot;/&quot;;

    ret.erase(ret.end()-1);

    return ret;
  }
};
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cou929.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cou929.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cou929.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cou929.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cou929.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cou929.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cou929.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cou929.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cou929.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cou929.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cou929.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cou929.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cou929.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cou929.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=208&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cou929.wordpress.com/2010/02/03/srm-405-div2-practice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f7647a55b45c08dc47d0c520ad0264c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cou929</media:title>
		</media:content>
	</item>
		<item>
		<title>SRM 431 div1 (practice)</title>
		<link>http://cou929.wordpress.com/2010/02/01/srm-431-div1-practice/</link>
		<comments>http://cou929.wordpress.com/2010/02/01/srm-431-div1-practice/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 12:40:56 +0000</pubDate>
		<dc:creator>Kosei</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[TopCoder]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://cou929.wordpress.com/?p=206</guid>
		<description><![CDATA[Easy &#8211; LaserShooting Calculate expected numbers for each obstacles, and then sum up these numbers. The way to calculate the expected number for the obstacle is that (the angle of laser to hit the obstacle) / (pi). In this problem the position (x, y) of obstacle is given, so we can calculate the angle using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=206&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><a href="http://www.topcoder.com/stat?c=problem_statement&amp;pm=10258&amp;rd=13522">Easy &#8211; LaserShooting</a></h3>
<p>Calculate expected numbers for each obstacles, and then sum up these numbers. The way to calculate the expected number for the obstacle is that (the angle of laser to hit the obstacle) / (pi). In this problem the position (x, y) of obstacle is given, so we can calculate the angle using arc tangent.</p>
<pre class="brush: cpp;">
class LaserShooting {
public:
  double numberOfHits(vector &lt;int&gt; x, vector &lt;int&gt; y1, vector &lt;int&gt; y2) {
    double ret = 0;

    for (int i=0; i&lt;x.size(); i++) {
      double ang1 = atan((double)y1[i] / (double)x[i]);
      double ang2 = atan((double)y2[i] / (double)x[i]);
      ret += abs(ang1 - ang2) / M_PI;
    }

    return ret;
  }
};
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cou929.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cou929.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cou929.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cou929.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cou929.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cou929.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cou929.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cou929.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cou929.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cou929.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cou929.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cou929.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cou929.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cou929.wordpress.com/206/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=206&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cou929.wordpress.com/2010/02/01/srm-431-div1-practice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f7647a55b45c08dc47d0c520ad0264c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cou929</media:title>
		</media:content>
	</item>
		<item>
		<title>SRM 433 div1 (practice)</title>
		<link>http://cou929.wordpress.com/2010/01/28/srm-433-div1-practice/</link>
		<comments>http://cou929.wordpress.com/2010/01/28/srm-433-div1-practice/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 01:35:41 +0000</pubDate>
		<dc:creator>Kosei</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[TopCoder]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://cou929.wordpress.com/?p=204</guid>
		<description><![CDATA[Easy &#8211; MagicWords According to &#8220;Constrains&#8221;, S contains up to 8 element and maximum length of each elements are 20. So there is 8! * 20 * 8 = 6451200 steps in the largest input case. This is seems that we can solve this problem simply searching all permutations. I&#8217;ve coded as such, but in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=204&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><a href="http://www.topcoder.com/stat?c=problem_statement&amp;pm=10195&amp;rd=13695">Easy &#8211; MagicWords</a></h3>
<p>According to &#8220;Constrains&#8221;, S contains up to 8 element and maximum length of each elements are 20. So there is 8! * 20 * 8 = 6451200 steps in the largest input case. This is seems that we can solve this problem simply searching all permutations. I&#8217;ve coded as such, but in the largest case (such as test case #6), it has took too long time, therefore introduced memorization using std::map. Then the code is optimized, passed system test. </p>
<pre class="brush: cpp;">
class MagicWords {
public:
  map &lt;string, int&gt; memo;

  bool isMagic(string &amp;str, int pos) {
    int len = str.size();
    for (int i=0; i&lt;len; i++)
      if (str[i] != str[(i+pos)%len])
        return false;
    return true;
  }

  int count(vector &lt;string&gt; S, int K) {
    int ret = 0;
    vector &lt;int&gt; pos;
    for (int i=0; i&lt;S.size(); i++) pos.push_back(i);

    do {
      string str;
      int magic = 0;
      for (int i=0; i&lt;S.size(); i++) str += S[pos[i]];
      if (memo.find(str) != memo.end())
        magic = memo[str];
      else
        for (int i=0; i&lt;str.size(); i++) if (isMagic(str, i)) magic++;
      memo[str] = magic;
      if (magic == K) ret++;
    } while (next_permutation(pos.begin(), pos.end()));

    return ret;
  }
};
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cou929.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cou929.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cou929.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cou929.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cou929.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cou929.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cou929.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cou929.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cou929.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cou929.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cou929.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cou929.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cou929.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cou929.wordpress.com/204/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=204&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cou929.wordpress.com/2010/01/28/srm-433-div1-practice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f7647a55b45c08dc47d0c520ad0264c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cou929</media:title>
		</media:content>
	</item>
		<item>
		<title>SRM 435 div1 (practice)</title>
		<link>http://cou929.wordpress.com/2010/01/25/srm-435-div1-practice/</link>
		<comments>http://cou929.wordpress.com/2010/01/25/srm-435-div1-practice/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 01:57:13 +0000</pubDate>
		<dc:creator>Kosei</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[TopCoder]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://cou929.wordpress.com/?p=202</guid>
		<description><![CDATA[Easy &#8211; CellRemoval Easy problem. First of all, find leaf nodes from array &#8216;parent&#8217;. Leaf node is the node that no element refer it. And then traverse a tree from each leaf node to root node. During traversing, stop traverse if encounters &#8216;deletedCell&#8217;. If the leaf node can reach root node, count up return value. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=202&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><a href="http://www.topcoder.com/stat?c=problem_statement&amp;pm=10275&amp;rd=13697">Easy &#8211; CellRemoval</a></h3>
<p>Easy problem. First of all, find leaf nodes from array &#8216;parent&#8217;. Leaf node is the node that no element refer it. And then traverse a tree from each leaf node to root node. During traversing, stop traverse if encounters &#8216;deletedCell&#8217;. If the leaf node can reach root node, count up return value.</p>
<p>The size of parent array is up to 50. This is very small tree. So you need not to implement memorization or other techniques. Number of nodes is small enough for execution time.</p>
<pre class="brush: cpp;">
class CellRemoval {
public:
  int ret;
  vector &lt;int&gt; parent;
  int deletedCell;

  int r(int pos) {
    if (pos == -1) {
      ret++;
      return 0;
    } else if (pos == deletedCell) {
      return 0;
    }

    r(parent[pos]);
    return 0;
  }

  int cellsLeft(vector &lt;int&gt; _parent, int _deletedCell) {
    ret = 0;
    parent = _parent;
    deletedCell = _deletedCell;
    int leafs[parent.size()];
    memset(leafs, 0, sizeof(leafs));

    for (int i=0; i&lt;parent.size(); i++)
      if (parent[i] != -1)
        leafs[parent[i]]++;

    for (int i=0; i&lt;parent.size(); i++)
      if (leafs[i] == 0)
        r(i);

    return ret;
  }
};
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cou929.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cou929.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cou929.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cou929.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cou929.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cou929.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cou929.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cou929.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cou929.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cou929.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cou929.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cou929.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cou929.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cou929.wordpress.com/202/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=202&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cou929.wordpress.com/2010/01/25/srm-435-div1-practice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f7647a55b45c08dc47d0c520ad0264c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cou929</media:title>
		</media:content>
	</item>
		<item>
		<title>SRM 436 div1 (practice)</title>
		<link>http://cou929.wordpress.com/2010/01/24/srm-436-div1-practice/</link>
		<comments>http://cou929.wordpress.com/2010/01/24/srm-436-div1-practice/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 06:36:18 +0000</pubDate>
		<dc:creator>Kosei</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[TopCoder]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://cou929.wordpress.com/?p=200</guid>
		<description><![CDATA[Easy &#8211; BestView Just search all skyscrapers. To determine skyscraper A is visible from skyscraper B, check all skyscrapers between A and B. So complexity is, at worst case, about 50 * (1 + 2 + &#8230; + 50), is equal to about 60,000. Completely no problem to search all skyscrapers.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=200&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><a href="http://www.topcoder.com/stat?c=problem_statement&amp;pm=10341&amp;rd=13698">Easy &#8211; BestView</a></h3>
<p>Just search all skyscrapers. To determine skyscraper A is visible from skyscraper B, check all skyscrapers between A and B. So complexity is, at worst case, about 50 * (1 + 2 + &#8230; + 50), is equal to about 60,000. Completely no problem to search all skyscrapers.</p>
<pre class="brush: cpp;">
class BestView {
public:
  int numberOfBuildings(vector &lt;int&gt; heights) {
    int ret = 0;

    for (int i=0; i&lt;heights.size(); i++) {
      int counter = 0;
      for (int j=0; j&lt;heights.size(); j++) if (i != j) {
          int left = min(i, j), right = max(i, j);
          double ratio = (double)(heights[left] - heights[right]) / (double)(left - right);
          bool visible = true;
          for (int k=left+1; k&lt;right; k++)
            if (heights[k] &gt;= heights[left] + ratio * (k - left)) {
              visible = false;
              break;
            }
          if (visible) counter++;
        }
      ret = max(ret, counter);
    }

    return ret;
  }
};
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cou929.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cou929.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cou929.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cou929.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cou929.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cou929.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cou929.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cou929.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cou929.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cou929.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cou929.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cou929.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cou929.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cou929.wordpress.com/200/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=200&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cou929.wordpress.com/2010/01/24/srm-436-div1-practice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f7647a55b45c08dc47d0c520ad0264c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cou929</media:title>
		</media:content>
	</item>
		<item>
		<title>SRM 459 div1</title>
		<link>http://cou929.wordpress.com/2010/01/20/srm-459-div1/</link>
		<comments>http://cou929.wordpress.com/2010/01/20/srm-459-div1/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 19:31:14 +0000</pubDate>
		<dc:creator>Kosei</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[TopCoder]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://cou929.wordpress.com/?p=198</guid>
		<description><![CDATA[Cannot attend this srm because I&#8217;ve overslept. Took a nap before srm but woken up after it started :( So first of all I&#8217;ve solved div1 easy in practice room. Easy &#8211; Inequalities Input is an array of &#8220;X (&#60;= &#124; &#124; &#62;=) C&#8221;. And C is an integer which range is [0, 1000]. So [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=198&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Cannot attend this srm because I&#8217;ve overslept. Took a nap before srm but woken up after it started :( So first of all I&#8217;ve solved div1 easy in practice room. </p>
<h3><a href="http://www.topcoder.com/stat?c=problem_statement&amp;pm=10682&amp;rd=14145">Easy &#8211; Inequalities</a></h3>
<p>Input is an array of &#8220;X (&lt;= |  | &gt;=) C&#8221;. And C is an integer which range is [0, 1000]. So we need to check only [-0.5, 1000.5] by 0.5 interval. This is small enough for brute-force approach.</p>
<pre class="brush: cpp;">
class Inequalities {
public:
  vector &lt;string&gt; split(const string _s, const string del) {
    vector &lt;string&gt; ret;
    string s = _s;

    while (!s.empty())
      {
        size_t pos = s.find(del);
        string sub = &quot;&quot;;
        sub = s.substr(0, pos);
        ret.push_back(sub);
        if (pos != string::npos)
          pos += del.size();
        s.erase(0, pos);
      }

    return ret;
  }

  int toInt(string s) {int r = 0; istringstream ss(s); ss &gt;&gt; r; return r;}

  int maximumSubset(vector &lt;string&gt; inequalities) {
    int ret = 0;

    for (double i=-1; i&lt;=1001; i+=0.5) {
      int satisfy = 0;
      for (int j=0; j&lt;inequalities.size(); j++) {
        vector &lt;string&gt; res = split(inequalities[j], &quot; &quot;);
        double num = (double)toInt(res[2]);
        if (res[1] == &quot;=&quot;) {
          if (i != num) continue;
        } else if (res[1] == &quot;&lt;&quot;) {
          if (i &gt;= num) continue;
        } else if (res[1] == &quot;&lt;=&quot;) {
          if (i &gt; num) continue;
        } else if (res[1] == &quot;&gt;&quot;) {
          if (i &lt;= num) continue;
        } else if (res[1] == &quot;&gt;=&quot;) {
          if (i &lt; num) continue;
        }
        satisfy++;
      }
      ret = max(ret, satisfy);
    }

    return ret;
  }
};
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cou929.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cou929.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cou929.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cou929.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cou929.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cou929.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cou929.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cou929.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cou929.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cou929.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cou929.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cou929.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cou929.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cou929.wordpress.com/198/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=198&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cou929.wordpress.com/2010/01/20/srm-459-div1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f7647a55b45c08dc47d0c520ad0264c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cou929</media:title>
		</media:content>
	</item>
		<item>
		<title>Member SRM 458 div1 (practice)</title>
		<link>http://cou929.wordpress.com/2010/01/16/member-srm-458-div1-practice/</link>
		<comments>http://cou929.wordpress.com/2010/01/16/member-srm-458-div1-practice/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 13:02:35 +0000</pubDate>
		<dc:creator>Kosei</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[TopCoder]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://cou929.wordpress.com/?p=196</guid>
		<description><![CDATA[Medium &#8211; NewCoins Solved with refering top submission by UdH-WiNGeR. This is a dp approach. An array dp[i] stores &#8220;number of coins which is needed when smallest coin value is equal to i&#8221;. Suppose i is a smallest coin value and j is a multiple i, number of coin needed is dp[j] + price % [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=196&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><a href="http://www.topcoder.com/stat?c=problem_statement&amp;pm=10569&amp;rd=14180">Medium &#8211; NewCoins</a></h3>
<p>Solved with refering <a href="http://www.topcoder.com/stat?c=problem_solution&amp;cr=22221928&amp;rd=14180&amp;pm=10569">top submission</a> by UdH-WiNGeR. This is a dp approach. An array dp[i] stores &#8220;number of coins which is needed when smallest coin value is equal to i&#8221;. Suppose i is a smallest coin value and j is a multiple i, number of coin needed is dp[j] + price % j / i. Calculate in this way from 10000 to 1.</p>
<pre class="brush: cpp;">
class NewCoins {
public:
  int minCoins(vector &lt;int&gt; price) {
    int dp[100001];
    memset(dp, 0, sizeof(dp));

    for (int i=100000; i&gt;=1; i--) {
      for (int j=0; j&lt;price.size(); j++)
        dp[i] += price[j] / i;

      for (int j = i+i; j&lt;=100000; j+=i) {
        int tmp = dp[j];
        for (int k=0; k&lt;price.size(); k++)
          tmp += price[k] % j / i;
        dp[i] = min(dp[i], tmp);
      }
    }

    return dp[1];
  }
};
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cou929.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cou929.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cou929.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cou929.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cou929.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cou929.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cou929.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cou929.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cou929.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cou929.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cou929.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cou929.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cou929.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cou929.wordpress.com/196/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cou929.wordpress.com&amp;blog=8385179&amp;post=196&amp;subd=cou929&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cou929.wordpress.com/2010/01/16/member-srm-458-div1-practice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f7647a55b45c08dc47d0c520ad0264c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cou929</media:title>
		</media:content>
	</item>
	</channel>
</rss>
