﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-新的征程，无惧的迈步-随笔分类-algorithm</title><link>http://www.cppblog.com/cdy20/category/6113.html</link><description>勇敢.坚毅.智慧</description><language>zh-cn</language><lastBuildDate>Wed, 02 Nov 2011 16:17:47 GMT</lastBuildDate><pubDate>Wed, 02 Nov 2011 16:17:47 GMT</pubDate><ttl>60</ttl><item><title>zlib算法（暂存，压缩解压）</title><link>http://www.cppblog.com/cdy20/archive/2011/01/21/139043.html</link><dc:creator>蔡东赟</dc:creator><author>蔡东赟</author><pubDate>Fri, 21 Jan 2011 09:11:00 GMT</pubDate><guid>http://www.cppblog.com/cdy20/archive/2011/01/21/139043.html</guid><wfw:comment>http://www.cppblog.com/cdy20/comments/139043.html</wfw:comment><comments>http://www.cppblog.com/cdy20/archive/2011/01/21/139043.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cdy20/comments/commentRss/139043.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cdy20/services/trackbacks/139043.html</trackback:ping><description><![CDATA[<p>1. Compression algorithm (deflate)</p>
<p>The deflation algorithm used by gzip (also zip and zlib) is a variation of<br>LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in<br>the input data.&nbsp; The second occurrence of a string is replaced by a<br>pointer to the previous string, in the form of a pair (distance,<br>length).&nbsp; Distances are limited to 32K bytes, and lengths are limited<br>to 258 bytes. When a string does not occur anywhere in the previous<br>32K bytes, it is emitted as a sequence of literal bytes.&nbsp; (In this<br>description, `string' must be taken as an arbitrary sequence of bytes,<br>and is not restricted to printable characters.)</p>
<p>Literals or match lengths are compressed with one Huffman tree, and<br>match distances are compressed with another tree. The trees are stored<br>in a compact form at the start of each block. The blocks can have any<br>size (except that the compressed data for one block must fit in<br>available memory). A block is terminated when deflate() determines that<br>it would be useful to start another block with fresh trees. (This is<br>somewhat similar to the behavior of LZW-based _compress_.)</p>
<p>Duplicated strings are found using a hash table. All input strings of<br>length 3 are inserted in the hash table. A hash index is computed for<br>the next 3 bytes. If the hash chain for this index is not empty, all<br>strings in the chain are compared with the current input string, and<br>the longest match is selected.</p>
<p>The hash chains are searched starting with the most recent strings, to<br>favor small distances and thus take advantage of the Huffman encoding.<br>The hash chains are singly linked. There are no deletions from the<br>hash chains, the algorithm simply discards matches that are too old.</p>
<p>To avoid a worst-case situation, very long hash chains are arbitrarily<br>truncated at a certain length, determined by a runtime option (level<br>parameter of deflateInit). So deflate() does not always find the longest<br>possible match but generally finds a match which is long enough.</p>
<p>deflate() also defers the selection of matches with a lazy evaluation<br>mechanism. After a match of length N has been found, deflate() searches for<br>a longer match at the next input byte. If a longer match is found, the<br>previous match is truncated to a length of one (thus producing a single<br>literal byte) and the process of lazy evaluation begins again. Otherwise,<br>the original match is kept, and the next match search is attempted only N<br>steps later.</p>
<p>The lazy match evaluation is also subject to a runtime parameter. If<br>the current match is long enough, deflate() reduces the search for a longer<br>match, thus speeding up the whole process. If compression ratio is more<br>important than speed, deflate() attempts a complete second search even if<br>the first match is already long enough.</p>
<p>The lazy match evaluation is not performed for the fastest compression<br>modes (level parameter 1 to 3). For these fast modes, new strings<br>are inserted in the hash table only when no match was found, or<br>when the match is not too long. This degrades the compression ratio<br>but saves time since there are both fewer insertions and fewer searches.</p>
<p><br>2. Decompression algorithm (inflate)</p>
<p>2.1 Introduction</p>
<p>The key question is how to represent a Huffman code (or any prefix code) so<br>that you can decode fast.&nbsp; The most important characteristic is that shorter<br>codes are much more common than longer codes, so pay attention to decoding the<br>short codes fast, and let the long codes take longer to decode.</p>
<p>inflate() sets up a first level table that covers some number of bits of<br>input less than the length of longest code.&nbsp; It gets that many bits from the<br>stream, and looks it up in the table.&nbsp; The table will tell if the next<br>code is that many bits or less and how many, and if it is, it will tell<br>the value, else it will point to the next level table for which inflate()<br>grabs more bits and tries to decode a longer code.</p>
<p>How many bits to make the first lookup is a tradeoff between the time it<br>takes to decode and the time it takes to build the table.&nbsp; If building the<br>table took no time (and if you had infinite memory), then there would only<br>be a first level table to cover all the way to the longest code.&nbsp; However,<br>building the table ends up taking a lot longer for more bits since short<br>codes are replicated many times in such a table.&nbsp; What inflate() does is<br>simply to make the number of bits in the first table a variable, and&nbsp; then<br>to set that variable for the maximum speed.</p>
<p>For inflate, which has 286 possible codes for the literal/length tree, the size<br>of the first table is nine bits.&nbsp; Also the distance trees have 30 possible<br>values, and the size of the first table is six bits.&nbsp; Note that for each of<br>those cases, the table ended up one bit longer than the ``average'' code<br>length, i.e. the code length of an approximately flat code which would be a<br>little more than eight bits for 286 symbols and a little less than five bits<br>for 30 symbols.</p>
<p><br>2.2 More details on the inflate table lookup</p>
<p>Ok, you want to know what this cleverly obfuscated inflate tree actually<br>looks like.&nbsp; You are correct that it's not a Huffman tree.&nbsp; It is simply a<br>lookup table for the first, let's say, nine bits of a Huffman symbol.&nbsp; The<br>symbol could be as short as one bit or as long as 15 bits.&nbsp; If a particular<br>symbol is shorter than nine bits, then that symbol's translation is duplicated<br>in all those entries that start with that symbol's bits.&nbsp; For example, if the<br>symbol is four bits, then it's duplicated 32 times in a nine-bit table.&nbsp; If a<br>symbol is nine bits long, it appears in the table once.</p>
<p>If the symbol is longer than nine bits, then that entry in the table points<br>to another similar table for the remaining bits.&nbsp; Again, there are duplicated<br>entries as needed.&nbsp; The idea is that most of the time the symbol will be short<br>and there will only be one table look up.&nbsp; (That's whole idea behind data<br>compression in the first place.)&nbsp; For the less frequent long symbols, there<br>will be two lookups.&nbsp; If you had a compression method with really long<br>symbols, you could have as many levels of lookups as is efficient.&nbsp; For<br>inflate, two is enough.</p>
<p>So a table entry either points to another table (in which case nine bits in<br>the above example are gobbled), or it contains the translation for the symbol<br>and the number of bits to gobble.&nbsp; Then you start again with the next<br>ungobbled bit.</p>
<p>You may wonder: why not just have one lookup table for how ever many bits the<br>longest symbol is?&nbsp; The reason is that if you do that, you end up spending<br>more time filling in duplicate symbol entries than you do actually decoding.<br>At least for deflate's output that generates new trees every several 10's of<br>kbytes.&nbsp; You can imagine that filling in a 2^15 entry table for a 15-bit code<br>would take too long if you're only decoding several thousand symbols.&nbsp; At the<br>other extreme, you could make a new table for every bit in the code.&nbsp; In fact,<br>that's essentially a Huffman tree.&nbsp; But then you spend two much time<br>traversing the tree while decoding, even for short symbols.</p>
<p>So the number of bits for the first lookup table is a trade of the time to<br>fill out the table vs. the time spent looking at the second level and above of<br>the table.</p>
<p>Here is an example, scaled down:</p>
<p>The code being decoded, with 10 symbols, from 1 to 6 bits long:</p>
<p>A: 0<br>B: 10<br>C: 1100<br>D: 11010<br>E: 11011<br>F: 11100<br>G: 11101<br>H: 11110<br>I: 111110<br>J: 111111</p>
<p>Let's make the first table three bits long (eight entries):</p>
<p>000: A,1<br>001: A,1<br>010: A,1<br>011: A,1<br>100: B,2<br>101: B,2<br>110: -&gt; table X (gobble 3 bits)<br>111: -&gt; table Y (gobble 3 bits)</p>
<p>Each entry is what the bits decode as and how many bits that is, i.e. how<br>many bits to gobble.&nbsp; Or the entry points to another table, with the number of<br>bits to gobble implicit in the size of the table.</p>
<p>Table X is two bits long since the longest code starting with 110 is five bits<br>long:</p>
<p>00: C,1<br>01: C,1<br>10: D,2<br>11: E,2</p>
<p>Table Y is three bits long since the longest code starting with 111 is six<br>bits long:</p>
<p>000: F,2<br>001: F,2<br>010: G,2<br>011: G,2<br>100: H,2<br>101: H,2<br>110: I,3<br>111: J,3</p>
<p>So what we have here are three tables with a total of 20 entries that had to<br>be constructed.&nbsp; That's compared to 64 entries for a single table.&nbsp; Or<br>compared to 16 entries for a Huffman tree (six two entry tables and one four<br>entry table).&nbsp; Assuming that the code ideally represents the probability of<br>the symbols, it takes on the average 1.25 lookups per symbol.&nbsp; That's compared<br>to one lookup for the single table, or 1.66 lookups per symbol for the<br>Huffman tree.</p>
<p>There, I think that gives you a picture of what's going on.&nbsp; For inflate, the<br>meaning of a particular symbol is often more than just a letter.&nbsp; It can be a<br>byte (a "literal"), or it can be either a length or a distance which<br>indicates a base value and a number of bits to fetch after the code that is<br>added to the base value.&nbsp; Or it might be the special end-of-block code.&nbsp; The<br>data structures created in inftrees.c try to encode all that information<br>compactly in the tables.</p>
<p><br>Jean-loup Gailly&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mark Adler<br><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#106;&#108;&#111;&#117;&#112;&#64;&#103;&#122;&#105;&#112;&#46;&#111;&#114;&#103;">jloup@gzip.org</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#109;&#97;&#100;&#108;&#101;&#114;&#64;&#97;&#108;&#117;&#109;&#110;&#105;&#46;&#99;&#97;&#108;&#116;&#101;&#99;&#104;&#46;&#101;&#100;&#117;">madler@alumni.caltech.edu</a></p>
<p><br>References:</p>
<p>[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data<br>Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,<br>pp. 337-343.</p>
<p>``DEFLATE Compressed Data Format Specification'' available in<br><a href="http://www.ietf.org/rfc/rfc1951.txt">http://www.ietf.org/rfc/rfc1951.txt</a><br></p>
<img src ="http://www.cppblog.com/cdy20/aggbug/139043.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cdy20/" target="_blank">蔡东赟</a> 2011-01-21 17:11 <a href="http://www.cppblog.com/cdy20/archive/2011/01/21/139043.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>晒掉论文《BP神经网络的异常点检测应用可行性研究》</title><link>http://www.cppblog.com/cdy20/archive/2010/06/17/118048.html</link><dc:creator>蔡东赟</dc:creator><author>蔡东赟</author><pubDate>Thu, 17 Jun 2010 00:50:00 GMT</pubDate><guid>http://www.cppblog.com/cdy20/archive/2010/06/17/118048.html</guid><wfw:comment>http://www.cppblog.com/cdy20/comments/118048.html</wfw:comment><comments>http://www.cppblog.com/cdy20/archive/2010/06/17/118048.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.cppblog.com/cdy20/comments/commentRss/118048.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cdy20/services/trackbacks/118048.html</trackback:ping><description><![CDATA[<strong>想了几个月。<br />捣鼓了十多天实验，和分析搞出来的。BP神经网络的异常点检测应用可行性研究<br />这就是我杯具的毕业设计。<br /><br />在这些日子，积压的 还有 一切的一切，我失去了你。<br /></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><a href="http://www.cppblog.com/Files/cdy20/2.4.rar">http://www.cppblog.com/Files/cdy20/2.4.rar</a><br /><br /><br /><a href="http://www.cppblog.com/Files/cdy20/2.4.rar"><br /><span style="font-family: '黑体'; font-size: 22pt; font-weight: bold; mso-spacerun: 'yes'">
<p style="text-align: center; line-height: 150%; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '黑体'; font-size: 16pt; font-weight: bold; mso-spacerun: 'yes'">摘</span><span style="font-family: '黑体'; font-size: 16pt; font-weight: bold; mso-spacerun: 'yes'">&nbsp;&nbsp;</span><span style="font-family: '黑体'; font-size: 16pt; font-weight: bold; mso-spacerun: 'yes'">要</span><span style="font-family: '黑体'; font-size: 16pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: center; line-height: 150%; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '黑体'; font-size: 16pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: left; line-height: 150%; margin-top: 0pt; text-indent: 21pt; layout-grid-mode: char; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">异常点数据是指数据集中与众不同数据。这部分数据的量小，但是对于我们的日常生产生活的影响极大。因此，异常点检测被广泛应用于网络入侵检测，金融保险，天气预报以及新药研制等领域。相对于大量的正常数据挖掘而言，异常点检测被称作小模式数据挖掘。BP算法是一种常用的数据挖掘算法。但是BP算法进行实际数据的异常点数据挖掘过程中存在：实际数据的维数较高，存在冗余特征的干扰，以及在高维特征下，数据量不充分的问题。因此，本文分析BP神经网络处理各种数据的情况，并得到以下结果。（1）BP神经网络能够较好的分离特征单一的仿真数据；但是（2）特征相似性较大的数据集，难以分离判断；（3）正常数据不充分或者不具有代表性，因此正常数据类学习不充分，从而导致异常无法判断。针对以上问题，本文提出了以下的改进措施：（1）BP算法前进行特征约简（映射）从中选取有益于异常检测的特征（2）多神经网络融合，不同神经网络识别不同的特征，相互取长补短，融合后得到最终的结果。</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: left; line-height: 150%; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: left; line-height: 150%; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: left; line-height: 150%; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: left; line-height: 150%; margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt; margin-left: 21pt" class="p0"><span style="font-family: '黑体'; font-size: 14pt; font-weight: bold; mso-spacerun: 'yes'">关键字</span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'">：异常，<font face="Times New Roman">BP</font><font face="宋体">，异常点检测，神经网络</font></span><span style="font-family: '宋体'; font-size: 12pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p style="text-align: center; line-height: 150%; margin-top: 0pt; margin-bottom: 0pt" class="p0" align="left"><!--endfragment--><br /></p>
</span></a><br /><br /><br />引用论文注明出处。妈的国内还没有一个人做，国外tmd都是聚类，神经网络只是辅助 <br /><br /><br /><br />add&nbsp; ps：你们反应也太激烈了吧！吓死我。祝大家工作生活顺利！~<img src ="http://www.cppblog.com/cdy20/aggbug/118048.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cdy20/" target="_blank">蔡东赟</a> 2010-06-17 08:50 <a href="http://www.cppblog.com/cdy20/archive/2010/06/17/118048.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>O(n)时间O(1)辅助空间，循环移位</title><link>http://www.cppblog.com/cdy20/archive/2009/11/26/101964.html</link><dc:creator>蔡东赟</dc:creator><author>蔡东赟</author><pubDate>Thu, 26 Nov 2009 04:40:00 GMT</pubDate><guid>http://www.cppblog.com/cdy20/archive/2009/11/26/101964.html</guid><wfw:comment>http://www.cppblog.com/cdy20/comments/101964.html</wfw:comment><comments>http://www.cppblog.com/cdy20/archive/2009/11/26/101964.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/cdy20/comments/commentRss/101964.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cdy20/services/trackbacks/101964.html</trackback:ping><description><![CDATA[O(n)时间O(1)辅助空间，循环移位<br><br><br>这一道，google的笔试题，网易也用过，学校的数据结构题目系统也有，之前我都是卡着机器出的<br><br>现在整理一下<br><br>一 3次翻转做法<br>/*about 循环移位<br>实例：abcdefgh 向左循环移位3位<br>&nbsp;&nbsp;&nbsp;&nbsp; 结果 defghabc<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.abc做翻转&nbsp;<span style="COLOR: red"> cba</span> defgh<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 defgh做翻转&nbsp; cba&nbsp; <span style="COLOR: red">hgfed<br></span>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.第二结果全部在做翻转&nbsp;&nbsp;&nbsp; 成为&nbsp; <span style="COLOR: red">defghabc&nbsp;</span>&nbsp;&nbsp; <br>*/<br><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">template</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;reverse(T&nbsp;a[],</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j)<br><img id=Codehighlighter1_50_150_Open_Image onclick="this.style.display='none'; Codehighlighter1_50_150_Open_Text.style.display='none'; Codehighlighter1_50_150_Closed_Image.style.display='inline'; Codehighlighter1_50_150_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_50_150_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_50_150_Closed_Text.style.display='none'; Codehighlighter1_50_150_Open_Image.style.display='inline'; Codehighlighter1_50_150_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_50_150_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_50_150_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;j)<br><img id=Codehighlighter1_75_148_Open_Image onclick="this.style.display='none'; Codehighlighter1_75_148_Open_Text.style.display='none'; Codehighlighter1_75_148_Closed_Image.style.display='inline'; Codehighlighter1_75_148_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_75_148_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_75_148_Closed_Text.style.display='none'; Codehighlighter1_75_148_Open_Image.style.display='inline'; Codehighlighter1_75_148_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_75_148_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_75_148_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap(a[i],a[j]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">j;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>template</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;exch1(T&nbsp;a[],</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;k)<br><img id=Codehighlighter1_202_273_Open_Image style="DISPLAY: inline" onclick="this.style.display='none'; Codehighlighter1_202_273_Open_Text.style.display='none'; Codehighlighter1_202_273_Closed_Image.style.display='inline'; Codehighlighter1_202_273_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_202_273_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_202_273_Closed_Text.style.display='none'; Codehighlighter1_202_273_Open_Image.style.display='inline'; Codehighlighter1_202_273_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_202_273_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_202_273_Open_Text style="DISPLAY: inline"><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reverse(a,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,k</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reverse(a,k,n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reverse(a,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span></div>
<br>&nbsp;&nbsp;&nbsp;&nbsp; reverse(a,0,k-1); //&nbsp; k/2<br>&nbsp;&nbsp;&nbsp;&nbsp; reverse(a,k,n-1); // (n-k)/2<br>&nbsp;&nbsp;&nbsp;&nbsp; reverse(a,0,n-1); //&nbsp; n/2<br>&nbsp;为 k/2+(n-k)/2+k/2=n/2 + n/2&nbsp; = n<br><br><br>二 ...<br><br><br>
<img src ="http://www.cppblog.com/cdy20/aggbug/101964.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cdy20/" target="_blank">蔡东赟</a> 2009-11-26 12:40 <a href="http://www.cppblog.com/cdy20/archive/2009/11/26/101964.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>求素数时间测试</title><link>http://www.cppblog.com/cdy20/archive/2009/09/22/96913.html</link><dc:creator>蔡东赟</dc:creator><author>蔡东赟</author><pubDate>Tue, 22 Sep 2009 02:38:00 GMT</pubDate><guid>http://www.cppblog.com/cdy20/archive/2009/09/22/96913.html</guid><wfw:comment>http://www.cppblog.com/cdy20/comments/96913.html</wfw:comment><comments>http://www.cppblog.com/cdy20/archive/2009/09/22/96913.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.cppblog.com/cdy20/comments/commentRss/96913.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cdy20/services/trackbacks/96913.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/cdy20/archive/2009/09/22/96913.html'>阅读全文</a><img src ="http://www.cppblog.com/cdy20/aggbug/96913.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cdy20/" target="_blank">蔡东赟</a> 2009-09-22 10:38 <a href="http://www.cppblog.com/cdy20/archive/2009/09/22/96913.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> hdu  Northcott Game  尼姆博奕 (Nimm Game) </title><link>http://www.cppblog.com/cdy20/archive/2009/04/23/80816.html</link><dc:creator>蔡东赟</dc:creator><author>蔡东赟</author><pubDate>Thu, 23 Apr 2009 02:56:00 GMT</pubDate><guid>http://www.cppblog.com/cdy20/archive/2009/04/23/80816.html</guid><wfw:comment>http://www.cppblog.com/cdy20/comments/80816.html</wfw:comment><comments>http://www.cppblog.com/cdy20/archive/2009/04/23/80816.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cdy20/comments/commentRss/80816.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cdy20/services/trackbacks/80816.html</trackback:ping><description><![CDATA[<p>昨晚热身，a了个背包，tle了搜索（好久没练的），剩下的队友出，早上出了博弈的<br><br></p>
<h1>Northcott Game </h1>
<h5>Time Limit : 1000/1000ms (Java/Other)&nbsp;&nbsp;&nbsp;Memory Limit : 32768/32768K (Java/Other)</h5>
<h5>Total Submission(s) : 11&nbsp;&nbsp;&nbsp;Accepted Submission(s) : 3</h5>
<h4>Font: <span onclick="ProFont('Times New Roman')">Times New Roman</span> | <span onclick="ProFont('Verdana')">Verdana</span> | <span onclick="ProFont('Georgia')">Georgia</span> </h4>
<h4>Font Size: <span onclick=ProFontAdd(-1)>&#8592;</span> <span onclick=ProFontAdd(1)>&#8594;</span></h4>
<h3 onclick="ObjFolder('procon')">Problem Description</h3>
<div id=procon>　　Tom和Jerry正在玩一种Northcott游戏，可是Tom老是输，因此他怀疑这个游戏是不是有某种必胜策略，郁闷的Tom现在向你求救了，你能帮帮他么？<br>游戏规则是这样的：<br>　　如图所示，游戏在一个n行m列（1 &#8804; n &#8804; 1000且2 &#8804; m &#8804; 100）的棋盘上进行，每行有一个黑子（黑方）和一个白子（白方）。执黑的一方先行，每次玩家可以移动己方的任何一枚棋子到同一行的任何一个空格上，当然这过程中不许越过该行的敌方棋子。双方轮流移动，直到某一方无法行动为止，移动最后一步的玩家获胜。Tom总是先下（黑方）。图1是某个初始局面，图二是Tom移动一个棋子后的局面（第一行的黑子左移两步）。<br><br>
<center><img src="http://acm.hdu.edu.cn/data/images/C63-1003-1.png"><br><br>图1</center><br><br>
<center><img src="http://acm.hdu.edu.cn/data/images/C63-1003-2.png"><br><br>图2</center><br></div>
<h3 onclick="ObjFolder('proinput')">Input</h3>
<div id=proinput>　　输入数据有多组。每组数据第一行为两个整数n和m，由空格分开。接下来有n行，每行两个数Ti，Ji (1 &#8804; Ti, Ji &#8804; m)分别表示Tom和Jerry在该行棋子所处的列数。<br>　　<strong>注意：各组测试数据之间有不定数量的空行。你必须处理到文件末。</strong><br></div>
<h3 onclick="ObjFolder('prooutput')">Output</h3>
<div id=prooutput>对于每组测试数据输出一行你的结果。如果当前局面下Tom有必胜策略则输出&#8220;I WIN!&#8221;，否则输出&#8220;BAD LUCK!&#8221;。 </div>
<h3 onclick="ObjFolder('prosamplein')">Sample Input</h3>
<div id=prosamplein>
<pre>3 6
4 5
1 2
1 2
3 6
4 5
1 3
1 2
</pre>
</div>
<h3 onclick="ObjFolder('prosampleout')">Sample Output</h3>
<div id=prosampleout>
<pre>BAD LUCK!
I WIN!
</pre>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img id=Codehighlighter1_1_586_Open_Image onclick="this.style.display='none'; Codehighlighter1_1_586_Open_Text.style.display='none'; Codehighlighter1_1_586_Closed_Image.style.display='inline'; Codehighlighter1_1_586_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1_586_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1_586_Closed_Text.style.display='none'; Codehighlighter1_1_586_Open_Image.style.display='inline'; Codehighlighter1_1_586_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="COLOR: #000000">&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1_586_Closed_Text>/**/</span><span id=Codehighlighter1_1_586_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;尼姆博奕(Nimm&nbsp;Game):<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">有三堆各若干个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取一个,多者不限,最后取光者得胜.<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">这种情况最有意思,它与二进制有密切关系,我们用(a,b,c)表示某种局势,首先(0,0,0)显然是奇异局势,无论谁面对奇异局势,都必然失败.第二种奇异局势是(0,n,n),只要与对手拿走一样多的物品,最后都将导致(0,0,0).仔细分析一下,(1,2,3)也是奇异局势,无论对手如何拿,接下来都可以变为(0,n,n)的情形.<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">计算机算法里面有一种叫做按位模2加,也叫做异或的运算,我们用符号(+)表示这种运算.这种运算和一般加法不同的一点是1+1=0.先看(1,2,3)的按位模2加的结果：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">1&nbsp;=二进制01<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">2&nbsp;=二进制10<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">3&nbsp;=二进制11&nbsp;(+)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">-------<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">0&nbsp;=二进制00&nbsp;(注意不进位)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">对于奇异局势(0,n,n)也一样,结果也是0.<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">任何奇异局势(a,b,c)都有a(+)b(+)c&nbsp;=0.<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">如果我们面对的是一个非奇异局势(a,b,c),要如何变为奇异局势呢？假设&nbsp;a&nbsp;&lt;&nbsp;b&lt;&nbsp;c,我们只要将&nbsp;c&nbsp;变为&nbsp;a(+)b,即可,因为有如下的运算结果:&nbsp;a(+)b(+)(a(+)b)=(a(+)a)(+)(b(+)b)=0(+)0=0.要将c&nbsp;变为a(+)b,只要从&nbsp;c中减去&nbsp;c-(a(+)b)即可.<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">&nbsp;</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;</span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;</span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;MAXN&nbsp;10001</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;an[MAXN];<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;Nimm_Game(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n)<br><img id=Codehighlighter1_688_798_Open_Image onclick="this.style.display='none'; Codehighlighter1_688_798_Open_Text.style.display='none'; Codehighlighter1_688_798_Closed_Image.style.display='inline'; Codehighlighter1_688_798_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_688_798_Closed_Image onclick="this.style.display='none'; Codehighlighter1_688_798_Closed_Text.style.display='none'; Codehighlighter1_688_798_Open_Image.style.display='inline'; Codehighlighter1_688_798_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif">&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_688_798_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_688_798_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;ans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img id=Codehighlighter1_740_777_Open_Image onclick="this.style.display='none'; Codehighlighter1_740_777_Open_Text.style.display='none'; Codehighlighter1_740_777_Closed_Image.style.display='inline'; Codehighlighter1_740_777_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_740_777_Closed_Image onclick="this.style.display='none'; Codehighlighter1_740_777_Closed_Text.style.display='none'; Codehighlighter1_740_777_Open_Image.style.display='inline'; Codehighlighter1_740_777_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i)</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_740_777_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_740_777_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans</span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000">an[i];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;ans;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;<br><img id=Codehighlighter1_812_1067_Open_Image onclick="this.style.display='none'; Codehighlighter1_812_1067_Open_Text.style.display='none'; Codehighlighter1_812_1067_Closed_Image.style.display='inline'; Codehighlighter1_812_1067_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_812_1067_Closed_Image onclick="this.style.display='none'; Codehighlighter1_812_1067_Closed_Text.style.display='none'; Codehighlighter1_812_1067_Open_Image.style.display='inline'; Codehighlighter1_812_1067_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_812_1067_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_812_1067_Open_Text><span style="COLOR: #000000">{&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,m,a,b;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">m)&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">EOF)&nbsp;<br><img id=Codehighlighter1_869_1052_Open_Image onclick="this.style.display='none'; Codehighlighter1_869_1052_Open_Text.style.display='none'; Codehighlighter1_869_1052_Closed_Image.style.display='inline'; Codehighlighter1_869_1052_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_869_1052_Closed_Image onclick="this.style.display='none'; Codehighlighter1_869_1052_Closed_Text.style.display='none'; Codehighlighter1_869_1052_Open_Image.style.display='inline'; Codehighlighter1_869_1052_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_869_1052_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_869_1052_Open_Text><span style="COLOR: #000000">{&nbsp;<br><img id=Codehighlighter1_895_971_Open_Image onclick="this.style.display='none'; Codehighlighter1_895_971_Open_Text.style.display='none'; Codehighlighter1_895_971_Closed_Image.style.display='inline'; Codehighlighter1_895_971_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_895_971_Closed_Image onclick="this.style.display='none'; Codehighlighter1_895_971_Closed_Text.style.display='none'; Codehighlighter1_895_971_Open_Image.style.display='inline'; Codehighlighter1_895_971_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i)</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_895_971_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_895_971_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;an[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">abs(a</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">b)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">Nimm_Game(n))&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">BAD&nbsp;LUCK!\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">I&nbsp;WIN!\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000">&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span></div>
</div>
<img src ="http://www.cppblog.com/cdy20/aggbug/80816.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cdy20/" target="_blank">蔡东赟</a> 2009-04-23 10:56 <a href="http://www.cppblog.com/cdy20/archive/2009/04/23/80816.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>威佐夫博奕(Wythoff Game)</title><link>http://www.cppblog.com/cdy20/archive/2009/04/18/80319.html</link><dc:creator>蔡东赟</dc:creator><author>蔡东赟</author><pubDate>Sat, 18 Apr 2009 01:57:00 GMT</pubDate><guid>http://www.cppblog.com/cdy20/archive/2009/04/18/80319.html</guid><wfw:comment>http://www.cppblog.com/cdy20/comments/80319.html</wfw:comment><comments>http://www.cppblog.com/cdy20/archive/2009/04/18/80319.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/cdy20/comments/commentRss/80319.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cdy20/services/trackbacks/80319.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/cdy20/archive/2009/04/18/80319.html'>阅读全文</a><img src ="http://www.cppblog.com/cdy20/aggbug/80319.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cdy20/" target="_blank">蔡东赟</a> 2009-04-18 09:57 <a href="http://www.cppblog.com/cdy20/archive/2009/04/18/80319.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> 图算法进度</title><link>http://www.cppblog.com/cdy20/archive/2008/10/26/65157.html</link><dc:creator>蔡东赟</dc:creator><author>蔡东赟</author><pubDate>Sun, 26 Oct 2008 15:33:00 GMT</pubDate><guid>http://www.cppblog.com/cdy20/archive/2008/10/26/65157.html</guid><wfw:comment>http://www.cppblog.com/cdy20/comments/65157.html</wfw:comment><comments>http://www.cppblog.com/cdy20/archive/2008/10/26/65157.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/cdy20/comments/commentRss/65157.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cdy20/services/trackbacks/65157.html</trackback:ping><description><![CDATA[<div>* 求有向图的强连通分支 (Strongerst Connected Component)(cut)</div>
<div>o Kosaraju算法&nbsp;&nbsp; <br></div>
<div>o Gabow算法</div>
<div>o Tarjan算法</div>
<div>* 求最小生成树 (Minimal Spanning Trees) (cut)<br></div>
<div>o Kruskal算法(cut边更新)</div>
<div>o Prim算法(cut点更新)</div>
<div>* 最短路径问题(cut)</div>
<div>o SSSP(Single-source Shortest Paths)</div>
<div>* Dijkstra算法&nbsp; (cut)<br></div>
<div>* Bellman-Ford算法(SPFA算法)(cut) </div>
<div>o APSP(All-pairs Shortest Paths)</div>
<div>* Floyd-Warshall算法(cut)</div>
<div>* Johnson算法</div>
<div>* 网络流问题 &nbsp;&nbsp;&nbsp;&nbsp; </div>
<div>o 最大网络流</div>
<div>* 增广路算法</div>
<div>* Ford-Fulkerson算法</div>
<div>* Edmonds-Karp算法</div>
<div>* Dinic</div>
<div>* 预流推进算法</div>
<div>o 最小费用流</div>
<div>* 图匹配问题&nbsp; （部分cut）<br></div>
<div>o 匈牙利算法(cut)</div>
<div>o Kuhn-Munkres算法<br></div>
<ul>
    <li style="BACKGROUND-COLOR: #fff780">o Edmonds' blossom-contraction 算法<br><br><br>&nbsp;次小生成树(K小生成树)<br>最小树形图<br>&nbsp;最小K限制度生成树<br>&nbsp;最优比率生成树(0-1分数规划)<br>第K最短路<br>LP问题以及Primal-Dual(单纯型法)<br>&nbsp;最大流(最短增广路、最高标号预流推进)<br>&nbsp;最小费用流(最小费用路、Primal-Dual算法)<br>&nbsp;二分图最优匹配(原始-对偶KM算法)<br></li>
</ul>
<p><br>acm.pku.edu.cn 的：<br><span style="COLOR: red">最小生成树&nbsp;&nbsp;<br>1251(cut)<br>&nbsp;<br>1258(cut)<br>&nbsp;<br>1789(cut)<br>&nbsp;<br>2485(cut)</span></p>
<p style="COLOR: red">最短路&nbsp;<br>&nbsp;<br>1062(cut 建模的时侯要注意 ，不断建符合等级差的图 做最短路径)<br>&nbsp;<br>1125（cut 做全源最短路<br>&nbsp;&nbsp; 再对以每各点为根的树：找最长的边 <br>&nbsp;再对每棵树的最长边 找最短的那一条&nbsp;&nbsp; <br>&nbsp;int ans=maxint;<br>&nbsp;&nbsp;&nbsp; for(i=1;i&lt;=n;i++){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmp=-1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(j=1;j&lt;=n;j++){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmp=max(tmp,a[i][j]);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(tmp &lt; ans){ans=tmp;val=i;}<br>&nbsp;&nbsp;&nbsp; }<br>）<br>&nbsp;<br>1797(cut<br>&nbsp;&nbsp;&nbsp; 起点到n点 路径上&nbsp; 所能承受的 最大重量的车<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; dist[k]&nbsp;&nbsp; 源点到k 路径中最小的那个边权值&nbsp;&nbsp; mat[k][i]边k-i权值&nbsp; <br>&nbsp;&nbsp; 取路径 dist[k]&nbsp; 和mat【k】【i】边最大那个&nbsp; 更新 dist[i]&nbsp; )<br>&nbsp;<br>2253(cut 要求的与 1797相反)</p>
<p style="COLOR: red"><br></p>
<p style="COLOR: red"><br></p>
<p style="COLOR: red"><br></p>
<p style="COLOR: red">
<meta content=Word.Document name=ProgId>
<meta content="Microsoft Word 11" name=Generator>
<meta content="Microsoft Word 11" name=Originator>
<link href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel=File-List><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:536871559 0 0 0 415 0;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
p
{mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:宋体;
mso-bidi-font-family:宋体;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style>
<p>Johnson算法适用于求All Pairs Shortest Path. Johnson算法应用了重标号技术，先进行一次Bellman-Ford算法，然后对原图进行重标号，w'(i,j)=h[i]-h[j]+w(i,j)。然后对每个点进行一次Dijkstra，每次Dijkstra的复杂度为O(nlogn+m)，于是算法复杂度为O(n^2logn+m)。</p>
<br>
<p>&#160;</p>
<img src ="http://www.cppblog.com/cdy20/aggbug/65157.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cdy20/" target="_blank">蔡东赟</a> 2008-10-26 23:33 <a href="http://www.cppblog.com/cdy20/archive/2008/10/26/65157.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>