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

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

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>ZOJ Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/category/zoj/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 128. Longest Consecutive Sequence</title>
		<link>https://zxi.mytechroad.com/blog/zoj/leetcode-longest-consecutive-sequence/</link>
					<comments>https://zxi.mytechroad.com/blog/zoj/leetcode-longest-consecutive-sequence/#comments</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Thu, 16 Mar 2017 02:22:06 +0000</pubDate>
				<category><![CDATA[ZOJ]]></category>
		<category><![CDATA[dp]]></category>
		<category><![CDATA[hashmap]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=23</guid>

					<description><![CDATA[<p>Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/zoj/leetcode-longest-consecutive-sequence/">花花酱 LeetCode 128. Longest Consecutive Sequence</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Given an unsorted array of integers, find the length of the longest consecutive elements sequence.</p>
<p>For example,<br />
Given <code>[100, 4, 200, 1, 3, 2]</code>,<br />
The longest consecutive elements sequence is <code>[1, 2, 3, 4]</code>. Return its length: <code>4</code>.</p>
<p>Your algorithm should run in O(<i>n</i>) complexity.</p><pre class="crayon-plain-tag">class Solution {
public:
    int longestConsecutive(vector&lt;int&gt; &amp;num) {
        unordered_map&lt;int,int&gt; m;
        int ans = 0;
        for(auto n : num) {
            if(m.count(n)) continue;
            if(m.count(n-1) &amp;&amp; m.count(n+1)){
                int l = m[n-1], r = m[n+1];
                m[n] = m[n-l] = m[n+r] = r+l+1;
            } else if(m.count(n-1)) {
                int l = m[n-1];
                m[n] = m[n-l] = l+1; 
            } else if(m.count(n+1)) {
                int r = m[n+1];
                m[n] = m[n+r] = r+1;
            } else {
                m[n] = 1;
            }
            ans = max(ans, m[n]);
        }
        return ans;
    }
};</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/zoj/leetcode-longest-consecutive-sequence/">花花酱 LeetCode 128. Longest Consecutive Sequence</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/zoj/leetcode-longest-consecutive-sequence/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>[ZOJ] 3612: Median</title>
		<link>https://zxi.mytechroad.com/blog/zoj/zoj-3612-median/</link>
					<comments>https://zxi.mytechroad.com/blog/zoj/zoj-3612-median/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 13 Mar 2017 02:51:59 +0000</pubDate>
				<category><![CDATA[ZOJ]]></category>
		<category><![CDATA[binary_search]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[median]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[vector]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=17</guid>

					<description><![CDATA[<p>[crayon-663c523f33c5f156750062/] &#160;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/zoj/zoj-3612-median/">[ZOJ] 3612: Median</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p></p><pre class="crayon-plain-tag">// 3934633  2017-03-13 10:48:25 Accepted  3612  C++0x 900 540 xxfflower
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;unordered_map&gt;
#include &lt;algorithm&gt;
#include &lt;queue&gt;
#include &lt;set&gt;
using namespace std;
typedef long long int64;

int main() {
  int t,n,x;
  char op[20];
  cin&gt;&gt;t;

  while(t--) {
    scanf("%d", &amp;n);
    
    vector&lt;int64&gt; a;

    while(n--) {
      scanf("%s %d", op, &amp;x);
      auto it = lower_bound(a.begin(), a.end(), x);

      if(op[0] == 'r') {
        if(it==a.end() || *it != x) {
          puts("Wrong!");
          continue;
        } else {
          a.erase(it);
          if(a.empty()) {
            puts("Empty!");
            continue;
          }
        }
      } else if(op[0] == 'a') {
        a.insert(it, x);
      }

      if(a.size()%2==1) {
        printf("%lld\n", a[a.size()/2]);
      } else {
        int64 ans = a[a.size()/2-1] + a[a.size()/2];
        if(ans%2==0) 
          printf("%lld\n", ans/2);
        else 
          printf("%.1lf\n", ans/2.0);
      }
    }
  }

  return 0;
}</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/zoj/zoj-3612-median/">[ZOJ] 3612: Median</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/zoj/zoj-3612-median/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[ZOJ] 3713: In 7-bit</title>
		<link>https://zxi.mytechroad.com/blog/zoj/zoj-3713-in-7-bit/</link>
					<comments>https://zxi.mytechroad.com/blog/zoj/zoj-3713-in-7-bit/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 13 Mar 2017 00:40:57 +0000</pubDate>
				<category><![CDATA[ZOJ]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[oj]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=14</guid>

					<description><![CDATA[<p>[crayon-663c523f33eaf972426504/] &#160;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/zoj/zoj-3713-in-7-bit/">[ZOJ] 3713: In 7-bit</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p></p><pre class="crayon-plain-tag">// 3934609  2017-03-13 08:38:54 Accepted  3713  C++0x 290 6428  xxfflower
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;iomanip&gt;
using namespace std;

void put_hex(int byte) {
   cout &lt;&lt; hex &lt;&lt; uppercase &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; byte;
}

void put_str(const string&amp; s) {
  for(char c : s)
    put_hex(c);
}

void put_len(int length) {
  while(length&gt;=128) {
    put_hex(length % 128 + 128);
    length &gt;&gt;= 7;
  }
  put_hex(length);
}

int main(int argc, char const *argv[])
{
  int n;
  cin&gt;&gt;n;
  string s;
  getline(cin, s);

  while(n--) {
    getline(cin, s);
    put_len(s.length());
    put_str(s);
    cout&lt;&lt;endl;
  }
  return 0;
}</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/zoj/zoj-3713-in-7-bit/">[ZOJ] 3713: In 7-bit</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/zoj/zoj-3713-in-7-bit/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
