<?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"
	>

<channel>
	<title>Suhendry's Blog</title>
	<atom:link href="http://www.suhendry.net/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.suhendry.net/blog</link>
	<description>When in doubt, do math ;-)</description>
	<pubDate>Thu, 15 Jul 2010 07:27:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>TopCoder SRM 475</title>
		<link>http://www.suhendry.net/blog/?p=993</link>
		<comments>http://www.suhendry.net/blog/?p=993#comments</comments>
		<pubDate>Tue, 06 Jul 2010 15:24:47 +0000</pubDate>
		<dc:creator>suhendry</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[TC]]></category>

		<guid isPermaLink="false">http://www.suhendry.net/blog/?p=993</guid>
		<description><![CDATA[There are no red coder from Indonesia who participate in this match, and there are only two yellow coders (felix_halim and handojo1). Me? I&#8217;m back to blue&#8230;

SRM 475, 300 point
RabbitStepping
The field size is at most 17, so we can solve this problem by bruteforce. We just need to try all possible initial combination and simulate [...]]]></description>
			<content:encoded><![CDATA[<p>There are no red coder from Indonesia who participate in this match, and there are only two yellow coders (felix_halim and handojo1). Me? I&#8217;m back to blue&#8230;</p>
<p><span id="more-993"></span></p>
<p><b>SRM 475, 300 point</b></p>
<p><a href='http://www.suhendry.net/blog/wp-content/uploads/2010/07/rabbitstepping.html' target="_blank">RabbitStepping</a></p>
<p>The field size is at most 17, so we can solve this problem by bruteforce. We just need to try all possible initial combination and simulate the rabbit&#8217;s movement. To generate all possible initial combination, we can iterate from 0 to 2<sup>n</sup>-1 and work on its binary representation.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> bit <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> bit <span style="color: #000080;">&lt;</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #000080;">&lt;&lt;</span> n<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> bit<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> n<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> bit <span style="color: #000040;">&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #000080;">&lt;&lt;</span> i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// there's a rabbit at cell i</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Remember, the number of rabbit is r, so we should process only bit which has r hamming weight.</p>
<p><b>Hamming weight</b><br />
Hamming weight of binary number is the digit sum of the binary representasion of a given number (the number of digit &#8216;1&#8242; in its binary representation). For example, 11 in binary is 1011<sub>2</sub>, so the hamming weight of 11 or h(11) is 3.</p>
<p>There are various method to calculate hamming weight.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> h<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> n<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">int</span> ret <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span> n <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    ret <span style="color: #000040;">+</span><span style="color: #000080;">=</span> n <span style="color: #000040;">%</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>
    n  <span style="color: #000040;">/</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0000ff;">return</span> ret<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>or using bitwise operator&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> h<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> n<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">int</span> ret <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span> n <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    ret <span style="color: #000040;">+</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>n <span style="color: #000040;">&amp;</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    n  <span style="color: #000080;">&gt;&gt;=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0000ff;">return</span> ret<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The simplest one that I know is this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> h<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> n<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> n <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">1</span> <span style="color: #000040;">+</span> h<span style="color: #008000;">&#40;</span>n<span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span>n<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The last one comes from an observation that n-1 will make the most right &#8216;1&#8242; turn into &#8216;0&#8242; and any digit that lies right to it become &#8216;1&#8242;. For example, 616 is 100110<b>1000</b><sub>2</sub> and 615 is 100110<b>0111</b><sub>2</sub>. So n &#038; (n-1) will erase one &#8216;1&#8242; from n, ie. the right most one.</p>
<p>C/C++ also has this hamming weight (or population-count/popcount) implementation:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> x <span style="color: #000080;">=</span> __builtin_popcount<span style="color: #008000;">&#40;</span>n<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>I took only about 10-15 minutes to code this problem, but *damn* I spent more than 30 minutes to find bugs in my code T_T. By the time I submitted the solution, it was 15 minutes left before the contest end.</p>
<p>I didn&#8217;t manage to think any solution for 600pt, so I ended with 117.29 point till the end of the contest. Yeah, my rating goes down again (-11).</p>
<p>Here is my 300 code, the time complexity is O(2<sup>n</sup> * n * r):</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#define REP(i,n) for(int i=0,_n=(n);i&lt;_n;++i)</span>
<span style="color: #0000ff;">struct</span> RabbitStepping <span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">double</span> getExpected<span style="color: #008000;">&#40;</span>string field, <span style="color: #0000ff;">int</span> r<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> h<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> n<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> n <span style="color: #008080;">?</span> <span style="color: #0000dd;">1</span><span style="color: #000040;">+</span>h<span style="color: #008000;">&#40;</span>n<span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span>n<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">:</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">double</span> RabbitStepping<span style="color: #008080;">::</span><span style="color: #007788;">getExpected</span><span style="color: #008000;">&#40;</span>string field, <span style="color: #0000ff;">int</span> r<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">double</span> ret <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">int</span> n <span style="color: #000080;">=</span> field.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, cnt <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
  REP<span style="color: #008000;">&#40;</span>bit,<span style="color: #0000dd;">1</span><span style="color: #000080;">&lt;&lt;</span>n<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> h<span style="color: #008000;">&#40;</span>bit<span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> r <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    cnt<span style="color: #000040;">++</span><span style="color: #008080;">;</span>
    vector <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> move<span style="color: #008000;">&#40;</span>r<span style="color: #008000;">&#41;</span>, prev<span style="color: #008000;">&#40;</span>r<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    vector <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> pos<span style="color: #008080;">;</span>
    REP<span style="color: #008000;">&#40;</span>i,n<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> bit <span style="color: #000040;">&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #000080;">&lt;&lt;</span> i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> pos.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> s <span style="color: #000080;">=</span> n<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span> s <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">2</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
      REP<span style="color: #008000;">&#40;</span>i,pos.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> s <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> s <span style="color: #000040;">-</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> s <span style="color: #000040;">-</span> <span style="color: #0000dd;">2</span> <span style="color: #008000;">&#41;</span> move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> s <span style="color: #000040;">-</span> <span style="color: #0000dd;">3</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> field<span style="color: #008000;">&#91;</span>pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">'W'</span> <span style="color: #008000;">&#41;</span> move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> field<span style="color: #008000;">&#91;</span>pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">'B'</span> <span style="color: #008000;">&#41;</span> move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> field<span style="color: #008000;">&#91;</span>pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">'R'</span> <span style="color: #000040;">&amp;&amp;</span> s <span style="color: #000080;">==</span> n <span style="color: #008000;">&#41;</span> move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> field<span style="color: #008000;">&#91;</span>pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">'R'</span> <span style="color: #000040;">&amp;&amp;</span> s <span style="color: #000040;">!</span><span style="color: #000080;">=</span> n <span style="color: #008000;">&#41;</span> move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> prev<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
      <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
      prev <span style="color: #000080;">=</span> pos<span style="color: #008080;">;</span>
      <span style="color: #0000ff;">int</span> rabbit<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">20</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
      REP<span style="color: #008000;">&#40;</span>i,move.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> rabbit<span style="color: #008000;">&#91;</span>move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#93;</span><span style="color: #000040;">++</span><span style="color: #008080;">;</span>
      REP<span style="color: #008000;">&#40;</span>i,move.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> rabbit<span style="color: #008000;">&#91;</span>move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">else</span> pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> move<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
      <span style="color: #008000;">&#125;</span>
      s<span style="color: #000040;">--</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    REP<span style="color: #008000;">&#40;</span>i,pos.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> pos<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> ret <span style="color: #000040;">++</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> ret <span style="color: #000040;">/</span> cnt<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>fushar and agus.mw increases their rating and back to yellow, congratz to them <img src='http://www.suhendry.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.suhendry.net/blog/?feed=rss2&amp;p=993</wfw:commentRss>
		</item>
		<item>
		<title>ACM-ICPC 2009 Jakarta - Problem Set &#038; Analysis</title>
		<link>http://www.suhendry.net/blog/?p=957</link>
		<comments>http://www.suhendry.net/blog/?p=957#comments</comments>
		<pubDate>Fri, 02 Jul 2010 09:54:26 +0000</pubDate>
		<dc:creator>suhendry</dc:creator>
		
		<category><![CDATA[Algorithm]]></category>

		<category><![CDATA[Event]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.suhendry.net/blog/?p=957</guid>
		<description><![CDATA[Tadaaa!! 
I decided to write this write up because of Felix Halim. He has set his IM status to &#8220;SUSU BLOG!!&#8221; for almost one year (man.. he&#8217;s so persistent), and I got annoyed everytime I online and saw my IM list. Not to mention Ilham who sometimes buzz me just to remind me about this [...]]]></description>
			<content:encoded><![CDATA[<p>Tadaaa!! </p>
<p>I decided to write this write up because of Felix Halim. He has set his IM status to &#8220;SUSU BLOG!!&#8221; for almost one year (man.. he&#8217;s so persistent), and I got annoyed everytime I online and saw my IM list. Not to mention Ilham who sometimes buzz me just to remind me about this write up >.<</p>
<p><a href="http://www.suhendry.net/blog/wp-content/uploads/2010/07/fh.jpg"><img src="http://www.suhendry.net/blog/wp-content/uploads/2010/07/fh-150x150.jpg" alt="" title="FH" width="150" height="150" class="alignnone size-thumbnail wp-image-987" /></a><br />
<i>click image to enlarge</i></p>
<p>I haven&#8217;t writen this write up before because I&#8217;m not quite &#8220;familiar&#8221; with the problem. By &#8220;familiar&#8221; I mean not all problem have been verified and solved by me <small>(I fallen ill and have not fully recovered when ICPC)</small>.</p>
<p>You can found The ICPC 2009 Jakarta Site link <a href="http://competition.binus.ac.id/icpc2009/" target="_blank">here</a>, and I hope it will not be deleted. The top three teams are:<br />
1. <b>UESTC_floyd</b> from University of Electronic Science and Technology of China.<br />
2. <b>dota</b> from National Taiwan University.<br />
3. <b>Dongskar Pedongi</b> from Institut Teknologi Bandung.</p>
<p>The best team from BINUS (<b>Aeon</b>) got 9<sup>th</sup> rank, too bad.. hopefully we can perform better this year.</p>
<p>There are some problems that I don&#8217;t fully understand the solution yet. I will add any necessaray review later.</p>
<p>You can download the complete problemset here:<br />
<a href="http://www.suhendry.net/contest/icpc09jak/icpc09jak-probs-publish.pdf" target="_blank">ACM-ICPC 2009 Jakarta - Problem Set</a> (537 KB)</p>
<ul>
<li><a href="?p=957&#038;page=2">Problem A - Mystic Craft</a></li>
<li><a href="?p=957&#038;page=3">Problem B - Top-10</a></li>
<li><a href="?p=957&#038;page=4">Problem C - Random Simple Polygon</a></li>
<li><a href="?p=957&#038;page=5">Problem D - Alien</a></li>
<li><a href="?p=957&#038;page=6">Problem E - A + B</a></li>
<li><a href="?p=957&#038;page=7">Problem F - 1:1000000000000&#8230;</a></li>
<li><a href="?p=957&#038;page=8">Problem G - The Puzzle Board from God</a></li>
<li><a href="?p=957&#038;page=9">Problem H - Hero&#8217;s Adventure</a></li>
<li><a href="?p=957&#038;page=10">Problem I - Spam Detection</a></li>
<li><a href="?p=957&#038;page=11">Problem J - Favorite Time</a></li>
</ul>
<p>Thanks to all authors: Ryan Leonel Somali, Felix Halim, Ilham Winata Kurnia, Timotius Sakti, Andoko Chandra, Gunawan Lie, Surya Sujarwo and Ardian Kristanto Purnomo who have helped me prepare all the problemset, solution and testdata.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suhendry.net/blog/?feed=rss2&amp;p=957</wfw:commentRss>
		</item>
		<item>
		<title>How I Knew About ACM-ICPC</title>
		<link>http://www.suhendry.net/blog/?p=913</link>
		<comments>http://www.suhendry.net/blog/?p=913#comments</comments>
		<pubDate>Mon, 12 Apr 2010 11:00:31 +0000</pubDate>
		<dc:creator>suhendry</dc:creator>
		
		<category><![CDATA[Random Post]]></category>

		<category><![CDATA[Words]]></category>

		<guid isPermaLink="false">http://www.suhendry.net/blog/?p=913</guid>
		<description><![CDATA[I was first introduced to ACM-ICPC by Mr. Ali, my lecturer in data structure course. He didn&#8217;t give any lecture about ACM-ICPC, but he gave me UVA Online Judge website address. I find the site very interesting, though I could hardly solve any problem. At that time, I could only solve about 10 (very easy) [...]]]></description>
			<content:encoded><![CDATA[<p>I was first introduced to ACM-ICPC by Mr. Ali, my lecturer in data structure course. He didn&#8217;t give any lecture about ACM-ICPC, but he gave me UVA Online Judge website address. I find the site very interesting, though I could hardly solve any problem. At that time, I could only solve about 10 (very easy) problems in a month.<span id="more-913"></span> In the same year, I participated in BNPC-CS 2003 (Bina Nusantara Programming Contest for College Student). I managed to pass the qualification round (multiple choice problems) but failed at semifinal round (programming). I found that the problems in this contest were taken from UVA Online Judge. This really encouraged me to solve more problems in UVA so I could get a better rank next year! By 2004, I had solved around 100 problems. Unfortunately, however, the problems in BNPC-CS 2004 were not taken from UVA Online Judge. Despite this, I managed to solve one problem in semifinal round! There were 41 people selected for the final round, and I was the 42<sup>nd</sup> :-(. In 2005, once again I participated in BNPC-CS, but this time I have no goal because it was my last year in university. Surprisingly, I ranked 10<sup>th</sup> in the contest!! I got a bronze medal and was invited to ACM-ICPC training.</p>
<p>At that time, ACM-ICPC training was only intended for BNPC-CS winners. Our coach was Peter Wijaya, an ex-contestant. Actually, he never taught us anything, he chose some problems from UVA and let us solve them by ourselves. This training was the first time when I learned about algorithm, and I find it very interesting. I never knew how to code BFS before or what dynamic programming is. At that time, I coded a lot! I used <a href="http://felix-halim.net/uva/hunting.php?id=244" target="_blank">Felix Halim&#8217;s tools</a> to find easy problems on UVA. He had also created a ranklist page for Indonesian coder in UVA, which made me more enthusiastic to solve more and more problems, so I can get a better rank than others. Around October 2005, I was selected to participate in ACM-ICPC Manila site, together with Ang Ing Ing and Evan Leonardi. At that time, I had solved more than 300 problems in UVA.</p>
<p>Manila 2005 was my first experience in ACM-ICPC. My team only managed to get 14<sup>th</sup> rank, worse than Felix&#8217;s team, 10<sup>th</sup> rank. As I recall, the problems was not too hard, and I think I can solve all of them by now (though some problems have unclear statements).</p>
<p>In 2006, Yen Lina asked me to become a new coach, and I agreed. I never had a proper training before, so I just follow Peter Wijaya&#8217;s style of coaching: select some problems and solve them. But this time, I also tried to solve the problems I&#8217;ve selected and helped those who can&#8217;t solve them. I used to say: &#8220;Any problem that I can solve, you have to be able to solve it. Any problem that I can&#8217;t solve, you might better try to solve it&#8221; :)). Though I were a coach, I think I learn a lot at that time. I began to read Introduction to Algorithm and many other books, and I also joined <a href="http://topcoder.com/tc" target="_blank">TopCoder</a>. I learned about network flow algorithm, number theories, and many graph theories. I used to spend my weekend to code or compete in online contests.</p>
<p>After I had solved a lot of problems, I began to refine my coding skills. I used to code just to get an accepted answer, but later I began to analyze my code, proof, and rewrite an eficient code. My experience in TopCoder has also helped me improve my speed and accuracy a lot (&#8221;one hit AC&#8221;).</p>
<p>Well, that&#8217;s a bit about my problem solving background.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suhendry.net/blog/?feed=rss2&amp;p=913</wfw:commentRss>
		</item>
		<item>
		<title>Matrix Multiplication</title>
		<link>http://www.suhendry.net/blog/?p=902</link>
		<comments>http://www.suhendry.net/blog/?p=902#comments</comments>
		<pubDate>Sun, 10 Jan 2010 13:53:38 +0000</pubDate>
		<dc:creator>suhendry</dc:creator>
		
		<category><![CDATA[Algorithm]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.suhendry.net/blog/?p=902</guid>
		<description><![CDATA[Matrix multiplication could be useful to solve some problems. For example, what is the last digit of 1,000,000,000th fibonacci? Calculating fibonacci number using dynamic programming will need O(n) time complexity, we need a faster one to solve this problem.
Let A be a 1 x 2 matrix which consist of f0 and f1 (ie. 0 and [...]]]></description>
			<content:encoded><![CDATA[<p>Matrix multiplication could be useful to solve some problems. For example, what is the last digit of 1,000,000,000<sup>th</sup> fibonacci? Calculating fibonacci number using dynamic programming will need O(n) time complexity, we need a faster one to solve this problem.</p>
<p><span id="more-902"></span>Let A be a 1 x 2 matrix which consist of f<sub>0</sub> and f<sub>1</sub> (ie. 0 and 1) and B be a 2 x 2 matrix which consist of {(0,1),(1,1)}. If we multiply A and B, we will get a 1 x 2 matrix C which consist of f<sub>1</sub> and f<sub>0</sub>+f<sub>1</sub> (= f<sub>2</sub>). If we multiply C with B, then we will get a matrix D which consist of f<sub>2</sub> and f<sub>1</sub>+f<sub>2</sub> (= f<sub>3</sub>). By doing this, we can obtain f<sub>n</sub> by multiplying A with B for n-1 times.</p>
<p><img src="http://www.suhendry.net/blog/wp-content/uploads/2010/01/fib.gif" alt="fibonacci" title="fibonacci" width="363" height="221" class="size-full wp-image-903" /></p>
<p>Matrix multiplication is associative, so we can compute f<sub>n</sub> by multiplying A with B to the power of n-1. We know that a<sup>n</sup> can be computed in O(lg n) and multiplying two matrixes needs O(s<sup>3</sup>) where s is the size of the matrix, hence the total time complexity would be O(s<sup>3</sup> . lg n).</p>
<p>Here is an example code of computing the last digit of n<sup>th</sup> fibonacci number.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">typedef</span> vector<span style="color: #000080;">&lt;</span>vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> <span style="color: #000080;">&gt;</span> vvi<span style="color: #008080;">;</span>
<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> mod <span style="color: #000080;">=</span> <span style="color: #0000dd;">10</span><span style="color: #008080;">;</span>
&nbsp;
vvi mul<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> vvi <span style="color: #000040;">&amp;</span>a, <span style="color: #0000ff;">const</span> vvi <span style="color: #000040;">&amp;</span>b<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  vvi ret<span style="color: #008000;">&#40;</span>a.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,b<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span>.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  REP<span style="color: #008000;">&#40;</span>i,a.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> REP<span style="color: #008000;">&#40;</span>j,b<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
    REP<span style="color: #008000;">&#40;</span>k,a<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> ret<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>ret<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> a<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>k<span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> b<span style="color: #008000;">&#91;</span>k<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">%</span> mod<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">return</span> ret<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
vvi power<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> vvi <span style="color: #000040;">&amp;</span>a, <span style="color: #0000ff;">int</span> p<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> p <span style="color: #000080;">==</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> a<span style="color: #008080;">;</span>
  vvi x <span style="color: #000080;">=</span> power<span style="color: #008000;">&#40;</span>a,p<span style="color: #000040;">/</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> p <span style="color: #000040;">%</span> <span style="color: #0000dd;">2</span> <span style="color: #000080;">==</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> mul<span style="color: #008000;">&#40;</span>a,mul<span style="color: #008000;">&#40;</span>x,x<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">return</span> mul<span style="color: #008000;">&#40;</span>x,x<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  vvi a<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span>,<span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span>, b<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">2</span>,<span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  a<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span>, a<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
  b<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span>, b<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> b<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> b<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">int</span> n<span style="color: #008080;">;</span>
  <span style="color: #0000dd;">scanf</span><span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">&quot;%d&quot;</span>, <span style="color: #000040;">&amp;</span>n <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">&quot;%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, n <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span> <span style="color: #008080;">?</span> <span style="color: #0000dd;">0</span> <span style="color: #008080;">:</span> mul<span style="color: #008000;">&#40;</span>a,power<span style="color: #008000;">&#40;</span>b,n<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Now let&#8217;s consider another problem. Given a graph G of k node, how many distinct path of length n are there that starts from node 1? This problem could also be solved by matrix multiplication.</p>
<p>Let A be a 1 x k matrix which consist of the number of path that end in each node, for the initial case of course it will be (1, 0, &#8230;, 0). Let B the adjacency matrix of graph G. If we multiply A with B, we will get a matrix C which consist of the number of path of length-1 that end in each node. If we multiply C with B again, we will get a matrix D which consist of the number of path of length-2 that end in each node, and so on.</p>
<p><img src="http://www.suhendry.net/blog/wp-content/uploads/2010/01/mat.gif" alt="matrix" title="mat" width="500" height="245" class="size-full wp-image-904" /></p>
<p>There are 3 + 1 + 1 + 2 = 7 paths of length 2 in the graph above:<br />
A - B - A<br />
A - C - A<br />
A - D - A<br />
A - D - B<br />
A - D - C<br />
A - B - D<br />
A - C - D</p>
<p>Exercises:<br />
<a href="http://acm.tju.edu.cn/toj/showp2169.html" target="_blank" />TJU 2169 - Number Sequence</a><br />
<a href="http://acm.tju.edu.cn/toj/showp2871.html" target="_blank" />TJU 2871 - Magic Bean</a><br />
<a href="http://uva.onlinejudge.org/external/111/11149.html" target="_blank" />UVA 11149 - The Power of Matrix</a><br />
<a href="http://www.spoj.pl/problems/SEQ/" target="_blank" />SPOJ SEQ - Recursive Sequence</a><br />
<a href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4332" target="_blank" />Live Archieve 4332 - Blocks for kids</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.suhendry.net/blog/?feed=rss2&amp;p=902</wfw:commentRss>
		</item>
		<item>
		<title>ICPC Indonesia National Contest 2009</title>
		<link>http://www.suhendry.net/blog/?p=895</link>
		<comments>http://www.suhendry.net/blog/?p=895#comments</comments>
		<pubDate>Sat, 19 Dec 2009 19:14:49 +0000</pubDate>
		<dc:creator>suhendry</dc:creator>
		
		<category><![CDATA[Algorithm]]></category>

		<category><![CDATA[Event]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.suhendry.net/blog/?p=895</guid>
		<description><![CDATA[Yay! Akhirnya selesai juga write-up INC 2009, habis ini ICPC 2009! >:)
Testdata bisa didownload di sini:
INC 2009 - Testcase (ZIP - 992KB)
Pembahasan solusi bisa dilihat di sini:

Problem A - General Election
Problem B - Liar Game
Problem C - Why is Math Book So Sad?
Problem D - Noodle Team Contest
Problem E - Palapa Number
Problem F - New [...]]]></description>
			<content:encoded><![CDATA[<p>Yay! Akhirnya selesai juga write-up INC 2009, habis ini ICPC 2009! >:)</p>
<p>Testdata bisa didownload di sini:<br />
<a href="http://www.suhendry.net/contest/inc09/inc09-testcase.zip"/>INC 2009 - Testcase</a> (ZIP - 992KB)</p>
<p>Pembahasan solusi bisa dilihat di sini:</p>
<ul>
<li><a href="http://www.suhendry.net/blog/?p=895&#038;page=2">Problem A - General Election</a></li>
<li><a href="http://www.suhendry.net/blog/?p=895&#038;page=3">Problem B - Liar Game</a></li>
<li><a href="http://www.suhendry.net/blog/?p=895&#038;page=4">Problem C - Why is Math Book So Sad?</a></li>
<li><a href="http://www.suhendry.net/blog/?p=895&#038;page=5">Problem D - Noodle Team Contest</a></li>
<li><a href="http://www.suhendry.net/blog/?p=895&#038;page=6">Problem E - Palapa Number</a></li>
<li><a href="http://www.suhendry.net/blog/?p=895&#038;page=7">Problem F - New House</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.suhendry.net/blog/?feed=rss2&amp;p=895</wfw:commentRss>
		</item>
		<item>
		<title>BNPCHS 2009 - Final Round</title>
		<link>http://www.suhendry.net/blog/?p=876</link>
		<comments>http://www.suhendry.net/blog/?p=876#comments</comments>
		<pubDate>Mon, 07 Dec 2009 14:52:16 +0000</pubDate>
		<dc:creator>suhendry</dc:creator>
		
		<category><![CDATA[Algorithm]]></category>

		<category><![CDATA[Event]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.suhendry.net/blog/?p=876</guid>
		<description><![CDATA[Problemset bisa didownload di sini:
BNPCHS 2009 Final Round - Problemset (PDF - 496KB)
Testdata bisa didownload di sini:
BNPCHS 2009 Final Round - Testcase (ZIP - 3091KB)
Pembahasan solusi bisa dilihat di sini:

Problem A - Teks Fibonacci
Problem B - BeSaR DaN KeCiL
Problem C - Rentang Terbesar
Problem D - Merakit Komputer
Problem E - Mario Bros
Problem F - Kaca Patri
Problem [...]]]></description>
			<content:encoded><![CDATA[<p>Problemset bisa didownload di sini:<br />
<a href="http://www.suhendry.net/contest/bnpchs09/final/hs09-probs-publish.pdf"/>BNPCHS 2009 Final Round - Problemset</a> (PDF - 496KB)</p>
<p>Testdata bisa didownload di sini:<br />
<a href="http://www.suhendry.net/contest/bnpchs09/final/hs09-testcase.zip"/>BNPCHS 2009 Final Round - Testcase</a> (ZIP - 3091KB)</p>
<p>Pembahasan solusi bisa dilihat di sini:</p>
<ul>
<li><a href="http://www.suhendry.net/blog/?p=876&#038;page=2">Problem A - Teks Fibonacci</a></li>
<li><a href="http://www.suhendry.net/blog/?p=876&#038;page=3">Problem B - BeSaR DaN KeCiL</a></li>
<li><a href="http://www.suhendry.net/blog/?p=876&#038;page=4">Problem C - Rentang Terbesar</a></li>
<li><a href="http://www.suhendry.net/blog/?p=876&#038;page=5">Problem D - Merakit Komputer</a></li>
<li><a href="http://www.suhendry.net/blog/?p=876&#038;page=6">Problem E - Mario Bros</a></li>
<li><a href="http://www.suhendry.net/blog/?p=876&#038;page=7">Problem F - Kaca Patri</a></li>
<li><a href="http://www.suhendry.net/blog/?p=876&#038;page=8">Problem G - Jumlah Pembagi</a></li>
<li><a href="http://www.suhendry.net/blog/?p=876&#038;page=9">Problem H - Drum Minyak Pak Ricat</a></li>
<li><a href="http://www.suhendry.net/blog/?p=876&#038;page=10">Problem I - Jumlah Pangkat</a></li>
<li><a href="http://www.suhendry.net/blog/?p=876&#038;page=11">Problem J - Ordo Keprimaan</a></li>
<li><a href="http://www.suhendry.net/blog/?p=876&#038;page=12">Medalist</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.suhendry.net/blog/?feed=rss2&amp;p=876</wfw:commentRss>
		</item>
		<item>
		<title>BNPCHS 2009 - Qualification Round</title>
		<link>http://www.suhendry.net/blog/?p=857</link>
		<comments>http://www.suhendry.net/blog/?p=857#comments</comments>
		<pubDate>Mon, 23 Nov 2009 10:13:58 +0000</pubDate>
		<dc:creator>suhendry</dc:creator>
		
		<category><![CDATA[Algorithm]]></category>

		<category><![CDATA[Event]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.suhendry.net/blog/?p=857</guid>
		<description><![CDATA[Wah, bisa digebuk Felix Halim nih kalau gw ketauan publish pembahasan BNPCHS 2009 Qualification Round sebelum review INC 2009 ama ICPC 2009 Jakarta Site *kabur*.
Well anyway, Babak Penyisihan BNPCHS 2009 baru saja berlalu. Penyisihan kali ini jatuh pada hari Sabtu, 21 November 2009. Mengapa hari Sabtu? Biasanya lomba-lomba di BINUS selalu hari Minggu, tapi tanggal [...]]]></description>
			<content:encoded><![CDATA[<p>Wah, bisa digebuk Felix Halim nih kalau gw ketauan publish pembahasan BNPCHS 2009 Qualification Round sebelum review INC 2009 ama ICPC 2009 Jakarta Site *kabur*.</p>
<p>Well anyway, Babak Penyisihan BNPCHS 2009 baru saja berlalu. Penyisihan kali ini jatuh pada hari Sabtu, 21 November 2009. Mengapa hari Sabtu? Biasanya lomba-lomba di BINUS selalu hari Minggu, tapi tanggal 22 November 2009 ada Ujian Saringan Masuk BINUS, makanya lombanya digeser ke hari Sabtu.</p>
<p>Babak Penyisihan terdiri dari dua tahap: Multiple Choice dan Programming. Babak Multiple Choice terdiri dari 50 soal dengan masing-masing soal bernilai 3 point, sedangkan babak Programming terdiri dari 3 soal dengan masing-masing soal bernilai minimal 70 point.</p>
<p>Mengenai babak multiple choice, soalnya ntar diupload belakangan, belum dirapiin.</p>
<ul>
<li><a href="http://www.suhendry.net/blog/?p=857&#038;page=2">Problem A - Bujur Sangkar Ajaib</a></li>
<li><a href="http://www.suhendry.net/blog/?p=857&#038;page=3">Problem B - Menghitung Palindrom</a></li>
<li><a href="http://www.suhendry.net/blog/?p=857&#038;page=4">Problem C - String Prima</a></li>
</ul>
<p>Daftar finalis dapat dilihat di <a href="http://www.suhendry.net/blog/?p=857&#038;page=5">sini</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suhendry.net/blog/?feed=rss2&amp;p=857</wfw:commentRss>
		</item>
		<item>
		<title>Training Session 2009 (for beginner)</title>
		<link>http://www.suhendry.net/blog/?p=802</link>
		<comments>http://www.suhendry.net/blog/?p=802#comments</comments>
		<pubDate>Fri, 27 Mar 2009 12:58:41 +0000</pubDate>
		<dc:creator>suhendry</dc:creator>
		
		<category><![CDATA[Information]]></category>

		<guid isPermaLink="false">http://www.suhendry.net/blog/?p=802</guid>
		<description><![CDATA[Good news from compscidept! Here is the invitation for ACM-ICPC Training Session for new students in BINUS (new to programming contest and ACM-ICPC, not necessarily a new/first year student). If you&#8217;re interested, send me an email including:



1. Student ID (NIM)
2. Full name
3. Email address
4. Major (jurusan)
5. Regular course schedule (jadwal kuliah)
6. Last GPA
7. Grade for [...]]]></description>
			<content:encoded><![CDATA[<p>Good news from <a href="http://compscidept.blog.binusian.org/2009/03/19/binusian-programming-team/" target="_blank">compscidept</a>! Here is the invitation for <strong>ACM-ICPC Training Session</strong> for new students in BINUS (new to programming contest and ACM-ICPC, not necessarily a new/first year student). If you&#8217;re interested, send me an email including:</p>
<table width="60%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="65%" valign="top">
1. Student ID (NIM)<br />
2. Full name<br />
3. Email address<br />
4. Major (jurusan)<br />
5. Regular course schedule (jadwal kuliah)<br />
6. Last GPA<br />
7. Grade for these subjects (if there&#8217;s any):<br />
&nbsp;&nbsp;&nbsp;&nbsp;[ - ] Algoritma dan Pemrograman<br />
&nbsp;&nbsp;&nbsp;&nbsp;[ - ] Struktur Data<br />
&nbsp;&nbsp;&nbsp;&nbsp;[ - ] Perancangan dan Analisis Algoritma</td>
<td align="center" valign="middle" nowrap><a href="http://www.suhendry.net/blog/wp-content/uploads/2009/03/training_0904.jpg" target="_blank"><img src="http://www.suhendry.net/blog/wp-content/uploads/2009/03/training_0904-150x150.jpg" alt="" title="Training April 2009" width="150" height="150" class="alignnone size-thumbnail wp-image-806" /></a><small><br/><i>click the image if you can&#8217;t read it</i><br/><br />
</small></td>
</tr>
</table>
<p>As usual, there won&#8217;t be any entrance test but you should already know how to code because we&#8217;re not going to teach you how to write a loop or to create an array in C/C++. BTW, I am in charge with the registration but not with the training. You will be trained by Ricky Winata, 3rd place winner from local team of ACM-ICPC Jakarta 2008. He is smart.</p>
<p><span id="more-802"></span><br />
Registration will end at 4 April 2009 and the training will start at 20 April 2009. I&#8217;m a little bit curious&#8230; 20 April is the first week of Midterm Exam, are they sure about this? In case the training is postponed, then the end of registration date will be too early.</p>
<p>I know that there isn&#8217;t much information you can get from that nice poster. Knew it from last year and it happened again this time.</p>
<p><strong>Schedule</strong><br />
The training will be conducted once a week with two shifts per week, 2 x 100 minutes. The schedule will be arranged based on the participants&#8217; schedule (that&#8217;s why you should submit yours). Consider it like another (but interesting, challenging and fun) course or club activity. Some students asked me about this last year and they thought the training would be similar to software laboratory assistant&#8217;s training where you would be trained 12 hours a day in three or four weeks. No, it was far from their imagination :-).</p>
<p><strong>Training Method</strong><br />
The purpose of this training session is to introduce problem solving for programming contest. CompSci&#8217;s students may find it similar to &#8220;kuis-online&#8221;, of course with different kind of problemset (in fact, kuis-online was built based on programming contest style). We give you some problems, you work on those problems, and then we discuss them. We will refresh topics if you need them (for example, when you forget what is sorting or binary search). Here we will not let you know the solution for each problem before you work on it. You should think which approach you can use to solve the problem (can you solve it directly, or would sorting the data helps you, or is there any smarter way to solve the problem, etc). And then we will discuss the effectivity and efficiency of your approach. It&#8217;s quite different from what you can find in your normal algorithm/programming class in BINUS <font color="white">where you usually learn a subject by memorization so you can get a good score in exam, and never learn why you should learn it</font>.</p>
<p>It&#8217;s fun and challenging :-).</p>
<p>EDIT: rephrased by flanflygirl.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suhendry.net/blog/?feed=rss2&amp;p=802</wfw:commentRss>
		</item>
		<item>
		<title>ABS and MAX</title>
		<link>http://www.suhendry.net/blog/?p=778</link>
		<comments>http://www.suhendry.net/blog/?p=778#comments</comments>
		<pubDate>Wed, 11 Mar 2009 23:28:22 +0000</pubDate>
		<dc:creator>suhendry</dc:creator>
		
		<category><![CDATA[Algorithm]]></category>

		<guid isPermaLink="false">http://www.suhendry.net/blog/?p=778</guid>
		<description><![CDATA[Good morning! It&#8217;s 5:32 and I haven&#8217;t slept yet, not because that I can&#8217;t sleep, but there is an interesting problem that I like to work on (though it&#8217;s not important at all!).
1. Write ABS function which takes an integer N as input and return the absolute value of N. Your function should be one-liner [...]]]></description>
			<content:encoded><![CDATA[<p>Good morning! It&#8217;s 5:32 and I haven&#8217;t slept yet, not because that I can&#8217;t sleep, but there is an interesting problem that I like to work on (though it&#8217;s not important at all!).</p>
<p>1. Write ABS function which takes an integer N as input and return the absolute value of N. Your function should be one-liner (one statement) and may contain only +, -, *, /, (, ), numbers, and variable (ie. N). You&#8217;re not allowed to call any other functions (including built-in functions).</p>
<p>2. Write MAX function which takes two integers A and B as input and return the largest value between A and B. Your function should also be one-liner and may contain only +, -, *, /, (, ), numbers, and variables (ie. A and B). You&#8217;re allowed only to call one function: ABS.</p>
<p><span id="more-778"></span>It took me a while to figure out how to write such ABS function. I googled several sites and found only ABS function that exploit negative numbers&#8217; representation in computer, which means it needs bitwise operator such as << and >> (breaking the rule!), and there&#8217;s also compiler problem (16-bit or 32-bit).</p>
<p>Here is my solution for ABS:</p>
<pre>int abs(int n) { return n * ((2 * ((n*n+n)/(n*n+1))) - 1); }</pre>
<p><br/>The key idea is to multiply n by 1 if n > 0, and multiply n by -1 if n &#8804; 0. Then the problem is, how to map any n > 0 into 1 while any n by -1 if n &#8804; 0 will be mapped into -1 by the same operation?</p>
<p>n<sup>2</sup> + n :: always give a non-negative result for any integer n.<br />
n<sup>2</sup> + 1 :: always give a positive result for any integer n (it&#8217;s important to have a non-zero function as denominator).<br />
(n<sup>2</sup> + n) / (n<sup>2</sup> + 1) :: always give 1 if n > 0, because (p<sup>2</sup> + p) &#8805; (p<sup>2</sup> + 1) and (p<sup>2</sup> + p) < 2 * (p<sup>2</sup> + 1) for any positive integer p (n = p).<br />
(n<sup>2</sup> + n) / (n<sup>2</sup> + 1) :: always give 0 if n &#8804; 0, because (p<sup>2</sup> - p) < (p<sup>2</sup> + 1) and 0 &#8804; (p<sup>2</sup> - p) for any non-negative integer p (n = -p).</p>
<p>From (n<sup>2</sup> + n) / (n<sup>2</sup> + 1), we will receive either 1 (if n > 0) or 0 if (if n &#8804; 0). Mapping {1, 0} into {1, -1} is an easy task :-D.</p>
<p>For the second question (MAX), there is a simple solution which use ABS function:</p>
<pre>int max(int a, int b) { return (a + b + abs(a - b)) / 2; }</pre>
<p><br/>I&#8217;d like to know if there is any easier way to do ABS or MAX, but I can&#8217;t think straight right now&#8230; okay, good night!!</p>
<p>EDIT: grammar (flanflygirl)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suhendry.net/blog/?feed=rss2&amp;p=778</wfw:commentRss>
		</item>
		<item>
		<title>First Training Day</title>
		<link>http://www.suhendry.net/blog/?p=757</link>
		<comments>http://www.suhendry.net/blog/?p=757#comments</comments>
		<pubDate>Tue, 03 Mar 2009 19:07:06 +0000</pubDate>
		<dc:creator>suhendry</dc:creator>
		
		<category><![CDATA[Algorithm]]></category>

		<category><![CDATA[Random Post]]></category>

		<guid isPermaLink="false">http://www.suhendry.net/blog/?p=757</guid>
		<description><![CDATA[Feb 28 was the first day of our new training session, but the number of attendance was quite astonishing: one (marcadian). It was expected though considering the announcement was made only the day before. I can&#8217;t help but feel pathetic, why should I spend my beautiful weekend with a guy? Yet, I was lucky he&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Feb 28 was the first day of our new training session, but the number of attendance was quite astonishing: one (marcadian). It was expected though considering the announcement was made only the day before. I can&#8217;t help but feel pathetic, why should I spend my beautiful weekend with a guy? Yet, I was lucky he&#8217;s not a gay&#8230; or not yet (someone please tell me)? There was another student came in the middle of the training hour (jeff), be he went home soon&#8230;</p>
<p>Warm-up problems:<br />
PKU 2236 - Wireless Network<br />
PKU 2761 - Feed the dogs<br />
PKU 3419 - Difference Is Beautiful<br />
PKU 3421 - X-factor Chains</p>
<p>Spoiler Ahead!<br />
<span id="more-757"></span><br />
<strong>PKU 2236 - Wireless Network</strong><br />
This is an easy problem (compared to the others). Each time a computer is being repaired, merge this computer with any other computers within range that has been repaired. Repairing a computer twice won&#8217;t effect anything, so it will be usefull to remember which computer that has been repaired.</p>
<p><strong>PKU 2761 - Feed the dogs</strong><br />
You can find the k-th element in a range with a proper tree data structure, but marcadian said that he got TLE with this approach. There is a simpler solution using a certain tree stucture to find k-th element in the whole range (timo used to call it &#8220;misof-tree&#8221;). Notice that there will be no interval that contain another interval completely, we can use this special constraint. Solve the queries based on start-interval in ascending order. By doing so, we can &#8220;maintain&#8221; our tree structure by window-sliding.</p>
<p><strong>PKU 3419 - Difference Is Beautiful</strong><br />
Yes indeed, difference is beautiful, I like this problem :-). First, precompute A[1..N] where A<sub>i</sub> contains the longest extension you can make from data<sub>i</sub>, you can do it in O(N). Next, observe the extension&#8217;s end that can be made by each data<sub>i</sub>. Let the extension of data<sub>i</sub> ends at end<sub>i</sub> and data<sub>j</sub> ends at end<sub>j</sub>. If i < j then end<sub>i</sub> &lt;= end<sub>j</sub>. Now consider an interval (L, R), the extension&#8217;s end of each starting point in those intervals will be separated into two types: those which end within the interval, and those which end outside the interval. So? binary search is our friend.</p>
<p><strong>PKU 3421 - X-factor Chains</strong><br />
The time limit for this problem is tight!! A simple O(n.ln(n)) dp solution (precompute the table) will give you TLE. One approach (which I used) to optimize this dp solution is by pruning the search space using prime numbers. You should realize that the length of the longest chain that can be made is equal to the number of it&#8217;s prime factors. Another approach (a non dp solution) is by factoring the number and calculate how many different alignment can be made by those prime numbers. Marcadian used this second approach, and his code run faster than mine.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.suhendry.net/blog/?feed=rss2&amp;p=757</wfw:commentRss>
		</item>
	</channel>
</rss>
