<?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>EUYUIL</title> <atom:link href="http://euyuil.com/feed/" rel="self" type="application/rss+xml" /><link>http://euyuil.com</link> <description>折腾使人进步。</description> <lastBuildDate>Fri, 18 May 2012 06:35:08 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Linux 编程时在控制台输出带格式的字符</title><link>http://euyuil.com/3309/linux-program-print-style-chars-console/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linux-program-print-style-chars-console</link> <comments>http://euyuil.com/3309/linux-program-print-style-chars-console/#comments</comments> <pubDate>Wed, 16 May 2012 04:38:45 +0000</pubDate> <dc:creator>EUYUIL</dc:creator> <category><![CDATA[无类可分]]></category> <category><![CDATA[Linux]]></category> <guid
isPermaLink="false">http://euyuil.com/?p=3309</guid> <description><![CDATA[最近课上老师让写一个类似 ls 命令的程序，还要求要有颜色。上网查了查，有一种方法，大概是输出一个特殊的控制字符 \033, 然后再在后面加一些其它的配置啥的。比如，如果想在一般的文字中，输出一段蓝色的文字，可以这么做： puts("\033[0;34m这些字会是蓝色的，\033[0m而这些字是正常的。\n"); 上面那段代码中，前半句的文字是蓝色的，后半句是正常的。其奥秘就在 \033[0;34m 和 \033[0m 这两串东西里，前者表示随后输出的字符串都以蓝色显示，后者表示随后输出的字符串都以默认方式显示。 那如果需要其它的颜色怎么办呢？其实还是输出类似 \033[0;#m 这样的字符串，只要把里面的 # 改成代表颜色的数字即可： 黑色 30 红色 31 绿色 32 棕色 33 蓝色 34 洋红 35 蓝绿 36 浅灰 37 可以看出来，上面的例子中的参数是 34, 对应着表中的蓝色，所以输出的字符当然是蓝色的啦。 事实上，Linux 的 Console 支持的文字样式还远不止这些。比如，如果你想让接下来的字符都是粗体字，那么输出 \033[1m 即可；如果你想要其它颜色的粗体字，输出 \033[1;#m 字符串，其中 # 对应着上面表中的颜色就行了。 所以似乎 \033 的参数是这样组织的：\033[@;#m . 其中，@ 代表一个数字，表示字体样式；而 # 又代表一个数字，表示字体的颜色（字体的颜色是可选参数，也就是说，如果 ;#m 部分不写出来，就代表默认颜色）。然而现在我们已经知道了 [...]]]></description> <content:encoded><![CDATA[<p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">最近课上老师让写一个类似 ls 命令的程序，还要求要有颜色。上网查了查，有一种方法，大概是输出一个特殊的控制字符 \033, 然后再在后面加一些其它的配置啥的。比如，如果想在一般的文字中，输出一段蓝色的文字，可以这么做：</p><pre  style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;">puts("\033[0;34m<span style="color:blue;" >这些字会是蓝色的，</span>\033[0m而这些字是正常的。\n");</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><span
id="more-3309" ></span></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">上面那段代码中，前半句的文字是蓝色的，后半句是正常的。其奥秘就在 \033[0;34m 和 \033[0m 这两串东西里，前者表示随后输出的字符串都以蓝色显示，后者表示随后输出的字符串都以默认方式显示。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">那如果需要其它的颜色怎么办呢？其实还是输出类似 \033[0;#m 这样的字符串，只要把里面的 # 改成代表颜色的数字即可：</p><style>.table-color { margin: .5em auto; border: solid 1px #aaa; }
.table-color th { width: 80px; }
.table-color td { width: 40px; }</style><table
class="table-color" ><tr><th
style="color:black;" >黑色</th><td>30</td><th
style="color:red;" >红色</th><td>31</td><th
style="color:green;" >绿色</th><td>32</td><th
style="color:brown;" >棕色</th><td>33</td></tr><tr><th
style="color:blue;" >蓝色</th><td>34</td><th
style="color:magenta;" >洋红</th><td>35</td><th
style="color:cyan;" >蓝绿</th><td>36</td><th
style="color:lightgray;" >浅灰</th><td>37</td></tr></table><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">可以看出来，上面的例子中的参数是 34, 对应着表中的蓝色，所以输出的字符当然是蓝色的啦。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">事实上，Linux 的 Console 支持的文字样式还远不止这些。比如，如果你想让接下来的字符都是粗体字，那么输出 \033[1m 即可；如果你想要其它颜色的粗体字，输出 \033[1;#m 字符串，其中 # 对应着上面表中的颜色就行了。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">所以似乎 \033 的参数是这样组织的：\033[@;#m . 其中，@ 代表一个数字，表示字体样式；而 # 又代表一个数字，表示字体的颜色（字体的颜色是可选参数，也就是说，如果 ;#m 部分不写出来，就代表默认颜色）。然而现在我们已经知道了 # 能够写什么，而且 @ 我们也已经知道，0 代表普通样式，1 代表粗体。那 @ 还能是什么呢？看下表：</p><style>.table-style { margin: .5em auto; border: solid 1px #aaa; }
.table-style th { width: 100px; }
.table-style td { width: 500px; }</style><table
class="table-style" ><tr><th>\033[0m</th><td>控制台的默认样式和颜色。</td></tr><tr><th>\033[0;#m</th><td>使用默认样式，颜色由 # 指定。</td></tr><tr><th>\033[1m</th><td>使用<strong>粗体</strong>样式，颜色为默认值（不写出 ;#m 部分即颜色为默认，以下省略）。</td></tr><tr><th>\033[1;#m</th><td>使用<strong>粗体</strong>样式，颜色由 # 指定。</td></tr><tr><th>\033[2;#m</th><td>使用默认样式，但是颜色在 # 的基础上更深一些。</td></tr><tr><th>\033[4;#m</th><td>使用<span
style="text-decoration:underline;" >下划线</span>样式，颜色由 # 指定。</td></tr><tr><th>\033[7;#m</th><td>使用由 # 指定的背景色。</td></tr><tr><th>\033[9;#m</th><td>使用<span
style="text-decoration:line-through;" >删除线</span>样式，颜色由 # 指定。</td></tr></table><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">这样一来，我们能够在 Linux 控制台上使用的文字格式就丰富多了。其实有的时候我们还是不会满足，比如，同时使用粗体和下划线，应该怎么做呢？一种方法是在 \033[1m 之后紧随一个 \033[4m .</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">还有一些特别奇葩的光标控制输出，列表如下：</p><table
class="table-style" ><tr><th>\033[A</th><td>把光标上移一行。</td></tr><tr><th>\033[B</th><td>把光标下移一行。</td></tr><tr><th>\033[C</th><td>把光标右移一字符。</td></tr><tr><th>\033[D</th><td>把光标左移一字符。</td></tr><tr><th>\033[2K</th><td>把在本行的光标之前的所有字符删除。</td></tr></table><div
style="margin-top:15px;" ><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><strong>原创文章，转载请注明来源：</strong><a
href="http://euyuil.com/3309/linux-program-print-style-chars-console/" >http://euyuil.com/3309/linux-program-print-style-chars-console/</a></p></div> ]]></content:encoded> <wfw:commentRss>http://euyuil.com/3309/linux-program-print-style-chars-console/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>我校周末训练赛 1</title><link>http://euyuil.com/3443/tongji-weekend-contest-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tongji-weekend-contest-1</link> <comments>http://euyuil.com/3443/tongji-weekend-contest-1/#comments</comments> <pubDate>Sun, 13 May 2012 13:17:49 +0000</pubDate> <dc:creator>EUYUIL</dc:creator> <category><![CDATA[无类可分]]></category> <category><![CDATA[ICPC]]></category> <category><![CDATA[动态规划]]></category> <category><![CDATA[水题]]></category> <category><![CDATA[练习赛]]></category> <guid
isPermaLink="false">http://euyuil.com/?p=3443</guid> <description><![CDATA[不知道 WH 怎么想的，在 HUST 的测试版 OJ 上 clone 了一个比赛，作为我们的周末训练竞赛题。今天中午从宿舍和两个舍友来到图书馆，浪费了一下时间，就到了 12 点半。此时，比赛开始了。 A &#8211; A Very Simple Problem 一开始，我非常自然地去看 A 题（HUST 1563）。题目中的配图光荣地挂了，我就用 Chrome 的 Inspect Element, 看到了题号，然后到稳定版的 OJ 下看原题，就好了。A 题说的是一个三维空间里，一个 a × b × c 的立方体里，有一个半径为 r 的球，其球心坐标在 (x, y, z) 处。题目保证球不会和立方体产生切割，也不会在立方体之外。然后给球一个 (u, v, w) 的初速，问你在 t 单位时间后，球心位置在哪里。其中，球的任何碰撞都是完全弹性碰撞，不会损耗任何动能，并且不计任何摩擦，任何的反弹都遵循光的反射原理。 其实大体上这题的思路不难。将三个维度分开考虑，以下只考虑第一个维度，其它维度类似。因为球是有半径的东西，所以球心的范围是 [r, a - r], 所以其实可以把 a 减掉两个 [...]]]></description> <content:encoded><![CDATA[<p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">不知道 WH 怎么想的，<a
title="tongji周末训练1"  href="http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=8094#overview"  target="_blank" >在 HUST 的测试版 OJ 上 clone 了一个比赛</a>，作为我们的周末训练竞赛题。今天中午从宿舍和两个舍友来到图书馆，浪费了一下时间，就到了 12 点半。此时，比赛开始了。</p><hr/><h3>A &#8211; A Very Simple Problem</h3><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">一开始，我非常自然地去看 <a
title="HUST 1563"  href="http://acm.hust.edu.cn/problem.php?id=1563"  target="_blank" >A 题（HUST 1563）</a>。题目中的配图光荣地挂了，我就用 Chrome 的 Inspect Element, 看到了题号，然后到稳定版的 OJ 下看原题，就好了。A 题说的是一个三维空间里，一个 <span
style="font-family: 'times new roman', times;" ><em>a</em> × <em>b</em> × <em>c</em></span> 的立方体里，有一个半径为 <em><span
style="font-family: 'times new roman', times;" >r</span></em> 的球，其球心坐标在 <span
style="font-family: 'times new roman', times;" >(<em>x</em>, <em>y</em>, <em>z</em>)</span> 处。题目保证球不会和立方体产生切割，也不会在立方体之外。然后给球一个 <span
style="font-family: 'times new roman', times;" >(<em>u</em>, <em>v</em>, <em>w</em>)</span> 的初速，问你在 <em><span
style="font-family: 'times new roman', times;" >t</span></em> 单位时间后，球心位置在哪里。其中，球的任何碰撞都是完全弹性碰撞，不会损耗任何动能，并且不计任何摩擦，任何的反弹都遵循光的反射原理。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><span
id="more-3443" ></span></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">其实大体上这题的思路不难。将三个维度分开考虑，以下只考虑第一个维度，其它维度类似。因为球是有半径的东西，所以球心的范围是 <span
style="font-family: 'times new roman', times;" >[<em>r</em>, <em>a</em> - <em>r</em>]</span>, 所以其实可以把 <em><span
style="font-family: 'times new roman', times;" >a</span></em> 减掉两个 <em><span
style="font-family: 'times new roman', times;" >r</span></em>, 然后把 <em><span
style="font-family: 'times new roman', times;" >x</span></em> 减掉 <em><span
style="font-family: 'times new roman', times;" >r</span></em>, 之后再把位置加回来即可。其中会用到一个浮点数求余的函数，叫 <span
style="font-family: 'courier new', courier;" >fmod</span>. 其实也可以自己写这么一个函数。嗯，然后 tricks 是，可能立方体会紧紧包住这个球，还有速度可能是负的。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">事实证明我一开始开这道题是错误的选择，因为其实还有更水的题目在等着我。</p><hr/><h3>C &#8211; Sudoku</h3><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><a
title="HUST 1565"  href="http://acm.hust.edu.cn/problem.php?id=1565"  target="_blank" >这道题（HUST 1565）</a>乍一看还以为是特别难的题目，其实是一道猥琐的模拟题，题意不够清晰。主要的意思是，给出一个数独，然后对于一些空位，看看从行列和区域能否推断出这个空位的唯一结果。而且只能“推一步”，还要检查能不能推出来，是否有矛盾等。因为小 bug 我 WA 了多次，其实都是不应该的啊。</p><hr/><h3>E &#8211; Snowflakes in YangShen&#8217;s Home</h3><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><a
title="HUST 1574"  href="http://acm.hust.edu.cn/problem.php?id=1574"  target="_blank" >这道题（HUST 1574）</a>我认为是这次比赛中最水的题目，杀鸡用牛刀般地用了 STL 里的 <span
style="font-family: 'courier new', courier;" >stable_sort</span>, 轻易地过了。</p><hr/><h3>F &#8211; Next K-Bit Number</h3><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><a
title="HUST 1568"  href="http://acm.hust.edu.cn/problem.php?id=1568"  target="_blank" >这道题（HUST 1568）</a>的题意是，给出一个数字，它的二进制表示里有 <em><span
style="font-family: 'times new roman', times;" >k</span></em> 个 <span
style="font-family: 'times new roman', times;" >1</span>, 然后你要找出一个比这个数大的，且二进制表示里也有 <em><span
style="font-family: 'times new roman', times;" >k</span></em> 个 <span
style="font-family: 'times new roman', times;" >1</span> 的数中的，最小的那个数。我的策略是，从低位到高位找到第一次出现的 <span
style="font-family: 'times new roman', times;" >1</span>, 然后再往高位找到第一次出现的 <span
style="font-family: 'times new roman', times;" >0</span>, 假设右边（低位）有 <em><span
style="font-family: 'times new roman', times;" >n</span></em> 个 <span
style="font-family: 'times new roman', times;" >1</span>, 取其中一个取代之前找到那个 <span
style="font-family: 'times new roman', times;" >0</span>, 然后把剩余的 <span
style="font-family: 'times new roman', times;" >(<em>n</em> &#8211; 1)</span> 个 <span
style="font-family: 'times new roman', times;" >1</span> 全部挤到右边去。</p><hr/><h3>H &#8211; Lazy. Lazy. Laaaaaaaaaaaazy!</h3><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><a
title="HUST 1570"  href="http://acm.hust.edu.cn/problem.php?id=1570"  target="_blank" >这道题（HUST 1570）</a>是一道动规题，但是我一开始很 naive 地没有把它当成动规来写，以为是一道水题，我真是 too simple 了。题意大概是，让你打一串有大写有小写的文字，有 CAPSLOCK 和 SHIFT 两种大小写切换方法，问你最少需要按几下按键。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">动规的状态是 <span
style="font-family: 'courier new', courier;" >dp[i][j]</span>, 其含义是打完第 <span
style="font-family: 'courier new', courier;" >j</span> 个字符之后，且 CAPSLOCK 状态是 <span
style="font-family: 'courier new', courier;" >i</span>, 需要按键数量最少是几次。其中 <span
style="font-family: 'courier new', courier;" >i</span> 显然可取 <span
style="font-family: 'times new roman', times;" >0</span> 和 <span
style="font-family: 'times new roman', times;" >1</span> 啦。</p><hr/><h3>L &#8211; Polynomial Integration</h3><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><a
title="HUST 1575"  href="http://acm.hust.edu.cn/problem.php?id=1575"  target="_blank" >这道题（HUST 1575）</a>算挺水的吧，要求计算多项式函数定积分的值，只要注意 [latex]\int x^{-1} \mathrm{d}x = \ln\left\vert x \right\vert[/latex] 就可以了。</p><hr/><h3>M &#8211; Extractor</h3><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><a
title="HUST 1576"  href="http://acm.hust.edu.cn/problem.php?id=1576"  target="_blank" >这道题（HUST 1576）</a>其实也很水，我只看了样例就写过了。没看题，就不描述题意了。<div
style="margin-top:15px;" ><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><strong>原创文章，转载请注明来源：</strong><a
href="http://euyuil.com/3443/tongji-weekend-contest-1/" >http://euyuil.com/3443/tongji-weekend-contest-1/</a></p></div> ]]></content:encoded> <wfw:commentRss>http://euyuil.com/3443/tongji-weekend-contest-1/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>POJ 2387 Til the Cows Come Home</title><link>http://euyuil.com/3438/poj-2387-til-the-cows-come-home/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=poj-2387-til-the-cows-come-home</link> <comments>http://euyuil.com/3438/poj-2387-til-the-cows-come-home/#comments</comments> <pubDate>Fri, 11 May 2012 17:40:52 +0000</pubDate> <dc:creator>EUYUIL</dc:creator> <category><![CDATA[竞赛练习题解]]></category> <category><![CDATA[ICPC]]></category> <category><![CDATA[POJ]]></category> <category><![CDATA[图论]]></category> <category><![CDATA[堆]]></category> <category><![CDATA[最短路]]></category> <category><![CDATA[题解]]></category> <guid
isPermaLink="false">http://euyuil.com/?p=3438</guid> <description><![CDATA[其实这是一道裸的最短路问题，用来测试模板比较好。里面的 trick 是边数给在顶点数之前。 原题地址：http://poj.org/problem?id=2387 我是为了测试用堆优化了的 Dijkstra 算法，才写的这道题。代码前几次犯了一些很 naive 的错误，不过居然有的数据也能对，很神奇。最杯具的事情是，这个用堆优化过的代码，使用了大量的 STL 容器，导致运行时间达到了 235ms 之巨。瞬间感觉堆的优势就因 STL 而消失殆尽了。 源代码如下： [crayon-4fb84f470dd5a/] 原创文章，转载请注明来源：http://euyuil.com/3438/poj-2387-til-the-cows-come-home/]]></description> <content:encoded><![CDATA[<p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">其实这是一道裸的最短路问题，用来测试模板比较好。里面的 trick 是边数给在顶点数之前。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">原题地址：<a
href="http://poj.org/problem?id=2387"  title="POJ 2387 Til the Cows Come Home"  target="_blank" >http://poj.org/problem?id=2387</a></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">我是为了测试用堆优化了的 Dijkstra 算法，才写的这道题。代码前几次犯了一些很 naive 的错误，不过居然有的数据也能对，很神奇。最杯具的事情是，这个用堆优化过的代码，使用了大量的 STL 容器，导致运行时间达到了 235ms 之巨。瞬间感觉堆的优势就因 STL 而消失殆尽了。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><span
id="more-3438" ></span></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">源代码如下：</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"></p><pre class="crayon-plain-tag"   style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;">#include &lt;algorithm&gt;
#include &lt;iostream&gt;
#include &lt;climits&gt;
#include &lt;vector&gt;
#include &lt;list&gt;
using namespace std;
struct stl_glist
{
    struct edge_type {
        int first, second; int length;
        edge_type(int f, int s, int l) : first(f), second(s), length(l) { }
    };
    static const int inf;
    vector&lt;list&lt;int&gt; &gt; ves;
    vector&lt;edge_type&gt; es;
    inline void reset(int n) {
        ves.clear(); es.clear();
        ves.resize(n);
    }
    inline void insert(int u, int v, int w) {
        ves[u].push_back(es.size());
        ves[v].push_back(es.size());
        es.push_back(edge_type(u, v, w));
    }
};
struct stl_dijkstra
{
    const stl_glist &amp;g;
    vector&lt;int&gt; dist, v2hi, heap, prev;
    vector&lt;bool&gt; vstd;
    inline stl_dijkstra(const stl_glist &amp;g) : g(g) { }
    inline void heap_swap(int i, int j) {
        swap(v2hi[heap[i]], v2hi[heap[j]]);
        swap(heap[i], heap[j]);
    }
    inline void heap_push(int i) {
        v2hi[i] = heap.size();
        heap.push_back(i);
    }
    inline void heap_pop() {
        v2hi[heap.back()] = 0;
        heap.pop_back();
    }
    inline void min_heapify(size_t i)
    {
        size_t l = i &lt;&lt; 1, r = l + 1, t = i;
        if (l &lt; heap.size() &amp;&amp; dist[heap[l]] &lt; dist[heap[i]]) t = l;
        if (r &lt; heap.size() &amp;&amp; dist[heap[r]] &lt; dist[heap[t]]) t = r;
        if (t != i) {
            heap_swap(i, t);
            min_heapify(t);
        }
    }
    inline void heap_decrease_key(int i, int val)
    {
        dist[heap[i]] = val;
        for (int p = i &gt;&gt; 1; i &gt; 1 &amp;&amp; dist[heap[p]] &gt; dist[heap[i]];
                i = p, p = p &gt;&gt; 1) {
            heap_swap(i, p);
        }
    }
    inline void push_shorter(int v, int val) {
        int i = heap.size();
        if (v2hi[v] == 0) heap_push(v);
        else i = v2hi[v];
        heap_decrease_key(i, val);
    }
    inline int pop_shortest() {
        if (heap.size() &lt;= 1) return -1;
        int result = heap[1]; vstd[result] = true;
        heap_swap(1, heap.size() - 1); heap_pop();
        min_heapify(1); return result;
    }
    inline void update_adjacent(int u)
    {
        const list&lt;int&gt; &amp;esou = g.ves[u];
        for (list&lt;int&gt;::const_iterator e = esou.begin(); e != esou.end(); ++e) {
            const stl_glist::edge_type &amp;ed = g.es[*e];
            int v = u == ed.first ? ed.second : ed.first;
            if (vstd[v]) continue;
            int len = ed.length + dist[u];
            if (dist[v] &gt; len) {
                push_shorter(v, len);
                prev[v] = u;
            }
        }
    }
    inline void solve(int s)
    {
        dist.resize(g.ves.size()); fill(dist.begin(), dist.end(), stl_glist::inf);
        vstd.resize(g.ves.size()); fill(vstd.begin(), vstd.end(), false);
        v2hi.resize(g.ves.size()); fill(v2hi.begin(), v2hi.end(), 0);
        prev.resize(g.ves.size()); fill(prev.begin(), prev.end(), -1);
        heap.clear(); heap.reserve(g.ves.size() + 1); heap.push_back(0);
        push_shorter(s, 0);
        while ((s = pop_shortest()) &gt;= 0)
            update_adjacent(s);
    }
};
const int stl_glist::inf = INT_MAX;
int main()
{
    int n, m; cin &gt;&gt; m &gt;&gt; n;
    stl_glist graph; stl_dijkstra dijkstra(graph);
    graph.reset(n);
    for (int i = 0; i &lt; m; ++i) {
        int u, v; int w;
        cin &gt;&gt; u &gt;&gt; v &gt;&gt; w;
        graph.insert(--u, --v, w);
    }
    dijkstra.solve(0);
    cout &lt;&lt; dijkstra.dist.back() &lt;&lt; endl;
    return 0;
}</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><div
style="margin-top:15px;" ><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><strong>原创文章，转载请注明来源：</strong><a
href="http://euyuil.com/3438/poj-2387-til-the-cows-come-home/" >http://euyuil.com/3438/poj-2387-til-the-cows-come-home/</a></p></div> ]]></content:encoded> <wfw:commentRss>http://euyuil.com/3438/poj-2387-til-the-cows-come-home/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>STL 的 make_heap 不科学</title><link>http://euyuil.com/3429/make-heap-of-stl-is-bad/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=make-heap-of-stl-is-bad</link> <comments>http://euyuil.com/3429/make-heap-of-stl-is-bad/#comments</comments> <pubDate>Fri, 11 May 2012 11:49:25 +0000</pubDate> <dc:creator>EUYUIL</dc:creator> <category><![CDATA[编程语言]]></category> <category><![CDATA[C/C++]]></category> <category><![CDATA[STL]]></category> <category><![CDATA[图论]]></category> <category><![CDATA[堆]]></category> <category><![CDATA[最短路]]></category> <category><![CDATA[标准]]></category> <guid
isPermaLink="false">http://euyuil.com/?p=3429</guid> <description><![CDATA[首先声明标题只是抱怨性质的话。 今天本来是想写一个带堆优化的 Dijkstra 算法的，我不愿意自己写一个堆，所以就打算用 STL 的相应代码来实现。据我目前所知，STL 里有两种方式维护一个堆，一种是用 priority_queue, 一种是用 make_heap, push_heap, pop_heap 一类的函数。由于 priority_queue 不能实现修改堆中的 key 操作（也就是最大堆中的 Increase-key, 或者最小堆中的 Decrease-key 操作），而且封装得太紧，所以我选用了后者。 由于 Dijkstra 算法中，有一步是要找到最小 dist 的那个顶点，这一步如果用堆优化，就可以把复杂度从 n 降为 1（其主要的开销在堆的维护上，所以总复杂度是 nlogn）。但是有的时候某些已知顶点 v 的 dist 是会改变的，所以这个时候需要把堆里与 v 对应的 key 进行修改。为了修改这个元素，首先要知道这个元素的下标为几何，这个时候可以维护一个数组，其下标为 v 的元素指向堆中相应的代表 v 的元素。这个时候麻烦就来了：如果对堆进行了修改，刚才所述的数组也同样需要修改。这个时候貌似 make_heap 之类的函数也无能为力了。 不过后来我想出了一个比较逆天的方法，专门为堆的元素设计了一个模板类 heds, 名字的全称是 Heap Element for Dijkstra using STL. 我想，在这个类的对象交换的时候，顺便维护一下那个数组，不就可以直接用 STL [...]]]></description> <content:encoded><![CDATA[<p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">首先声明标题只是抱怨性质的话。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">今天本来是想写一个带堆优化的 <em>Dijkstra</em> 算法的，我不愿意自己写一个堆，所以就打算用 STL 的相应代码来实现。据我目前所知，STL 里有两种方式维护一个堆，一种是用 <span
style="font-family: 'courier new', courier;" >priority_queue</span>, 一种是用 <span
style="font-family: 'courier new', courier;" >make_heap</span>, <span
style="font-family: 'courier new', courier;" >push_heap</span>, <span
style="font-family: 'courier new', courier;" >pop_heap</span> 一类的函数。由于 <span
style="font-family: 'courier new', courier;" >priority_queue</span> 不能实现修改堆中的 <span
style="font-family: 'courier new', courier;" >key</span> 操作（也就是最大堆中的 <em>Increase-key</em>, 或者最小堆中的 <em>Decrease-key</em> 操作），而且封装得太紧，所以我选用了后者。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">由于 <em>Dijkstra</em> 算法中，有一步是要找到最小 <span
style="font-family: 'courier new', courier;" >dist</span> 的那个顶点，这一步如果用堆优化，就可以把复杂度从 <em><span
style="font-family: 'times new roman', times;" >n</span></em> 降为 <span
style="font-family: 'times new roman', times;" >1</span>（其主要的开销在堆的维护上，所以总复杂度是 <span
style="font-family: 'times new roman', times;" ><em>n</em>log<em>n</em></span>）。但是有的时候某些已知顶点 <em><span
style="font-family: 'times new roman', times;" >v</span></em> 的 <span
style="font-family: 'courier new', courier;" >dist</span> 是会改变的，所以这个时候需要把堆里与 <em><span
style="font-family: 'times new roman', times;" >v</span></em> 对应的 <span
style="font-family: 'courier new', courier;" >key</span> 进行修改。为了修改这个元素，首先要知道这个元素的下标为几何，这个时候可以维护一个数组，其下标为 <em><span
style="font-family: 'times new roman', times;" >v</span></em> 的元素指向堆中相应的代表 <em><span
style="font-family: 'times new roman', times;" >v</span></em> 的元素。这个时候麻烦就来了：如果对堆进行了修改，刚才所述的数组也同样需要修改。这个时候貌似 <span
style="font-family: 'courier new', courier;" >make_heap</span> 之类的函数也无能为力了。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><span
id="more-3429" ></span></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">不过后来我想出了一个比较逆天的方法，专门为堆的元素设计了一个模板类 <span
style="font-family: 'courier new', courier;" >heds</span>, 名字的全称是 <em>Heap Element for Dijkstra using STL</em>. 我想，在这个类的对象交换的时候，顺便维护一下那个数组，不就可以直接用 STL 的 <span
style="font-family: 'courier new', courier;" >make_heap</span> 等函数了吗？</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">首先我做了一个实验，重写了这个 <span
style="font-family: 'courier new', courier;" >heds</span> 类两个元素之间的 <span
style="font-family: 'courier new', courier;" >swap</span> 函数。然后兴冲冲地调用了 <span
style="font-family: 'courier new', courier;" >make_heap</span> 函数，发现 <strong><span
style="font-family: 'courier new', courier;" >swap</span> 根本没有被调用过</strong>。难道 <span
style="font-family: 'courier new', courier;" >make_heap</span> 自己做了一个奇葩的交换函数么？然后我又观察到，<span
style="font-family: 'courier new', courier;" >make_heap</span> 居然<strong>不会调用 <span
style="font-family: 'courier new', courier;" >heds</span> 的构造函数</strong>，而会调用该类的 <span
style="font-family: 'courier new', courier;" >operator=</span> , 所以就想通过重写等号运算符来解决。为了测试，我写了下面的代码：</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"></p><pre class="crayon-plain-tag"   style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;">#include &lt;cstdio&gt;
#include &lt;iostream&gt;
#include &lt;algorithm&gt;
using namespace std;
template &lt;class T, T *dist, int **v2hi&gt; struct heds
{
	int v;
	inline bool operator&lt;(const heds &amp;b) const {
		return dist[v] &lt; dist[b.v];
	}
	inline heds &amp;operator=(const heds &amp;b) {
		v2hi[v] = (int *) &amp;b; v = b.v;
	}
};
const int N = 10;
int *v2hi[N]; int dist[N];
heds &lt;int, dist, v2hi&gt; heap[N];
int main()
{
	for (int i = 0; i &lt; N; ++i)
		heap[i].v = dist[i] = i;
	for (int i = 0; i &lt; N; ++i)
		v2hi[i] = (int *) &amp;heap[i];
	random_shuffle(dist, dist + N);
	make_heap(heap, heap + N);
	return 0;
}</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">结果我发现，在 <span
style="font-family: 'courier new', courier;" >make_heap</span> 之后，<span
style="font-family: 'courier new', courier;" >v2hi</span> 这个数组居然有一些元素都指向着同一个指针，且这个指针居然不属于 <span
style="font-family: 'courier new', courier;" >heap</span> 数组的元素！其中的问题只可能出现在 <span
style="font-family: 'courier new', courier;" >v2hi[v] = (int *) &amp;b;</span> 这句话上。我认为，<span
style="font-family: 'courier new', courier;" >make_heap</span> 为了交换两个元素，没有调用 <span
style="font-family: 'courier new', courier;" >swap</span>, 而是使用了它自己维护的一种方法。这种方法也是<strong>使用了一个临时空间，但是这个临时空间居然没有调用它的构造函数</strong>。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">或许我只能在 <span
style="font-family: 'courier new', courier;" >heds</span> 类里再加一个成员变量，表示这个元素一开始的指针。这样即使是被 copy 出了临时变量，还可以知道原来的地址在哪里。如果 STL 的算法在交换元素的时候使用自己的函数该多好。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">又是一次瞎折腾的过程……<div
style="margin-top:15px;" ><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><strong>原创文章，转载请注明来源：</strong><a
href="http://euyuil.com/3429/make-heap-of-stl-is-bad/" >http://euyuil.com/3429/make-heap-of-stl-is-bad/</a></p></div> ]]></content:encoded> <wfw:commentRss>http://euyuil.com/3429/make-heap-of-stl-is-bad/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>SGU 101 Domino</title><link>http://euyuil.com/3372/sgu-101-domino/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sgu-101-domino</link> <comments>http://euyuil.com/3372/sgu-101-domino/#comments</comments> <pubDate>Thu, 10 May 2012 07:43:30 +0000</pubDate> <dc:creator>EUYUIL</dc:creator> <category><![CDATA[竞赛练习题解]]></category> <category><![CDATA[ICPC]]></category> <category><![CDATA[SGU]]></category> <category><![CDATA[图论]]></category> <category><![CDATA[推荐题]]></category> <category><![CDATA[易错题]]></category> <category><![CDATA[欧拉路]]></category> <category><![CDATA[题解]]></category> <guid
isPermaLink="false">http://euyuil.com/?p=3372</guid> <description><![CDATA[这道题的题意是，有 1 × 2 的多米诺骨牌，中间有一条线将其分成两个 1 × 1 的小块，每个小块上可以有 0 ~ 6 的整数。现在给出 n (1 ≤ n ≤ 100) 个多米诺骨牌，你要把它们接起来，并且相邻的两个多米诺骨牌相接的小块的数字要相同。问你是否存在这样一种方法，如果存在则输出具体的方案，如果有多种方案则输出一个即可；否则输出 No solution. 原题地址：http://acm.sgu.ru/problem.php?contest=0&#38;problem=101 其实看到这题后可以很快想到这是一个一笔画问题，其实就是欧拉回路和欧拉通路问题。判断欧拉回路或欧拉通路是否能存在，可以使用 O(V) 的算法实现。找到一条欧拉回路或欧拉通路，有一种算法叫 Fleury&#8217;s Algorithm, 复杂度是 O(V2). 但是其实有一种逆天的算法能在 O(V) 的时间内实现。 这道题有很多 tricks, 需要注意的有： 图是否是连通的。 有的时候输入数据没有把所有顶点用上，这时如果给出的顶点是连通的，那么也应该把图当成连通的。 图中是否有欧拉通路或欧拉回路。 如果只有欧拉通路，那么一定要选择正确的顶点开始遍历。 如果有欧拉回路，必须要从一个数据中给过的顶点开始遍历。 反正这些我是都栽了，绝对是忠告。 以下是源代码： [crayon-4fb84f4712b81/] 原创文章，转载请注明来源：http://euyuil.com/3372/sgu-101-domino/]]></description> <content:encoded><![CDATA[<p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">这道题的题意是，有 <span
style="font-family: 'times new roman', times;" >1 × 2</span> 的多米诺骨牌，中间有一条线将其分成两个 <span
style="font-family: 'times new roman', times;" >1 × 1</span> 的小块，每个小块上可以有 <span
style="font-family: 'times new roman', times;" >0 ~ 6</span> 的整数。现在给出 <span
style="font-family: 'times new roman', times;" ><em>n</em> (1 ≤ <em>n</em> ≤ 100)</span> 个多米诺骨牌，你要把它们接起来，并且相邻的两个多米诺骨牌相接的小块的数字要相同。问你是否存在这样一种方法，如果存在则输出具体的方案，如果有多种方案则输出一个即可；否则输出 <span
style="font-family: 'courier new', courier;" >No solution</span>.</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">原题地址：<a
href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=101"  target="_blank" >http://acm.sgu.ru/problem.php?contest=0&amp;problem=101</a></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><span
id="more-3372" ></span></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">其实看到这题后可以很快想到这是一个一笔画问题，其实就是欧拉回路和欧拉通路问题。判断欧拉回路或欧拉通路是否能存在，可以使用 <span
style="font-family: 'times new roman', times;" >O(<em>V</em>)</span> 的算法实现。找到一条欧拉回路或欧拉通路，有一种算法叫 <em>Fleury&#8217;s Algorithm</em>, 复杂度是 <span
style="font-family: 'times new roman', times;" >O(<em>V</em><sup>2</sup>)</span>. 但是其实有一种逆天的算法能在 <span
style="font-family: 'times new roman', times;" >O(<em>V</em>)</span> 的时间内实现。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">这道题有很多 tricks, 需要注意的有：</p><ul><li>图是否是连通的。</li><li>有的时候输入数据没有把所有顶点用上，这时如果给出的顶点是连通的，那么也应该把图当成连通的。</li><li>图中是否有欧拉通路或欧拉回路。</li><li>如果只有欧拉通路，那么一定要选择正确的顶点开始遍历。</li><li>如果有欧拉回路，必须要从一个数据中给过的顶点开始遍历。</li></ul><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">反正这些我是都栽了，绝对是忠告。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">以下是源代码：</p><pre class="crayon-plain-tag"   style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;">#include &lt;list&gt;
#include &lt;vector&gt;
#include &lt;cstdio&gt;
#include &lt;utility&gt;
#include &lt;cstdlib&gt;
using namespace std;
typedef list&lt;int&gt; lint;
typedef vector&lt;int&gt; vint;
typedef vector&lt;lint&gt; vlint;
typedef pair&lt;int, int&gt; prii;
typedef vector&lt;prii&gt; vprii;
typedef vector&lt;bool&gt; vbool;
int n;
vlint ves; // vertex to edges.
vprii es; // edges.
vbool vst; // vertex visited;
vbool est; // edge visited.
vint vstk; // vertex stack.
vint vrst; // vertex result.
vint estk; // edge stack.
vint erst; // edge result.
inline void init()
{
    ves.clear(); ves.resize(7);
    es.clear();
}
inline void insert(int u, int v)
{
    ves[u].push_back(es.size());
    ves[v].push_back(es.size());
    es.push_back(make_pair(u, v));
}
void search(int u)
{
    if (vst[u]) return; vst[u] = true;
    lint::iterator e; lint &amp;ve = ves[u];
    for (e = ve.begin(); e != ve.end(); ++e)
    {
        int v = es[*e].first == u ? es[*e].second : es[*e].first;
        search(v);
    }
}
inline bool connected()
{
    vst.clear(); vst.resize(7, false);
    int c = 0, last_node;
    for (int i = 0; i &lt; 7; ++i)
        if (ves[i].size() != 0)
            ++c, last_node = i;
    search(last_node);
    for (int i = 0; i &lt; 7; ++i)
        if (vst[i])
            --c;
    return c == 0;
}
inline void tour(int u)
{
    tour_start:
    {
        lint::iterator e; lint &amp;ve = ves[u];
        for (e = ve.begin(); e != ve.end(); ++e)
        {
            if (est[*e]) continue; est[*e] = true;
            u = es[*e].first == u ? es[*e].second : es[*e].first;
            break;
        }
        if (e == ve.end()) return;
        vstk.push_back(u);
        estk.push_back(*e);
    }
    goto tour_start;
}
inline void euler(int u)
{
    est.clear(); est.resize(es.size(), false);
    vrst.clear(); erst.clear();
    vstk.clear(); estk.clear();
    vstk.push_back(u);
    for (int i = 0; i &lt; n; ++i)
    {
        tour(vstk.back());
        vrst.push_back(vstk.back()); vstk.pop_back();
        erst.push_back(estk.back()); estk.pop_back();
    }
    // vertices are one more than edges.
    // and there is vstk.back() == u.
    vrst.push_back(vstk.back()); vstk.pop_back();
}
inline int start()
{
    int odd_count = 0, last_odd = -1, last_node = -1;
    for (int i = 0; i &lt; ves.size(); ++i) {
        if (ves[i].size() % 2 == 1)
            ++odd_count, last_odd = i;
        else if (ves[i].size() != 0)
            last_node = i;
    }
    if (odd_count == 0) return last_node;
    if (odd_count == 2) return last_odd;
    return -1;
}
int main()
{
    // freopen(&quot;101.domino.txt&quot;, &quot;r&quot;, stdin);
    scanf(&quot;%d&quot;, &amp;n); init();
    for (int i = 0; i &lt; n; ++i)
    {
        int u, v; scanf(&quot;%d%d&quot;, &amp;u, &amp;v);
        insert(u, v);
    }
    int s; if (!connected() || (s = start()) == -1) {
        printf(&quot;No solution\n&quot;);
    } else {
        euler(s);
        for (int i = 0; i &lt; erst.size(); ++i)
            printf(&quot;%d %c\n&quot;, erst[i] + 1,
                vrst[i] == es[erst[i]].first ? '+' : '-');
    }
    return 0;
}</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><div
style="margin-top:15px;" ><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><strong>原创文章，转载请注明来源：</strong><a
href="http://euyuil.com/3372/sgu-101-domino/" >http://euyuil.com/3372/sgu-101-domino/</a></p></div> ]]></content:encoded> <wfw:commentRss>http://euyuil.com/3372/sgu-101-domino/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>小小地维护了一下博客</title><link>http://euyuil.com/3379/blog-maintenance-finished/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=blog-maintenance-finished</link> <comments>http://euyuil.com/3379/blog-maintenance-finished/#comments</comments> <pubDate>Thu, 10 May 2012 01:07:21 +0000</pubDate> <dc:creator>EUYUIL</dc:creator> <category><![CDATA[无类可分]]></category> <category><![CDATA[GFW]]></category> <category><![CDATA[博客]]></category> <guid
isPermaLink="false">http://euyuil.com/?p=3379</guid> <description><![CDATA[首先惊悉功夫网将 GoDaddy 的 NS 给墙了。联想到近几天在学校的 DNS 服务器查不到自己的域名的 IP, 不禁一阵寒意。小站如此和谐，域名怎会被认证呢？后来看到月光博客里的提示，说可以把 NS 改成一些其它的免费 NS, 而不要把域名托管到国内，随后我就找了这么一家服务商。具体是什么就不说了，有软文之嫌啊。不知道以后能不能正确解析，师母已呆吧。 然后我想起博客上的回复评论以前是有 AJAX 的，现在都没发现。这是很奇怪的事情。开始以为是 WordPress 更新之后，我的老主题 out 了，不兼容了。好吧，经过各种折腾，其实不是主题的问题，而是用了 WP Minify 导致的。这个插件把各种 JavaScript 脚本和 CSS 整合成一个文件，可以加快网页读取速度。后来我在其设置页上把 comment-reply 给排除了，就好了。顺便排除了 Image Lazy Load, 这样久违的延迟载入功能又回来了。我猜出现这样的原因可能是我的某个 JavaScript 有问题，连累了其它的文件吧。 原创文章，转载请注明来源：http://euyuil.com/3379/blog-maintenance-finished/]]></description> <content:encoded><![CDATA[<p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">首先惊悉功夫网将 GoDaddy 的 NS 给墙了。联想到近几天在学校的 DNS 服务器查不到自己的域名的 IP, 不禁一阵寒意。小站如此和谐，域名怎会被认证呢？后来看到月光博客里的提示，说可以把 NS 改成一些其它的免费 NS, 而不要把域名托管到国内，随后我就找了这么一家服务商。具体是什么就不说了，有软文之嫌啊。不知道以后能不能正确解析，师母已呆吧。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">然后我想起博客上的回复评论以前是有 AJAX 的，现在都没发现。这是很奇怪的事情。开始以为是 WordPress 更新之后，我的老主题 out 了，不兼容了。好吧，经过各种折腾，其实不是主题的问题，而是用了 WP Minify 导致的。这个插件把各种 JavaScript 脚本和 CSS 整合成一个文件，可以加快网页读取速度。后来我在其设置页上把 comment-reply 给排除了，就好了。顺便排除了 Image Lazy Load, 这样久违的延迟载入功能又回来了。我猜出现这样的原因可能是我的某个 JavaScript 有问题，连累了其它的文件吧。<div
style="margin-top:15px;" ><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><strong>原创文章，转载请注明来源：</strong><a
href="http://euyuil.com/3379/blog-maintenance-finished/" >http://euyuil.com/3379/blog-maintenance-finished/</a></p></div> ]]></content:encoded> <wfw:commentRss>http://euyuil.com/3379/blog-maintenance-finished/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>2012 金华邀请赛参赛总结</title><link>http://euyuil.com/3354/2012-jinhua-invitation-review/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=2012-jinhua-invitation-review</link> <comments>http://euyuil.com/3354/2012-jinhua-invitation-review/#comments</comments> <pubDate>Mon, 07 May 2012 02:26:57 +0000</pubDate> <dc:creator>EUYUIL</dc:creator> <category><![CDATA[无类可分]]></category> <category><![CDATA[ICPC]]></category> <category><![CDATA[总结]]></category> <category><![CDATA[最长公共子序列]]></category> <category><![CDATA[现场赛]]></category> <category><![CDATA[网络流]]></category> <category><![CDATA[计算几何]]></category> <category><![CDATA[邀请赛]]></category> <guid
isPermaLink="false">http://euyuil.com/?p=3354</guid> <description><![CDATA[首先感慨一下，现在的动车都好谨慎。这次我们坐的动车，在近某站之前，说什么“由于停留时间较短，请不是本站下车的旅客不要外出散步”，结果“由于信号原因”，一直不敢开出，硬生生晚点了 50 分钟。然而似乎大家都很理解，没有什么抱怨，可能是因为上次事故的教训吧。 到了金华已是中午 12 点多，和叶总寒暄几句后，马上赶到浙江师范大学，那个热啊，真是符合热身赛的精神了。比赛场地是在机房，有两层，不过据说下半年的区域赛会在新建的体育馆内举行。找到位置后，两个队友过于兴奋，居然看到桌上的信封就想拿，那可是题目啊，比赛还没开始。 热身赛的第一题就这样过了，然后第二题是一个所谓的“最小费用最大流”，我居然从来没做过。然后拍 Wideas 的模板，最后 TLE 了。想想只不过是热热身，就下去看我校另一队——火腿队的战况。他们也差不多，正在奋战 BC 两题。好吧后来据说火腿队用模拟的方法过了 C. 下午去宾馆，由于这次我们居然来了个女生，当然是得住单间的。然后这样男生也成了奇数，所以让翔哥住单间尊贵了一次。说好的巧克力和咖啡晚上都没买。唉，算了，无功不受禄。 第二天早上，闹铃还没响，我在 6 点 15 分左右就起床了。按照舍友 SBH 的标准，所谓“起晚”的定义，是没有听闹铃而自然起床。所以我算是起晚了。然后校车去了比赛场地。 开始比赛后迅速看题。这 A 题怎么有点像最长公共子序列 (longest common sub-sequence) 呢？似乎又不是最长公共子序列，因为题目要求序列必须是连续的 (consecutive). 所以这应该叫最长公共子串 (longest common sub-string). 这是坑爹其一。当然还有坑爹其二：这题我们两个人提交了很多次，都 WA 了，卡到了 10 点 40 多分，居然开始了 rejudge&#8230; 结果我们 1A 了。 后来我发现了 E 是计算几何，还好我有清晰的模板，我就向队友表示：“如果你们不打字，就让我打计算几何模板吧。”结果打了一半，B 的思路有了，我就中断了。看到一题似乎是字符串匹配，数据范围 5M, 有点大，比赛时 too simple, sometimes naive [...]]]></description> <content:encoded><![CDATA[<p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">首先感慨一下，现在的动车都好谨慎。这次我们坐的动车，在近某站之前，说什么“由于停留时间较短，请不是本站下车的旅客不要外出散步”，结果“由于信号原因”，一直不敢开出，硬生生晚点了 50 分钟。然而似乎大家都很理解，没有什么抱怨，可能是因为上次事故的教训吧。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">到了金华已是中午 12 点多，和叶总寒暄几句后，马上赶到浙江师范大学，那个热啊，真是符合热身赛的精神了。比赛场地是在机房，有两层，不过据说下半年的区域赛会在新建的体育馆内举行。找到位置后，两个队友过于兴奋，居然看到桌上的信封就想拿，那可是题目啊，比赛还没开始。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><span
id="more-3354" ></span></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">热身赛的第一题就这样过了，然后第二题是一个所谓的“最小费用最大流”，我居然从来没做过。然后拍 Wideas 的模板，最后 TLE 了。想想只不过是热热身，就下去看我校另一队——火腿队的战况。他们也差不多，正在奋战 BC 两题。好吧后来据说火腿队用模拟的方法过了 C.</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">下午去宾馆，由于这次我们居然来了个女生，当然是得住单间的。然后这样男生也成了奇数，所以让翔哥住单间尊贵了一次。说好的巧克力和咖啡晚上都没买。唉，算了，无功不受禄。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">第二天早上，闹铃还没响，我在 6 点 15 分左右就起床了。按照舍友 SBH 的标准，所谓“起晚”的定义，是没有听闹铃而自然起床。所以我算是起晚了。然后校车去了比赛场地。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">开始比赛后迅速看题。这 A 题怎么有点像<strong>最长公共子序列</strong> (<em>longest common sub-sequence</em>) 呢？似乎又不是最长公共子序列，因为题目要求序列必须是连续的 (<em>consecutive</em>). 所以这应该叫<strong>最长公共子串</strong> (<em>longest common sub-string</em>). 这是坑爹其一。当然还有坑爹其二：这题我们两个人提交了很多次，都 WA 了，卡到了 10 点 40 多分，居然开始了 rejudge&#8230; 结果我们 1A 了。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">后来我发现了 E 是计算几何，还好我有清晰的模板，我就向队友表示：“如果你们不打字，就让我打计算几何模板吧。”结果打了一半，B 的思路有了，我就中断了。看到一题似乎是字符串匹配，数据范围 5M, 有点大，比赛时 too simple, sometimes naive 了，以为用 Trie 可以做，赛后 ZL 说会爆内存才意识到。在思考的过程中，B WA 了一次，然后过了。我就继续打计算几何。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">调试的过程中，有的数据出错了。所幸还是发现了错误——模板里产生射线的函数我给写错了，少了个取绝对值，所以有的时候射线的方向就会很奇怪。后来还是略带紧张地 1A 了。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">此时 LD 想写 D, 写就写吧。我就看那个 Trie 的模板啊，其实这也是无用功。然后 XW 问我那道棋盘的题的题意，我感觉没把握，就表示不敢开这道题。最后 D 那个线段树，LD 的样例都是对的，后来交上去 TLE 了。怒交怒 WA, 这样比赛就结束了。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">最后的排名比火腿队稍微低了一点，罚时似乎多了 3 分钟。</p><div
id="attachment_3362"  class="wp-caption alignleft"     style="width: 310pxwidth: 310pxfloat:left;float:left;"><a
href="http://uploads.euyuil.com/2012/05/IMG_20120505_162356.jpg" ><img
src="http://uploads.euyuil.com/2012/05/IMG_20120505_162356-300x225.jpg"  alt="浙江师范大学校门内的照片"  title="浙江师范大学校门内"  width="300"  height="225"  class="size-medium wp-image-3362" /></a><p
class="wp-caption-text"     style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;text-indent:0;text-indent:0;">浙江师范大学校门内的照片</p></div><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">出来在学校里逛了逛，发现正对大门有一尊孔子雕像，就想起了伟大领袖毛主席。随口问了一下旁边的志愿者同学，她说学校里是没有毛主席雕像的。第一次发现大学里也可以没有毛主席雕像啊。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">之后回宾馆，WH 和 Sky Walker 等要做 Google Code Jam, 我感觉衬衫无望，就回校了。动车上各种八卦，在此省略千字。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">最后是一点总结，参赛总结我一向不说优点，若是队友看到，不要往心里去啊。当然我也很欢迎队友能够数落一下我。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">对自己，这次的比赛还是弱了点。轮到自己带别人，却没有非常充分发挥所谓队长的作用。首先个人算法还是比较稀松，居然让女生去打了 2 道题，差点让人家单挑了；如果能够对各种问题即使是有略微的了解的话，可能我来打会比较快一些，所以这点要向 Wideas 学习。然后对于一些决策上的事情，还是优柔寡断了，比如说开题比较随意。总的来说，要加强训练。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">然后说说队友。共同的问题是语言，语言包含两方面，一个是编程语言，一个是英语。LD 高中竞赛用的是 Pascal, 只会很基础的 C 语言，指针什么的不会，更别说 STL 了，快排什么的都是直接手写，怎样把数组指针传递到函数里也不懂；写的程序不够结构化，别人看起来难以调试。相对来说 XW 在这方面好一些。然后是英语，虽然说我的英语也不是特别的好，但是在和 Wideas, WH 组队的时候，就没有带过词典啊。什么 bidirectional, corresponding 都来问我，真是替你们着急啊，看来下次是不是真的要带词典了呢？<div
style="margin-top:15px;" ><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><strong>原创文章，转载请注明来源：</strong><a
href="http://euyuil.com/3354/2012-jinhua-invitation-review/" >http://euyuil.com/3354/2012-jinhua-invitation-review/</a></p></div> ]]></content:encoded> <wfw:commentRss>http://euyuil.com/3354/2012-jinhua-invitation-review/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>ABBYY Cup 2.0 &#8211; Easy</title><link>http://euyuil.com/3323/abbyy-cup-2-0-easy/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=abbyy-cup-2-0-easy</link> <comments>http://euyuil.com/3323/abbyy-cup-2-0-easy/#comments</comments> <pubDate>Sun, 22 Apr 2012 15:06:28 +0000</pubDate> <dc:creator>EUYUIL</dc:creator> <category><![CDATA[竞赛练习题解]]></category> <category><![CDATA[ABBYY]]></category> <category><![CDATA[Codeforces]]></category> <category><![CDATA[二分法]]></category> <category><![CDATA[水题]]></category> <guid
isPermaLink="false">http://euyuil.com/?p=3323</guid> <description><![CDATA[这个比赛居然有 7 题，不过既然有个 Easy 在标题上，那么肯定很多水题的。不过几场 Div 2 下来，还没有到 Div 1, 还是略挫了啊…… 很有意思的是这个比赛有一部分是 host 在 Codeforces 上的，似乎官方是俄文，和 Codeforces 国籍相同啊。 我在比赛开始后半个小时才意识到注册了这个比赛。当时还在 Google Camp 里，情急之中做了 2 题，然后看了 C 题才回的宿舍。 首先是 A 题，很水。当时看到 A2 的时候愣了一下，怎么会有一样的题目呢……后来经过肉眼逐字比对发现没有任何区别，我才知道被坑了。其实 A2 就是比 A1 数据范围大一点啊什么的罢了。 B 题，本质上就是分解质因数呗。 这个时候开始回宿舍，并且打了很长时间的电话回家，还在外面吃了东西，在空闲的时候想了想 C 题。一晃一个小时过去了…… C 题，我是用并查集解的。把所有的人看成节点，朋友关系看成无向边，显然每个连通分量都是一个朋友圈。然后如果在一个朋友圈内，如果有两个家伙不喜欢对方，那么其实这个朋友圈是不能聚起来的，所以就把这些圈子排除掉，最后找人数最多的圈子就可以了。 D 题思路很快就出来了，显然就是预处理密钥串，使得能够在常数时间计算从第 i 个元素加到第 j 个元素的结果。然后密文上的第一个元素，加上密钥的第一个元素；密文的第二个元素，加上密钥的第一和第二个元素；以此类推。但是在推“第 t 个元素应该加上密钥的第几到第几个元素”这个问题上，我推了很久……其实这不是很难的内容，说明还需训练啊。 E 题被它的“In some solutions even [...]]]></description> <content:encoded><![CDATA[<p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><a
title="http://codeforces.com/contest/177"  href="http://codeforces.com/contest/177"  target="_blank" >这个比赛</a>居然有 7 题，不过既然有个 Easy 在标题上，那么肯定很多水题的。不过几场 Div 2 下来，还没有到 Div 1, 还是略挫了啊……</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">很有意思的是这个比赛有一部分是 host 在 Codeforces 上的，似乎官方是俄文，和 Codeforces 国籍相同啊。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">我在比赛开始后半个小时才意识到注册了这个比赛。当时还在 Google Camp 里，情急之中做了 2 题，然后看了 C 题才回的宿舍。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><span
id="more-3323" ></span></p><hr/><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">首先是 A 题，很水。当时看到 A2 的时候愣了一下，怎么会有一样的题目呢……后来经过肉眼逐字比对发现没有任何区别，我才知道被坑了。其实 A2 就是比 A1 数据范围大一点啊什么的罢了。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">B 题，本质上就是分解质因数呗。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">这个时候开始回宿舍，并且打了很长时间的电话回家，还在外面吃了东西，在空闲的时候想了想 C 题。一晃一个小时过去了……</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">C 题，我是用并查集解的。把所有的人看成节点，朋友关系看成无向边，显然每个连通分量都是一个朋友圈。然后如果在一个朋友圈内，如果有两个家伙不喜欢对方，那么其实这个朋友圈是不能聚起来的，所以就把这些圈子排除掉，最后找人数最多的圈子就可以了。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">D 题思路很快就出来了，显然就是预处理密钥串，使得能够在常数时间计算从第 <em><span
style="font-family: 'times new roman', times;" >i</span></em> 个元素加到第 <em><span
style="font-family: 'times new roman', times;" >j</span></em> 个元素的结果。然后密文上的第一个元素，加上密钥的第一个元素；密文的第二个元素，加上密钥的第一和第二个元素；以此类推。但是在推“第 <em><span
style="font-family: 'times new roman', times;" >t</span></em> 个元素应该加上密钥的第几到第几个元素”这个问题上，我推了很久……其实这不是很难的内容，说明还需训练啊。</p><hr/><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">E 题被它的“In some solutions even the 64-bit arithmetic can overflow”吓到了，其实注意一下，也没有那么恐怖。根据题意，有如下式子：</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">[latex] \LARGE \sum \limits_{i = 1}^{n} \lfloor \frac{x a_i}{b_i} \rfloor = c &#8211; n [/latex]</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">其中，我们要做的事情，就是求出 <em><span
style="font-family: 'times new roman', times;" >x</span></em> 有多少整数解。在此之前我们需要考虑一些特殊情况。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">比如，当所有的 <em><span
style="font-family: 'times new roman', times;" >a<sub>i</sub></span></em> 都是 <span
style="font-family: 'times new roman', times;" >0</span>, 并且 <span
style="font-family: 'times new roman', times;" ><em>c</em> = <em>n</em></span> 的时候，也就是说，每个星球都不能允许带包裹，并且星球的数目等于旅行天数时，<em><span
style="font-family: 'times new roman', times;" >x</span></em> 有无数个解；如果第一个条件成立，而 <span
style="font-family: 'times new roman', times;" ><em>c</em> ≠ <em>n</em></span> 的时候，则 <em><span
style="font-family: 'times new roman', times;" >x</span></em> 无解。因为没有判断 <span
style="font-family: 'times new roman', times;" ><em>c</em> ≠ <em>n</em></span>, 我 WA 了一次。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">还有就是万一 <span
style="font-family: 'times new roman', times;" ><em>c</em> &lt; <em>n</em></span> 什么的发生也是很恶心的，不知道数据有没有卡这些点，反正我是考虑了。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">然后的问题就是求 <em><span
style="font-family: 'times new roman', times;" >x</span></em> 了。求 <em><span
style="font-family: 'times new roman', times;" >x</span></em> 其实可以想到用二分法，经过我的计算，一定有 <span
style="font-family: 'times new roman', times;" ><em>x</em> ≤ 10<sup>18</sup></span>. 但是其实这还不够，如果二分的上界就认为是这个数了，那么根据上面那个大大的等式，<em><span
style="font-family: 'times new roman', times;" >x·a<sub>i</sub></span></em> 很容易超过 64-bit integer 的范围。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">所以枚举上界的时候，要令 [latex] upper(x) = \frac{10^{18}}{max\{a_i\}} [/latex] 才可以。但是这个时候，我居然让 <em><span
style="font-family: 'times new roman', times;" >x</span></em> 去除以每个 <em><span
style="font-family: 'times new roman', times;" >a<sub>i</sub></span></em>, 然后比较哪个比较小，其实这样是有问题的，如果 <em><span
style="font-family: 'times new roman', times;" >a<sub>i</sub></span></em> 含有 <span
style="font-family: 'times new roman', times;" >0</span>, 那就会出现被 <span
style="font-family: 'times new roman', times;" >0</span> 除的情况。所以我在这里 WA 了一次。更 2 的事情，是我该的时候居然该成了“如果 <em><span
style="font-family: 'times new roman', times;" >a<sub>i</sub></span></em> 是 <span
style="font-family: 'times new roman', times;" >0</span> 则不除”这样的方法，而不是之前的 <span
style="font-family: 'times new roman', times;" >max</span> 方法……不过最后还是过了。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">下面是 E 的代码：</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"></p><pre class="crayon-plain-tag"   style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;">#include &lt;cstdio&gt;
#include &lt;iostream&gt;
using namespace std;
typedef long long ll;
const int N = 11111;
ll n, a[N], b[N], c;
inline ll calc(ll x)
{
    ll result = 0ll;
    for (int i = 0; i &lt; n; ++i)
        result += x * a[i] / b[i];
    return result;
}
inline ll lower(ll r, ll cmn)
{
    ll l = 0ll;
    while (r - l &gt; 1ll)
    {
        ll m = (l + r) &gt;&gt; 1;
        if (calc(m) &gt;= cmn)
            r = m;
        else
            l = m;
    }
    return r;
}
inline ll upper(ll r, ll cmn)
{
    ll l = 0ll;
    while (r - l &gt; 1ll)
    {
        ll m = (l + r) &gt;&gt; 1;
        if (calc(m) &lt;= cmn)
            l = m;
        else
            r = m;
    }
    return l;
}
int main()
{
    // freopen(&quot;E1.in&quot;, &quot;r&quot;, stdin);
    cin &gt;&gt; n &gt;&gt; c;
    for (int i = 0; i &lt; n; ++i)
        cin &gt;&gt; a[i] &gt;&gt; b[i];
    bool allzero = true;
    for (int i = 0; i &lt; n; ++i)
        if (a[i] != 0)
            allzero = false;
    if (allzero) // unlimited sols.
    {
        if (c != n)
            cout &lt;&lt; 0 &lt;&lt; endl;
        else
            cout &lt;&lt; -1 &lt;&lt; endl;
        return 0;
    }
    ll maxx = 1111111111111111112ll;
    for (int i = 0; i &lt; n; ++i)
    {
        if (a[i] == 0)
            continue;
        ll t = 1111111111111111111ll / a[i];
        if (maxx &gt; t)
            maxx = t;
    }
    ll cmn = c - n;
    if (cmn &lt; 0) // no sols.
    {
        cout &lt;&lt; 0 &lt;&lt; endl;
        return 0;
    }
    ll lwr = lower(maxx, cmn);
    ll upr = upper(maxx, cmn);
    if (lwr &gt; upr)
        cout &lt;&lt; 0 &lt;&lt; endl;
    else
        cout &lt;&lt; upr - lwr + 1 &lt;&lt; endl;
    return 0;
}</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">最后两题没有看。<div
style="margin-top:15px;" ><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><strong>原创文章，转载请注明来源：</strong><a
href="http://euyuil.com/3323/abbyy-cup-2-0-easy/" >http://euyuil.com/3323/abbyy-cup-2-0-easy/</a></p></div> ]]></content:encoded> <wfw:commentRss>http://euyuil.com/3323/abbyy-cup-2-0-easy/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>如何在 Gnome 3 的 GDM 中隐藏某些用户</title><link>http://euyuil.com/3317/how-to-hide-user-gnome-3-gdm/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-hide-user-gnome-3-gdm</link> <comments>http://euyuil.com/3317/how-to-hide-user-gnome-3-gdm/#comments</comments> <pubDate>Mon, 16 Apr 2012 10:20:15 +0000</pubDate> <dc:creator>EUYUIL</dc:creator> <category><![CDATA[无类可分]]></category> <category><![CDATA[Arch Linux]]></category> <category><![CDATA[Git]]></category> <category><![CDATA[Gnome]]></category> <guid
isPermaLink="false">http://euyuil.com/?p=3317</guid> <description><![CDATA[曾经我写过一篇文章，说怎样在 Arch Linux 里搭建一个个人的 Git 服务器。当时我以为，在 GDM 的配置文件里写上 Exclude=git 就可以把 git 用户排除在登录界面上，其实这样是错误的。 后来我上网时发现有人说，如果把用户的 ID 改成 1000 以内的数字，就可以在 GDM 中自动隐藏这个用户。 更改用户 ID 可以用以下命令： # usermod --uid 998 git 这样，git 用户的 ID 就会变成 998 了。 经过实际测试，git 用户确实不在登录管理器上显示了。 原创文章，转载请注明来源：http://euyuil.com/3317/how-to-hide-user-gnome-3-gdm/]]></description> <content:encoded><![CDATA[<p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">曾经我写过<a
href="http://euyuil.com/3286/ssh-git-server-on-linux/"  title="在 Linux 上搭建 SSH Git 服务器"  target="_blank" >一篇文章</a>，说怎样在 Arch Linux 里搭建一个个人的 Git 服务器。当时我以为，在 GDM 的配置文件里写上 Exclude=git 就可以把 git 用户排除在登录界面上，其实这样是错误的。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">后来我上网时发现有人说，如果把用户的 ID 改成 1000 以内的数字，就可以在 GDM 中自动隐藏这个用户。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><span
id="more-3317" ></span></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">更改用户 ID 可以用以下命令：</p><pre  style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;">
# usermod --uid 998 git
</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">这样，git 用户的 ID 就会变成 998 了。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">经过实际测试，git 用户确实不在登录管理器上显示了。<div
style="margin-top:15px;" ><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><strong>原创文章，转载请注明来源：</strong><a
href="http://euyuil.com/3317/how-to-hide-user-gnome-3-gdm/" >http://euyuil.com/3317/how-to-hide-user-gnome-3-gdm/</a></p></div> ]]></content:encoded> <wfw:commentRss>http://euyuil.com/3317/how-to-hide-user-gnome-3-gdm/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>在 Linux 上搭建 SSH Git 服务器</title><link>http://euyuil.com/3286/ssh-git-server-on-linux/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ssh-git-server-on-linux</link> <comments>http://euyuil.com/3286/ssh-git-server-on-linux/#comments</comments> <pubDate>Sat, 17 Mar 2012 12:35:36 +0000</pubDate> <dc:creator>EUYUIL</dc:creator> <category><![CDATA[无类可分]]></category> <category><![CDATA[Arch Linux]]></category> <category><![CDATA[Git]]></category> <category><![CDATA[SSH]]></category> <category><![CDATA[搭建]]></category> <category><![CDATA[版本控制]]></category> <category><![CDATA[配置]]></category> <guid
isPermaLink="false">http://euyuil.com/?p=3286</guid> <description><![CDATA[最近各种项目，而且很多是小团队合作的，所以免不了要弄版本控制。最近比较主流的版本控制工具还是 Git, 所以我就打算在 Arch Linux 下搭建一个 SSH 的 Git 服务器。 服务器上搭建 Git 首先服务器上得有 Git 和 SSH Server 吧。在 Arch Linux 上安装这两个软件： ~ # pacman -S git sshd 在服务器上创建 Git 的专有账户： ~ # useradd git 再去 /etc/passwd 里把 git 账号的 /bin/bash 改成 /usr/bin/git-shell , 这样的话，别人就只能通过这个账号进行 Git 操作，而不能使用命令行。 如果你发现在 GDM 的启动画面上多了个 git 账号不美观的话，去 /etc/gdm/custom.conf 里修改，在 [greeter] 下添加一些东西： [...]]]></description> <content:encoded><![CDATA[<p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">最近各种项目，而且很多是小团队合作的，所以免不了要弄版本控制。最近比较主流的版本控制工具还是 Git, 所以我就打算在 Arch Linux 下搭建一个 SSH 的 Git 服务器。</p><h2>服务器上搭建 Git</h2><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">首先服务器上得有 Git 和 SSH Server 吧。在 Arch Linux 上安装这两个软件：</p><pre  style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;"><span style="color: #999999;" >~ #</span> pacman -S git sshd</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">在服务器上创建 Git 的专有账户：</p><pre  style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;"><span style="color: #999999;" >~ #</span> useradd git</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">再去 <span
style="font-family: 'courier new', courier;" >/etc/passwd</span> 里把 git 账号的 <span
style="font-family: 'courier new', courier;" >/bin/bash</span> 改成 <span
style="font-family: 'courier new', courier;" >/usr/bin/git-shell</span> , 这样的话，别人就只能通过这个账号进行 Git 操作，而不能使用命令行。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><span
id="more-3286" ></span></p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">如果你发现在 GDM 的启动画面上多了个 git 账号不美观的话，去 <span
style="font-family: 'courier new', courier;" >/etc/gdm/custom.conf</span> 里修改，在 <span
style="font-family: 'courier new', courier;" >[greeter]</span> 下添加一些东西：</p><pre  style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;">[greeter]
Exclude=git</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">网上还有说，要在 <span
style="font-family: 'courier new', courier;" >/etc/ssh/sshd_config</span> 下设置以下参数（反正我是没有设置也成功了）：</p><pre  style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;">RSAAuthentication yes
PubkeyAuthentication yes</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">然后服务器端就<strong>基本上</strong>搭建好了，对，基本上好了。这时可以在 git 用户的 <span
style="font-family: 'courier new', courier;" >home</span> 文件夹下建立一些仓库什么的，然后打开 SSH Daemon 什么的：</p><pre  style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;"><span style="color: #999999;" >~ #</span> /etc/rc.d/sshd start</pre><h2>客户端上使用 Git</h2><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">客户端我试过两种，分别是 Windows 和 Linux 客户端。不过大体上来说，每添加一个客户端，主要要做的事情是生成公钥和私钥，然后把公钥给服务器。</p><h3>Windows 客户端上使用 Git</h3><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">Windows 上我使用 TortoiseGit 作为资源管理器的一个插件。然后用 PuTTYgen 生成公钥和私钥，这个工具是 PuTTY 里的，但是如果你用默认安装 TortoiseGit 的话，也会有它。用 PuTTYgen 生成<strong>公钥/私钥对</strong>（如下图所示，点击 Generate 按钮）：</p><div
id="attachment_3288"  class="wp-caption aligncenter"     style="width: 503pxwidth: 503pxmargin-left:auto;margin-right:auto;display:block;margin-left:auto;margin-right:auto;display:block;"><a
href="http://uploads.euyuil.com/2012/03/putty-key-generator-before.png" ><img
class="size-full wp-image-3288"  title="PuTTY Key Generator 生成公钥/私钥对"  src="http://uploads.euyuil.com/2012/03/putty-key-generator-before.png"  alt="PuTTY Key Generator 生成公钥/私钥对"  width="493"  height="477" /></a><p
class="wp-caption-text"     style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;text-indent:0;text-indent:0;">PuTTY Key Generator 生成公钥/私钥对</p></div><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">然后按照程序给的指示，在空白处随便移动一下鼠标。之后，便产生了公钥/私钥对：</p><div
id="attachment_3289"  class="wp-caption aligncenter"     style="width: 503pxwidth: 503pxmargin-left:auto;margin-right:auto;display:block;margin-left:auto;margin-right:auto;display:block;"><a
href="http://uploads.euyuil.com/2012/03/putty-key-generator-after.png" ><img
class="size-full wp-image-3289"  title="PuTTY Key Generator 生成公钥/密钥对后"  src="http://uploads.euyuil.com/2012/03/putty-key-generator-after.png"  alt="PuTTY Key Generator 生成公钥/密钥对后"  width="493"  height="477" /></a><p
class="wp-caption-text"     style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;text-indent:0;text-indent:0;">PuTTY Key Generator 生成公钥/密钥对后</p></div><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">接下来把 Key Comment 和 Key Passphrase 设置一下，分别导出公钥和私钥就可以了（点击 Save Public Key 和 Save Private Key）。</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">之后把私钥保留，公钥发给服务器（假设命名为 <span
style="font-family: 'courier new', courier;" >id_rsa.pub</span>），在服务器的 <strong>git 用户</strong>的文件夹下创建 <span
style="font-family: 'courier new', courier;" >.ssh/authorized_keys</span> 文件，里面保存客户端的公钥。如果有多个客户端，只需在后面追加就可以了：</p><pre  style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;">~ $ cat id_rsa.pub &gt;&gt; ~/.ssh/authorized_keys
~ $ chmod 644 ~/.ssh/authorized_keys</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">（所以说其实服务器的设置只是“基本上完成了”。）</p><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">在此后的 TortoiseGit 操作中，只需要指定刚才生成的私钥，就可以将源代码同步到服务器了。在写地址的时候，我是使用 <span
style="font-family: 'courier new', courier;" >ssh://git@gitserver/~/project_name</span> 这样的格式，看得出来我把 Git 项目的仓库都放到了 git 用户的 <span
style="font-family: 'courier new', courier;" >home</span> 文件夹下。</p><h3>Linux 客户端使用 Git</h3><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">Linux 的话，简单说下吧。用 OpenSSH 中的 <span
style="font-family: 'courier new', courier;" >ssh-keygen</span> 工具生成公钥/私钥对，然后把公钥扔给服务器，与 Windows 类似：</p><pre  style="padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono'padding:.5em 1em;border:solid 1px #9f9f9f;background:#f1f1f1;margin-left:1em;font-family:'Yahei Mono''Yahei Consolas Hybrid''Yahei Consolas Hybrid'ConsolasConsolas'Courier New''Courier New'monospace;monospace;"><span style="color: #999999;" >~ $</span> ssh-keygen -C "your-key-comment" -t rsa</pre><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;">一路选择默认值，最后会在当前用户的 <span
style="font-family: 'courier new', courier;" >home</span> 文件夹下生成 <span
style="font-family: 'courier new', courier;" >.ssh/id_rsa</span> 和 <span
style="font-family: 'courier new', courier;" >.ssh/id_rsa.pub</span> 文件。那个带 <span
style="font-family: 'courier new', courier;" >.pub</span> 的文件，就是公钥，在服务器上把公钥加入 <span
style="font-family: 'courier new', courier;" >authorized_keys</span> 文件中（步骤见本文 Windows 节）。之后就正常使用 Git 就可以了，远程代码仓库见 Windows 中的设置。<div
style="margin-top:15px;" ><p
style="margin:0;padding:0;line-height:1.75em;text-indent:2em;margin:0;padding:0;line-height:1.75em;text-indent:2em;"><strong>原创文章，转载请注明来源：</strong><a
href="http://euyuil.com/3286/ssh-git-server-on-linux/" >http://euyuil.com/3286/ssh-git-server-on-linux/</a></p></div> ]]></content:encoded> <wfw:commentRss>http://euyuil.com/3286/ssh-git-server-on-linux/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
