﻿<?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++博客-心如止水-随笔分类-题目分类：递推/递归</title><link>http://www.cppblog.com/rakerichard/category/12749.html</link><description>Je n'ai pas le temps
</description><language>zh-cn</language><lastBuildDate>Thu, 01 Sep 2011 07:05:41 GMT</lastBuildDate><pubDate>Thu, 01 Sep 2011 07:05:41 GMT</pubDate><ttl>60</ttl><item><title>UVa 10202 Pairsumonious Numbers</title><link>http://www.cppblog.com/rakerichard/archive/2011/08/30/154675.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Tue, 30 Aug 2011 02:51:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2011/08/30/154675.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/154675.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2011/08/30/154675.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/154675.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/154675.html</trackback:ping><description><![CDATA[题解参见《算法艺术与信息学竞赛》。<br />以下是我的代码：<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">algorithm</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cstdio</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cstring</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br /></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 /></span><span style="color: #0000FF; ">const</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;kInf(</span><span style="color: #000000; ">0x7f7f7f7f</span><span style="color: #000000; ">);<br /><br /></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;main()<br />{<br />#ifndef&nbsp;ONLINE_JUDGE<br />&nbsp;&nbsp;&nbsp;&nbsp;freopen(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">data.in</span><span style="color: #000000; ">"</span><span style="color: #000000; ">,</span><span style="color: #000000; ">"</span><span style="color: #000000; ">r</span><span style="color: #000000; ">"</span><span style="color: #000000; ">,stdin);<br /></span><span style="color: #0000FF; ">#endif</span><span style="color: #000000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;n,m,r[</span><span style="color: #000000; ">315</span><span style="color: #000000; ">],a[</span><span style="color: #000000; ">15</span><span style="color: #000000; ">];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;t[</span><span style="color: #000000; ">315</span><span style="color: #000000; ">];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">bool</span><span style="color: #000000; ">&nbsp;found;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&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</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; ">==</span><span style="color: #000000; ">1</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m</span><span style="color: #000000; ">=</span><span style="color: #000000; ">n</span><span style="color: #000000; ">*</span><span style="color: #000000; ">(n</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">)</span><span style="color: #000000; ">/</span><span style="color: #000000; ">2</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&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; ">1</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">m;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">%d</span><span style="color: #000000; ">"</span><span style="color: #000000; ">,</span><span style="color: #000000; ">&amp;</span><span style="color: #000000; ">r[i]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(r</span><span style="color: #000000; ">+</span><span style="color: #000000; ">1</span><span style="color: #000000; ">,r</span><span style="color: #000000; ">+</span><span style="color: #000000; ">m</span><span style="color: #000000; ">+</span><span style="color: #000000; ">1</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;found</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">false</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&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;p</span><span style="color: #000000; ">=</span><span style="color: #000000; ">3</span><span style="color: #000000; ">;p</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">m&nbsp;</span><span style="color: #000000; ">&amp;&amp;</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">found;p</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">bool</span><span style="color: #000000; ">&nbsp;impossible(</span><span style="color: #0000FF; ">false</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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; ">1</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">n;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]</span><span style="color: #000000; ">=-</span><span style="color: #000000; ">kInf;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memcpy(t,r,</span><span style="color: #0000FF; ">sizeof</span><span style="color: #000000; ">(t));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">((t[</span><span style="color: #000000; ">1</span><span style="color: #000000; ">]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">t[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">]</span><span style="color: #000000; ">+</span><span style="color: #000000; ">t[p])</span><span style="color: #000000; ">%</span><span style="color: #000000; ">2</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">continue</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">((t[</span><span style="color: #000000; ">1</span><span style="color: #000000; ">]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">t[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">]</span><span style="color: #000000; ">+</span><span style="color: #000000; ">t[p])</span><span style="color: #000000; ">/</span><span style="color: #000000; ">2</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[</span><span style="color: #000000; ">1</span><span style="color: #000000; ">]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">t[</span><span style="color: #000000; ">1</span><span style="color: #000000; ">]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">a[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[</span><span style="color: #000000; ">3</span><span style="color: #000000; ">]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">t[p]</span><span style="color: #000000; ">-</span><span style="color: #000000; ">a[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t[</span><span style="color: #000000; ">1</span><span style="color: #000000; ">]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">t[</span><span style="color: #000000; ">2</span><span style="color: #000000; ">]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">t[p]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">kInf;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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; ">4</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">n;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;minv(kInf);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="color: #000000; ">=</span><span style="color: #000000; ">1</span><span style="color: #000000; ">;j</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">m;j</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minv</span><span style="color: #000000; ">=</span><span style="color: #000000; ">min(minv,t[j]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(minv</span><span style="color: #000000; ">==</span><span style="color: #000000; ">kInf)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;impossible</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">true</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">break</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">minv</span><span style="color: #000000; ">-</span><span style="color: #000000; ">a[</span><span style="color: #000000; ">1</span><span style="color: #000000; ">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="color: #000000; ">=</span><span style="color: #000000; ">1</span><span style="color: #000000; ">;j</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">i;j</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(a[j]</span><span style="color: #000000; ">!=-</span><span style="color: #000000; ">kInf)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;pos(</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;k</span><span style="color: #000000; ">=</span><span style="color: #000000; ">1</span><span style="color: #000000; ">;k</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">m;k</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(t[k]</span><span style="color: #000000; ">==</span><span style="color: #000000; ">a[i]</span><span style="color: #000000; ">+</span><span style="color: #000000; ">a[j])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos</span><span style="color: #000000; ">=</span><span style="color: #000000; ">k;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">break</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(pos</span><span style="color: #000000; ">==-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;impossible</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">true</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">break</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t[pos]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">kInf;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(impossible)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">break</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&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; ">impossible)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;found</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">true</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&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; ">found)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">Impossible\n</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">continue</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&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; ">1</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">n;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(i</span><span style="color: #000000; ">!=</span><span style="color: #000000; ">1</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">%d</span><span style="color: #000000; ">"</span><span style="color: #000000; ">,a[i]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">\n</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&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; ">;<br />}<br /></span></div><img src ="http://www.cppblog.com/rakerichard/aggbug/154675.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2011-08-30 10:51 <a href="http://www.cppblog.com/rakerichard/archive/2011/08/30/154675.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UVa 11137 Ingenuous Cubrency</title><link>http://www.cppblog.com/rakerichard/archive/2011/08/03/152339.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Wed, 03 Aug 2011 04:12:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2011/08/03/152339.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/152339.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2011/08/03/152339.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/152339.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/152339.html</trackback:ping><description><![CDATA[昨天和小猪商量分工问题，我主攻DP和数学，他主攻图论。从今天开始做DP。<br />以下是我的代码：<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; ">/*</span><span style="color: #008000; "><br />&nbsp;*&nbsp;Author:&nbsp;&nbsp;lee1r<br />&nbsp;*&nbsp;Created&nbsp;Time:&nbsp;&nbsp;2011/8/3&nbsp;10:55:57<br />&nbsp;*&nbsp;File&nbsp;Name:&nbsp;uva11137.cpp<br />&nbsp;</span><span style="color: #008000; ">*/</span><span style="color: #000000; "><br />#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 />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">sstream</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">fstream</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">vector</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">list</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">deque</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">queue</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">stack</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">map</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #0000FF; ">set</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">bitset</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">algorithm</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cstdio</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cstdlib</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cstring</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cctype</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">cmath</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br />#include</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">ctime</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; "><br /></span><span style="color: #0000FF; ">#define</span><span style="color: #000000; ">&nbsp;L(x)&nbsp;((x)&lt;&lt;1)</span><span style="color: #000000; "><br /></span><span style="color: #0000FF; ">#define</span><span style="color: #000000; ">&nbsp;R(x)&nbsp;(((x)&lt;&lt;1)+1)</span><span style="color: #000000; "><br /></span><span style="color: #0000FF; ">#define</span><span style="color: #000000; ">&nbsp;Half(x)&nbsp;((x)&gt;&gt;1)</span><span style="color: #000000; "><br /></span><span style="color: #0000FF; ">#define</span><span style="color: #000000; ">&nbsp;lowbit(x)&nbsp;((x)&amp;(-(x)))</span><span style="color: #000000; "><br /></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 /></span><span style="color: #0000FF; ">const</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;kInf(</span><span style="color: #000000; ">0x7f7f7f7f</span><span style="color: #000000; ">);<br /></span><span style="color: #0000FF; ">const</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">double</span><span style="color: #000000; ">&nbsp;kEps(1e</span><span style="color: #000000; ">-</span><span style="color: #000000; ">11</span><span style="color: #000000; ">);<br />typedef&nbsp;</span><span style="color: #0000FF; ">long</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">long</span><span style="color: #000000; ">&nbsp;int64;<br />typedef&nbsp;unsigned&nbsp;</span><span style="color: #0000FF; ">long</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">long</span><span style="color: #000000; ">&nbsp;uint64;<br /><br /></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;kList[</span><span style="color: #000000; ">27</span><span style="color: #000000; ">];<br />int64&nbsp;d[</span><span style="color: #000000; ">10007</span><span style="color: #000000; ">][</span><span style="color: #000000; ">22</span><span style="color: #000000; ">];<br /><br /></span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;Init()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;kList[</span><span style="color: #000000; ">27</span><span style="color: #000000; ">];<br />&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; ">1</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">21</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;kList[i]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">i</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i</span><span style="color: #000000; ">*</span><span style="color: #000000; ">i;<br />&nbsp;&nbsp;&nbsp;&nbsp;memset(d,</span><span style="color: #000000; ">0</span><span style="color: #000000; ">,</span><span style="color: #0000FF; ">sizeof</span><span style="color: #000000; ">(d));<br />&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; ">22</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[</span><span style="color: #000000; ">0</span><span style="color: #000000; ">][i]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">1</span><span style="color: #000000; ">;<br />&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; ">1</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">10000</span><span style="color: #000000; ">;i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&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;j</span><span style="color: #000000; ">=</span><span style="color: #000000; ">1</span><span style="color: #000000; ">;j</span><span style="color: #000000; ">&lt;=</span><span style="color: #000000; ">21</span><span style="color: #000000; ">;j</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i][j]</span><span style="color: #000000; ">=</span><span style="color: #000000; ">d[i][j</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">(i</span><span style="color: #000000; ">&gt;=</span><span style="color: #000000; ">kList[j])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i][j]</span><span style="color: #000000; ">+=</span><span style="color: #000000; ">d[i</span><span style="color: #000000; ">-</span><span style="color: #000000; ">kList[j]][j];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">freopen("data.in","r",stdin);</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;Init();<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;n;<br />&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</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; ">==</span><span style="color: #000000; ">1</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000; ">&lt;&lt;</span><span style="color: #000000; ">d[n][</span><span style="color: #000000; ">21</span><span style="color: #000000; ">]</span><span style="color: #000000; ">&lt;&lt;</span><span style="color: #000000; ">endl;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&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; ">;<br />}<br /></span></div><img src ="http://www.cppblog.com/rakerichard/aggbug/152339.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2011-08-03 12:12 <a href="http://www.cppblog.com/rakerichard/archive/2011/08/03/152339.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UVa 357 Let Me Count The Ways</title><link>http://www.cppblog.com/rakerichard/archive/2011/05/24/147055.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Tue, 24 May 2011 13:14:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2011/05/24/147055.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/147055.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2011/05/24/147055.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/147055.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/147055.html</trackback:ping><description><![CDATA[<div>题目大意：求出共有多少种组合方案，使得数字之和为n。可以选择的数字有1，5，10，25，50（用数组c存储）。<br />用d[i][j]表示：使用的最大数字不超过c[j]、和为i的方案总数。考虑这样分类：该方案的最后一个数为c[j]；该方案的最后一个数不为c[j]。那么就有d[i][j]=d[i-c[j]][j]+d[i][j-1]。边界条件为d[0][i]=1。<br />以下是我的代码：
<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"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#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 />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></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 /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;kMaxn(</span><span style="color: #000000">30000</span><span style="color: #000000">);<br /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;c[]</span><span style="color: #000000">=</span><span style="color: #000000">{</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">5</span><span style="color: #000000">,</span><span style="color: #000000">10</span><span style="color: #000000">,</span><span style="color: #000000">25</span><span style="color: #000000">,</span><span style="color: #000000">50</span><span style="color: #000000">};<br /><br /></span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;d[kMaxn</span><span style="color: #000000">+</span><span style="color: #000000">7</span><span style="color: #000000">][</span><span style="color: #000000">5</span><span style="color: #000000">];<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Init()<br />{<br />&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">5</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[</span><span style="color: #000000">0</span><span style="color: #000000">][i]</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&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">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">kMaxn;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&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;j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;j</span><span style="color: #000000">&lt;</span><span style="color: #000000">5</span><span style="color: #000000">;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i][j]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(i</span><span style="color: #000000">&gt;=</span><span style="color: #000000">c[j])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i][j]</span><span style="color: #000000">+=</span><span style="color: #000000">d[i</span><span style="color: #000000">-</span><span style="color: #000000">c[j]][j];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(j</span><span style="color: #000000">&gt;=</span><span style="color: #000000">1</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i][j]</span><span style="color: #000000">+=</span><span style="color: #000000">d[i][j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;#ifndef&nbsp;ONLINE_JUDGE<br />&nbsp;&nbsp;&nbsp;&nbsp;freopen(</span><span style="color: #000000">"</span><span style="color: #000000">data.in</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">r</span><span style="color: #000000">"</span><span style="color: #000000">,stdin);<br />&nbsp;&nbsp;&nbsp;&nbsp;freopen(</span><span style="color: #000000">"</span><span style="color: #000000">data.out</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">"</span><span style="color: #000000">w</span><span style="color: #000000">"</span><span style="color: #000000">,stdout);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">#endif</span><span style="color: #000000"><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;Init();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n;<br />&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</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">==</span><span style="color: #000000">1</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(d[n][</span><span style="color: #000000">4</span><span style="color: #000000">]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">1</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">There&nbsp;is&nbsp;only&nbsp;1&nbsp;way&nbsp;to&nbsp;produce&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">n</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;cents&nbsp;change.</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">There&nbsp;are&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">d[n][</span><span style="color: #000000">4</span><span style="color: #000000">]</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;ways&nbsp;to&nbsp;produce&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">n</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;cents&nbsp;change.</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&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">;<br />}<br /></span></div></div><img src ="http://www.cppblog.com/rakerichard/aggbug/147055.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2011-05-24 21:14 <a href="http://www.cppblog.com/rakerichard/archive/2011/05/24/147055.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 2147 kiki's game</title><link>http://www.cppblog.com/rakerichard/archive/2011/05/08/145937.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Sun, 08 May 2011 03:41:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2011/05/08/145937.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/145937.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2011/05/08/145937.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/145937.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/145937.html</trackback:ping><description><![CDATA[能够转移到某个必败状态的为必胜状态，只能转移到必胜状态的为必败状态。<br>根据这个递推即可，d[i][j]==1表示在i*j的棋盘上游戏，kiki必胜。<br>网上许多人对于这道题是判断奇偶性：先递推，然后发现规律。<br>开2000&#215;2000的bool数组会超空间，使用bitset即可。<br>以下是我的代码：
<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"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">bitset</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;dx[]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">},dy[]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">};<br><br>bitset</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">2007</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;d[</span><span style="COLOR: #000000">2007</span><span style="COLOR: #000000">];<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Init()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;d[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&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">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">2000</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&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;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">2000</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;success(</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;ii(i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dx[k]),jj(j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dy[k]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(ii</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">&nbsp;jj</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(d[ii][jj]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;success</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&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">success)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;Init();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,m;<br>&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%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)</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;(n&nbsp;</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">&nbsp;m))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(d[n][m])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Wonderful!\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">What&nbsp;a&nbsp;pity!\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><br>&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">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/rakerichard/aggbug/145937.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2011-05-08 11:41 <a href="http://www.cppblog.com/rakerichard/archive/2011/05/08/145937.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UVa 146 ID Codes</title><link>http://www.cppblog.com/rakerichard/archive/2011/04/15/144313.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Fri, 15 Apr 2011 08:14:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2011/04/15/144313.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/144313.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2011/04/15/144313.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/144313.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/144313.html</trackback:ping><description><![CDATA[以下是我的代码：
<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"><span style="COLOR: #000000">#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>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;s;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">s&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;s</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">#</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(next_permutation(s.begin(),s.end()))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">s</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">No&nbsp;Successor</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&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">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/rakerichard/aggbug/144313.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2011-04-15 16:14 <a href="http://www.cppblog.com/rakerichard/archive/2011/04/15/144313.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1559 最大子矩阵</title><link>http://www.cppblog.com/rakerichard/archive/2011/03/07/141311.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Mon, 07 Mar 2011 12:54:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2011/03/07/141311.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/141311.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2011/03/07/141311.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/141311.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/141311.html</trackback:ping><description><![CDATA[这题叫DP么？<br>以下是我的代码：<br>
<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"><span style="COLOR: #000000">#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>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstring</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;kMaxn&nbsp;(</span><span style="COLOR: #000000">1007</span><span style="COLOR: #000000">);<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;d[kMaxn][kMaxn];<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>&nbsp;&nbsp;&nbsp;&nbsp;freopen("data.in","r",stdin);<br>&nbsp;&nbsp;&nbsp;&nbsp;freopen("data.out","w",stdout);<br>&nbsp;&nbsp;&nbsp;&nbsp;//</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;T;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">T;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(T</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;m,n,x,y;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">m</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">y;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(d,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,kMaxn</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">kMaxn</span><span style="COLOR: #000000">*</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">));<br>&nbsp;&nbsp;&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">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">m;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">t;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">d[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">d[i][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">t;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;i=1;i&lt;=m;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;j=1;j&lt;=n;j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;d[i][j]&lt;&lt;"&nbsp;";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;ans(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&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">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">m;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">x&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;j</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">y)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">max(ans,d[i][j]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x][j]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d[i][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">d[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">y&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;j</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">x)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">max(ans,d[i][j]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y][j]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d[i][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">d[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">ans</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/rakerichard/aggbug/141311.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2011-03-07 20:54 <a href="http://www.cppblog.com/rakerichard/archive/2011/03/07/141311.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UVa 10198 Counting</title><link>http://www.cppblog.com/rakerichard/archive/2010/11/12/133467.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Fri, 12 Nov 2010 15:17:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2010/11/12/133467.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/133467.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2010/11/12/133467.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/133467.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/133467.html</trackback:ping><description><![CDATA[简单的递推，d[i]=d[i-1]+d[i-1]+d[i-2]+d[i-3]。数据规模很大，需要使用高精度。<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"><span style="COLOR: #000000">#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>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;maxn&nbsp;1007</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;maxl&nbsp;90</span><span style="COLOR: #000000"><br></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><br>typedef&nbsp;</span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"><br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;l,s[maxl];<br>}bign;<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Add(bign&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">c,bign&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a,bign&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">c,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(c));<br>&nbsp;&nbsp;&nbsp;&nbsp;c.l</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(a.l</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">b.l</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">a.l:b.l);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">long</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">c.l;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.s[i]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">a.s[i]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">b.s[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(c.s[i]</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">100000</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.s[i]</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">100000</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.s[i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(c.s[c.l])&nbsp;c.l</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>}<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Print(bign&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%ld</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,a.s[a.l</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a.l</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%05ld</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,a.s[i]);<br>}<br><br></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;n;<br>bign&nbsp;d[maxn]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{{</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,{</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">}},{</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,{</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">}},{</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,{</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">}},{</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,{</span><span style="COLOR: #000000">13</span><span style="COLOR: #000000">}}};<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;&nbsp;d[i]=d[i-1]+d[i-1]+d[i-2]+d[i-3]</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bign&nbsp;t1,t2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add(t1,d[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">],d[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add(t2,t1,d[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add(d[i],t2,d[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print(d[n]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/rakerichard/aggbug/133467.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2010-11-12 23:17 <a href="http://www.cppblog.com/rakerichard/archive/2010/11/12/133467.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>rqnoj 3 Jam的计数法</title><link>http://www.cppblog.com/rakerichard/archive/2010/09/26/127760.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Sun, 26 Sep 2010 07:40:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2010/09/26/127760.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/127760.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2010/09/26/127760.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/127760.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/127760.html</trackback:ping><description><![CDATA[让初始状态直接进入dfs函数。<br>Here is my code:<br>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#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>#include</span><span style="color: #000000;">&lt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;maxn&nbsp;107</span><span style="color: #000000;"><br></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></span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;s,t,w,counter</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;r[maxn],ans[maxn];<br></span><span style="color: #0000ff;">bool</span><span style="color: #000000;">&nbsp;first,used[maxn];<br><br></span><span style="color: #0000ff;">void</span><span style="color: #000000;">&nbsp;dfs(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;depth)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(counter</span><span style="color: #000000;">&gt;=</span><span style="color: #000000;">5</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(depth</span><span style="color: #000000;">&gt;=</span><span style="color: #000000;">w)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(first)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;first</span><span style="color: #000000;">=</span><span style="color: #0000ff;">false</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000;">&lt;&lt;</span><span style="color: #000000;">ans</span><span style="color: #000000;">&lt;&lt;</span><span style="color: #000000;">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;counter</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;i</span><span style="color: #000000;">=</span><span style="color: #000000;">(first</span><span style="color: #000000;">?</span><span style="color: #000000;">r[depth]</span><span style="color: #000000;">-</span><span style="color: #000000;">'</span><span style="color: #000000;">a</span><span style="color: #000000;">'</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">:</span><span style="color: #000000;">ans[depth</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">-</span><span style="color: #000000;">'</span><span style="color: #000000;">a</span><span style="color: #000000;">'</span><span style="color: #000000;">+</span><span style="color: #000000;">2</span><span style="color: #000000;">);i</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">t;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&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;">used[i])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;used[i]</span><span style="color: #000000;">=</span><span style="color: #0000ff;">true</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[depth]</span><span style="color: #000000;">=</span><span style="color: #000000;">i</span><span style="color: #000000;">+</span><span style="color: #000000;">'</span><span style="color: #000000;">a</span><span style="color: #000000;">'</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(depth</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;used[i]</span><span style="color: #000000;">=</span><span style="color: #0000ff;">false</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;">s</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;">t</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;">w</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;">r;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;&nbsp;Input</span><span style="color: #008000;"><br></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;memset(ans,</span><span style="color: #000000;">0</span><span style="color: #000000;">,</span><span style="color: #0000ff;">sizeof</span><span style="color: #000000;">(ans));<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(used,</span><span style="color: #0000ff;">false</span><span style="color: #000000;">,</span><span style="color: #0000ff;">sizeof</span><span style="color: #000000;">(used));<br>&nbsp;&nbsp;&nbsp;&nbsp;counter</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;first</span><span style="color: #000000;">=</span><span style="color: #0000ff;">true</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;dfs(</span><span style="color: #000000;">0</span><span style="color: #000000;">);<br></span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}<br></span></div>
<br><br>  <img src ="http://www.cppblog.com/rakerichard/aggbug/127760.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2010-09-26 15:40 <a href="http://www.cppblog.com/rakerichard/archive/2010/09/26/127760.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1013 K-based numbers. Version 3</title><link>http://www.cppblog.com/rakerichard/archive/2010/09/10/126357.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Fri, 10 Sep 2010 13:51:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2010/09/10/126357.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/126357.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2010/09/10/126357.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/126357.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/126357.html</trackback:ping><description><![CDATA[通过这相似的三道题体会到了&#8220;量变引起质变&#8221;的道理。第一题数据规模很小，当然可以DP，但是搜索就足够了；第二题规模大了不少，高精度是必须的，同时需要用动态规划，递推和记忆化两种形式，我一直偏爱记忆化，选择了记忆化搜索；第三题规模继续增大，为了节省空间，高精度用到了压位存储，同时记忆化不再可行！因为会造成栈崩溃！改用递推。<br>以下是我的代码：<br>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#include</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">stdio.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br>#include</span><span style="color: #000000;">&lt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;max_digit&nbsp;300</span><span style="color: #000000;"><br></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;maxn&nbsp;1801</span><span style="color: #000000;"><br>typedef&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;"><br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;n,s[max_digit];<br>}bign;<br></span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;n,k;<br>bign&nbsp;d[maxn][</span><span style="color: #000000;">2</span><span style="color: #000000;">];<br><br></span><span style="color: #0000ff;">void</span><span style="color: #000000;">&nbsp;Add(bign&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">c,bign&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">a,bign&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">b)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(c.s,</span><span style="color: #000000;">0</span><span style="color: #000000;">,</span><span style="color: #0000ff;">sizeof</span><span style="color: #000000;">(c.s));<br>&nbsp;&nbsp;&nbsp;&nbsp;c.n</span><span style="color: #000000;">=</span><span style="color: #000000;">(a.n</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">b.n</span><span style="color: #000000;">?</span><span style="color: #000000;">a.n:b.n);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</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;">c.n;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.s[i]</span><span style="color: #000000;">+=</span><span style="color: #000000;">a.s[i]</span><span style="color: #000000;">+</span><span style="color: #000000;">b.s[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(c.s[i]</span><span style="color: #000000;">&gt;=</span><span style="color: #000000;">100000000</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.s[i</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+=</span><span style="color: #000000;">c.s[i]</span><span style="color: #000000;">/</span><span style="color: #000000;">100000000</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.s[i]</span><span style="color: #000000;">%=</span><span style="color: #000000;">100000000</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(c.s[c.n])&nbsp;c.n</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>}<br></span><span style="color: #0000ff;">void</span><span style="color: #000000;">&nbsp;Mul(bign&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">c,</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;t,bign&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">a)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(c.s,</span><span style="color: #000000;">0</span><span style="color: #000000;">,</span><span style="color: #0000ff;">sizeof</span><span style="color: #000000;">(c.s));<br>&nbsp;&nbsp;&nbsp;&nbsp;c.n</span><span style="color: #000000;">=</span><span style="color: #000000;">a.n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</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;">c.n;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.s[i]</span><span style="color: #000000;">=</span><span style="color: #000000;">t</span><span style="color: #000000;">*</span><span style="color: #000000;">a.s[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</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;">c.n;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(c.s[i]</span><span style="color: #000000;">&gt;=</span><span style="color: #000000;">100000000</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.s[i</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+=</span><span style="color: #000000;">c.s[i]</span><span style="color: #000000;">/</span><span style="color: #000000;">100000000</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.s[i]</span><span style="color: #000000;">%=</span><span style="color: #000000;">100000000</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(c.s[c.n])&nbsp;c.n</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>}<br></span><span style="color: #0000ff;">void</span><span style="color: #000000;">&nbsp;Print(bign&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">a)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%ld</span><span style="color: #000000;">"</span><span style="color: #000000;">,a.s[a.n</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;i</span><span style="color: #000000;">=</span><span style="color: #000000;">a.n</span><span style="color: #000000;">-</span><span style="color: #000000;">2</span><span style="color: #000000;">;i</span><span style="color: #000000;">&gt;=</span><span style="color: #000000;">0</span><span style="color: #000000;">;i</span><span style="color: #000000;">--</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%08ld</span><span style="color: #000000;">"</span><span style="color: #000000;">,a.s[i]);<br>}<br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%ld%ld</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;">k);<br>&nbsp;&nbsp;&nbsp;&nbsp;d[n][</span><span style="color: #000000;">1</span><span style="color: #000000;">].n</span><span style="color: #000000;">=</span><span style="color: #000000;">1</span><span style="color: #000000;">;d[n][</span><span style="color: #000000;">1</span><span style="color: #000000;">].s[</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">k;<br>&nbsp;&nbsp;&nbsp;&nbsp;d[n][</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;">;d[n][</span><span style="color: #000000;">0</span><span style="color: #000000;">].s[</span><span style="color: #000000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">k</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;i</span><span style="color: #000000;">=</span><span style="color: #000000;">n</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;i</span><span style="color: #000000;">&gt;=</span><span style="color: #000000;">1</span><span style="color: #000000;">;i</span><span style="color: #000000;">--</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(i</span><span style="color: #000000;">==</span><span style="color: #000000;">1</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mul(d[i][</span><span style="color: #000000;">1</span><span style="color: #000000;">],k</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">,d[i</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">][</span><span style="color: #000000;">1</span><span style="color: #000000;">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">continue</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bign&nbsp;t;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mul(t,k</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">,d[i</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">][</span><span style="color: #000000;">1</span><span style="color: #000000;">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add(d[i][</span><span style="color: #000000;">1</span><span style="color: #000000;">],t,d[i</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">][</span><span style="color: #000000;">0</span><span style="color: #000000;">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mul(d[i][</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;">,d[i</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">][</span><span style="color: #000000;">1</span><span style="color: #000000;">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;Print(d[</span><span style="color: #000000;">1</span><span style="color: #000000;">][</span><span style="color: #000000;">1</span><span style="color: #000000;">]);printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">\n</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br></span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}<br></span></div>
<br><br><img src ="http://www.cppblog.com/rakerichard/aggbug/126357.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2010-09-10 21:51 <a href="http://www.cppblog.com/rakerichard/archive/2010/09/10/126357.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 2515 Yanghee 的算术</title><link>http://www.cppblog.com/rakerichard/archive/2010/07/09/119840.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Fri, 09 Jul 2010 03:05:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2010/07/09/119840.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/119840.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2010/07/09/119840.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/119840.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/119840.html</trackback:ping><description><![CDATA[此题《算法艺术》上有详解。<br>最近做题果然不如以前，WA了几次&#8230;&#8230;<br>WA的原因如下：<br>1、a[i]+a[j]写成a[1]+a[j]；<br>2、注意从原序列中删除x的时候，序列中可能存在多个x，此时只能删除1次，不能重复删除；甚至有可能x不存在，这说明当前枚举的a[2]+a[3]的值不符合要求。<br>以下是我代码：<br>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#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>#include</span><span style="color: #000000;">&lt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;maxn&nbsp;57</span><span style="color: #000000;"><br></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;INF&nbsp;200007</span><span style="color: #000000;"><br></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></span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;n,a[maxn],r[maxn</span><span style="color: #000000;">*</span><span style="color: #000000;">maxn</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">];<br></span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;m,t[maxn</span><span style="color: #000000;">*</span><span style="color: #000000;">maxn</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">];<br></span><span style="color: #0000ff;">bool</span><span style="color: #000000;">&nbsp;okay,impossible;<br></span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;pos(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;x)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;i</span><span style="color: #000000;">=</span><span style="color: #000000;">1</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;">(n</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(t[i]</span><span style="color: #000000;">==</span><span style="color: #000000;">x)&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;i;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>}<br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;"><br>&nbsp;&nbsp;&nbsp;&nbsp;freopen("data.in","r",stdin);<br>&nbsp;&nbsp;&nbsp;&nbsp;freopen("data.out","w",stdout);<br>&nbsp;&nbsp;&nbsp;&nbsp;//</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br>&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;i</span><span style="color: #000000;">=</span><span style="color: #000000;">1</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;">(n</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;">r[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;&nbsp;Input</span><span style="color: #008000;"><br></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;okay</span><span style="color: #000000;">=</span><span style="color: #0000ff;">false</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;p</span><span style="color: #000000;">=</span><span style="color: #000000;">3</span><span style="color: #000000;">;p</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">n</span><span style="color: #000000;">*</span><span style="color: #000000;">(n</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">r[p]</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">r[</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">r[</span><span style="color: #000000;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">&amp;&amp;!</span><span style="color: #000000;">okay;p</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(a,</span><span style="color: #000000;">0</span><span style="color: #000000;">,</span><span style="color: #0000ff;">sizeof</span><span style="color: #000000;">(a));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;i</span><span style="color: #000000;">=</span><span style="color: #000000;">1</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;">(n</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t[i]</span><span style="color: #000000;">=</span><span style="color: #000000;">r[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">((t[</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">t[</span><span style="color: #000000;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">-</span><span style="color: #000000;">t[p])</span><span style="color: #000000;">%</span><span style="color: #000000;">2</span><span style="color: #000000;">!=</span><span style="color: #000000;">0</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">continue</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">(t[</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">t[</span><span style="color: #000000;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">-</span><span style="color: #000000;">t[p])</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[</span><span style="color: #000000;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">(t[</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">-</span><span style="color: #000000;">t[</span><span style="color: #000000;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">t[p])</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[</span><span style="color: #000000;">3</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">(t[</span><span style="color: #000000;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">+</span><span style="color: #000000;">t[p]</span><span style="color: #000000;">-</span><span style="color: #000000;">t[</span><span style="color: #000000;">1</span><span style="color: #000000;">])</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(a[</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">0</span><span style="color: #000000;">||</span><span style="color: #000000;">a[</span><span style="color: #000000;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">0</span><span style="color: #000000;">||</span><span style="color: #000000;">a[</span><span style="color: #000000;">3</span><span style="color: #000000;">]</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">0</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">continue</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t[</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">t[</span><span style="color: #000000;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">=</span><span style="color: #000000;">t[p]</span><span style="color: #000000;">=</span><span style="color: #000000;">INF;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;i</span><span style="color: #000000;">=</span><span style="color: #000000;">4</span><span style="color: #000000;">;i</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">n;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m</span><span style="color: #000000;">=</span><span style="color: #000000;">INF;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;j</span><span style="color: #000000;">=</span><span style="color: #000000;">1</span><span style="color: #000000;">;j</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">n</span><span style="color: #000000;">*</span><span style="color: #000000;">(n</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">;j</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(t[j]</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">m)&nbsp;m</span><span style="color: #000000;">=</span><span style="color: #000000;">t[j];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;&nbsp;Find&nbsp;min_num</span><span style="color: #008000;"><br></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]</span><span style="color: #000000;">=</span><span style="color: #000000;">m</span><span style="color: #000000;">-</span><span style="color: #000000;">a[</span><span style="color: #000000;">1</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(a[i]</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">0</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;impossible</span><span style="color: #000000;">=</span><span style="color: #0000ff;">false</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;j</span><span style="color: #000000;">=</span><span style="color: #000000;">1</span><span style="color: #000000;">;j</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">i</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;j</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;tmp</span><span style="color: #000000;">=</span><span style="color: #000000;">pos(a[i]</span><span style="color: #000000;">+</span><span style="color: #000000;">a[j]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(tmp</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">0</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;impossible</span><span style="color: #000000;">=</span><span style="color: #0000ff;">true</span><span style="color: #000000;">;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t[tmp]</span><span style="color: #000000;">=</span><span style="color: #000000;">INF;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;&nbsp;Delete</span><span style="color: #008000;"><br></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(impossible)&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(i</span><span style="color: #000000;">==</span><span style="color: #000000;">n)&nbsp;okay</span><span style="color: #000000;">=</span><span style="color: #0000ff;">true</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">long</span><span style="color: #000000;">&nbsp;i</span><span style="color: #000000;">=</span><span style="color: #000000;">1</span><span style="color: #000000;">;i</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">n;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000;">&lt;&lt;</span><span style="color: #000000;">a[i]</span><span style="color: #000000;">&lt;&lt;</span><span style="color: #000000;">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;&nbsp;Output</span><span style="color: #008000;"><br></span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}<br></span></div>
<br><br>  <img src ="http://www.cppblog.com/rakerichard/aggbug/119840.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2010-07-09 11:05 <a href="http://www.cppblog.com/rakerichard/archive/2010/07/09/119840.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vijos P1319 数列</title><link>http://www.cppblog.com/rakerichard/archive/2010/01/06/105027.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Wed, 06 Jan 2010 12:33:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2010/01/06/105027.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/105027.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2010/01/06/105027.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/105027.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/105027.html</trackback:ping><description><![CDATA[<font face=宋体>仔细观察，很容易发现规律。<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">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</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">#define</span><span style="COLOR: #000000">&nbsp;MAXN&nbsp;1010</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>typedef&nbsp;unsigned&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;Long;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>Long&nbsp;f(Long&nbsp;x,Long&nbsp;a)<br><img id=Codehighlighter1_86_155_Open_Image onclick="this.style.display='none'; Codehighlighter1_86_155_Open_Text.style.display='none'; Codehighlighter1_86_155_Closed_Image.style.display='inline'; Codehighlighter1_86_155_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_86_155_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_86_155_Closed_Text.style.display='none'; Codehighlighter1_86_155_Open_Image.style.display='inline'; Codehighlighter1_86_155_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_86_155_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_86_155_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Long&nbsp;i,re</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;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">a;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;re</span><span style="COLOR: #000000">*=</span><span style="COLOR: #000000">x;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;re;<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></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br><img id=Codehighlighter1_168_544_Open_Image onclick="this.style.display='none'; Codehighlighter1_168_544_Open_Text.style.display='none'; Codehighlighter1_168_544_Closed_Image.style.display='inline'; Codehighlighter1_168_544_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_168_544_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_168_544_Closed_Text.style.display='none'; Codehighlighter1_168_544_Open_Image.style.display='inline'; Codehighlighter1_168_544_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_168_544_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_168_544_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_207_209_Open_Image onclick="this.style.display='none'; Codehighlighter1_207_209_Open_Text.style.display='none'; Codehighlighter1_207_209_Closed_Image.style.display='inline'; Codehighlighter1_207_209_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_207_209_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_207_209_Closed_Text.style.display='none'; Codehighlighter1_207_209_Open_Image.style.display='inline'; Codehighlighter1_207_209_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Long&nbsp;k,n,i,count,tot,tmp,a[MAXN]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_207_209_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_207_209_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%lu%lu</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">k,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;tot</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(tot</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n)<br><img id=Codehighlighter1_284_481_Open_Image onclick="this.style.display='none'; Codehighlighter1_284_481_Open_Text.style.display='none'; Codehighlighter1_284_481_Closed_Image.style.display='inline'; Codehighlighter1_284_481_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_284_481_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_284_481_Closed_Text.style.display='none'; Codehighlighter1_284_481_Open_Image.style.display='inline'; Codehighlighter1_284_481_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_284_481_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_284_481_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;tot</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">tot;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[tot]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">f(k,count);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">tmp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_391_475_Open_Image onclick="this.style.display='none'; Codehighlighter1_391_475_Open_Text.style.display='none'; Codehighlighter1_391_475_Closed_Image.style.display='inline'; Codehighlighter1_391_475_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_391_475_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_391_475_Closed_Text.style.display='none'; Codehighlighter1_391_475_Open_Image.style.display='inline'; Codehighlighter1_391_475_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_391_475_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_391_475_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;tot</span><span style="COLOR: #000000">++</span><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;a[tot]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[i]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">a[tmp];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(tot</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">n)&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%lu\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,a[n]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;getchar();getchar();</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</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></span></div>
</font>
<img src ="http://www.cppblog.com/rakerichard/aggbug/105027.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2010-01-06 20:33 <a href="http://www.cppblog.com/rakerichard/archive/2010/01/06/105027.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vijos P1132 求二叉树的先序序列</title><link>http://www.cppblog.com/rakerichard/archive/2010/01/06/105016.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Wed, 06 Jan 2010 12:12:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2010/01/06/105016.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/105016.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2010/01/06/105016.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/105016.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/105016.html</trackback:ping><description><![CDATA[<p><font face=宋体 size=3>通过后序序列找根结点，在中序序列中分成两部分。</font></p>
<p><font face=宋体 size=3>以下是我的代码：</font></p>
<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">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</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">char</span><span style="COLOR: #000000">&nbsp;s1[</span><span style="COLOR: #000000">30</span><span style="COLOR: #000000">],s2[</span><span style="COLOR: #000000">30</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;pos(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;s[],</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;x)<br><img id=Codehighlighter1_82_134_Open_Image onclick="this.style.display='none'; Codehighlighter1_82_134_Open_Text.style.display='none'; Codehighlighter1_82_134_Closed_Image.style.display='inline'; Codehighlighter1_82_134_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_82_134_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_82_134_Closed_Text.style.display='none'; Codehighlighter1_82_134_Open_Image.style.display='inline'; Codehighlighter1_82_134_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_82_134_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_82_134_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i</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;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(s[</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">x);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;i;<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></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;solve(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;begin1,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;end1,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;begin2,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;end2)<br><img id=Codehighlighter1_188_382_Open_Image onclick="this.style.display='none'; Codehighlighter1_188_382_Open_Text.style.display='none'; Codehighlighter1_188_382_Closed_Image.style.display='inline'; Codehighlighter1_188_382_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_188_382_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_188_382_Closed_Text.style.display='none'; Codehighlighter1_188_382_Open_Image.style.display='inline'; Codehighlighter1_188_382_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_188_382_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_188_382_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;m;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;m</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">pos(s1,s2[end2]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%c</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,s2[end2]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(&nbsp;m</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">begin1&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;solve(begin1,m</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,begin2,begin2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">begin1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">m</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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(&nbsp;m</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">end1&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;solve(m</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,end1,end2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">end1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">m,end2</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><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br><img id=Codehighlighter1_395_497_Open_Image onclick="this.style.display='none'; Codehighlighter1_395_497_Open_Text.style.display='none'; Codehighlighter1_395_497_Closed_Image.style.display='inline'; Codehighlighter1_395_497_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_395_497_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_395_497_Closed_Text.style.display='none'; Codehighlighter1_395_497_Open_Image.style.display='inline'; Codehighlighter1_395_497_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_395_497_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_395_497_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;gets(s1);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;gets(s2);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;solve(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,strlen(s1)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,strlen(s2)</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;putchar(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\n</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</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></span></div>
<img src ="http://www.cppblog.com/rakerichard/aggbug/105016.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2010-01-06 20:12 <a href="http://www.cppblog.com/rakerichard/archive/2010/01/06/105016.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vijos P1562 zgx跳棋游戏之二</title><link>http://www.cppblog.com/rakerichard/archive/2010/01/06/104984.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Wed, 06 Jan 2010 11:35:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2010/01/06/104984.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/104984.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2010/01/06/104984.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/104984.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/104984.html</trackback:ping><description><![CDATA[<p><font face=宋体 size=3>样例中给出了n==4的情况，先考虑n==5的情况</font></p>
<p><font face=宋体 size=3>OOOOO*****__</font></p>
<p><font face=宋体 size=3>第一次移动-&gt;OOOO__****O*</font></p>
<p><font face=宋体 size=3>第二次移动-&gt;OOOO****__O*</font></p>
<p><font face=宋体 size=3>注意到前面的部分，转换到了n==4的情况，所以想到一个分治算法。</font></p>
<p><font face=宋体 size=3>以下是我的代码：</font></p>
<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">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</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">long</span><span style="COLOR: #000000">&nbsp;count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n;<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;swap(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a,</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b)<br><img id=Codehighlighter1_85_120_Open_Image onclick="this.style.display='none'; Codehighlighter1_85_120_Open_Text.style.display='none'; Codehighlighter1_85_120_Closed_Image.style.display='inline'; Codehighlighter1_85_120_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_85_120_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_85_120_Closed_Text.style.display='none'; Codehighlighter1_85_120_Open_Image.style.display='inline'; Codehighlighter1_85_120_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_85_120_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_85_120_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;t;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;t</span><span style="COLOR: #000000">=*</span><span style="COLOR: #000000">a;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">=*</span><span style="COLOR: #000000">b;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">t;<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></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;div(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;a[],</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;len)<br><img id=Codehighlighter1_149_1053_Open_Image onclick="this.style.display='none'; Codehighlighter1_149_1053_Open_Text.style.display='none'; Codehighlighter1_149_1053_Closed_Image.style.display='inline'; Codehighlighter1_149_1053_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_149_1053_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_149_1053_Closed_Text.style.display='none'; Codehighlighter1_149_1053_Open_Image.style.display='inline'; Codehighlighter1_149_1053_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_149_1053_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_149_1053_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;t;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(len</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_182_467_Open_Image onclick="this.style.display='none'; Codehighlighter1_182_467_Open_Text.style.display='none'; Codehighlighter1_182_467_Closed_Image.style.display='inline'; Codehighlighter1_182_467_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_182_467_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_182_467_Closed_Text.style.display='none'; Codehighlighter1_182_467_Open_Image.style.display='inline'; Codehighlighter1_182_467_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_182_467_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_182_467_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;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">step&nbsp;%ld:%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,count,a);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[len</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[len</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</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;&nbsp;&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[len</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[len</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">step&nbsp;%ld:%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,count,a);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[len</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[len</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</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;&nbsp;&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[len</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[len</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;div(a,len</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(len</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_494_1051_Open_Image onclick="this.style.display='none'; Codehighlighter1_494_1051_Open_Text.style.display='none'; Codehighlighter1_494_1051_Closed_Image.style.display='inline'; Codehighlighter1_494_1051_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_494_1051_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_494_1051_Closed_Text.style.display='none'; Codehighlighter1_494_1051_Open_Image.style.display='inline'; Codehighlighter1_494_1051_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_494_1051_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_494_1051_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;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">step&nbsp;%ld:%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,count,a);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">]);&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">step&nbsp;%ld:%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,count,a);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]);&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">step&nbsp;%ld:%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,count,a);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">step&nbsp;%ld:%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,count,a);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">step&nbsp;%ld:%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,count,a);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]);&nbsp;swap(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[</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;&nbsp;&nbsp;count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">step&nbsp;%ld:%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,count,a);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&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></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br><img id=Codehighlighter1_1066_1343_Open_Image onclick="this.style.display='none'; Codehighlighter1_1066_1343_Open_Text.style.display='none'; Codehighlighter1_1066_1343_Closed_Image.style.display='inline'; Codehighlighter1_1066_1343_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_1066_1343_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1066_1343_Closed_Text.style.display='none'; Codehighlighter1_1066_1343_Open_Image.style.display='inline'; Codehighlighter1_1066_1343_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_1066_1343_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_1066_1343_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,len;<br><img id=Codehighlighter1_1099_1101_Open_Image onclick="this.style.display='none'; Codehighlighter1_1099_1101_Open_Text.style.display='none'; Codehighlighter1_1099_1101_Closed_Image.style.display='inline'; Codehighlighter1_1099_1101_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1099_1101_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1099_1101_Closed_Text.style.display='none'; Codehighlighter1_1099_1101_Open_Image.style.display='inline'; Codehighlighter1_1099_1101_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;a[</span><span style="COLOR: #000000">205</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_1099_1101_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_1099_1101_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;len</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(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">len;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_1166_1291_Open_Image onclick="this.style.display='none'; Codehighlighter1_1166_1291_Open_Text.style.display='none'; Codehighlighter1_1166_1291_Closed_Image.style.display='inline'; Codehighlighter1_1166_1291_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1166_1291_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1166_1291_Closed_Text.style.display='none'; Codehighlighter1_1166_1291_Open_Image.style.display='inline'; Codehighlighter1_1166_1291_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_1166_1291_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_1166_1291_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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">O</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">n&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">len</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><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;a[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><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;a[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">_</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;div(a,len);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;getchar();getchar();</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</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></span></div>
<img src ="http://www.cppblog.com/rakerichard/aggbug/104984.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2010-01-06 19:35 <a href="http://www.cppblog.com/rakerichard/archive/2010/01/06/104984.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vijos P1114 FBI树</title><link>http://www.cppblog.com/rakerichard/archive/2010/01/06/104965.html</link><dc:creator>lee1r</dc:creator><author>lee1r</author><pubDate>Wed, 06 Jan 2010 11:14:00 GMT</pubDate><guid>http://www.cppblog.com/rakerichard/archive/2010/01/06/104965.html</guid><wfw:comment>http://www.cppblog.com/rakerichard/comments/104965.html</wfw:comment><comments>http://www.cppblog.com/rakerichard/archive/2010/01/06/104965.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/rakerichard/comments/commentRss/104965.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/rakerichard/services/trackbacks/104965.html</trackback:ping><description><![CDATA[<p><font face=宋体 size=3>部分和。</font></p>
<p><font face=宋体 size=3>以下是我的代码：</font></p>
<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">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img id=Codehighlighter1_38_40_Open_Image onclick="this.style.display='none'; Codehighlighter1_38_40_Open_Text.style.display='none'; Codehighlighter1_38_40_Closed_Image.style.display='inline'; Codehighlighter1_38_40_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_38_40_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_38_40_Closed_Text.style.display='none'; Codehighlighter1_38_40_Open_Image.style.display='inline'; Codehighlighter1_38_40_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,len</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,s[</span><span style="COLOR: #000000">2000</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_38_40_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_38_40_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">,sum[</span><span style="COLOR: #000000">2000</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_52_54_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_52_54_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></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;fbi(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;begin,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;end)<br><img id=Codehighlighter1_85_355_Open_Image onclick="this.style.display='none'; Codehighlighter1_85_355_Open_Text.style.display='none'; Codehighlighter1_85_355_Closed_Image.style.display='inline'; Codehighlighter1_85_355_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_85_355_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_85_355_Closed_Text.style.display='none'; Codehighlighter1_85_355_Open_Image.style.display='inline'; Codehighlighter1_85_355_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_85_355_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_85_355_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;mid</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(begin</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">end)</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(begin</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">end)<br><img id=Codehighlighter1_136_188_Open_Image onclick="this.style.display='none'; Codehighlighter1_136_188_Open_Text.style.display='none'; Codehighlighter1_136_188_Closed_Image.style.display='inline'; Codehighlighter1_136_188_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_136_188_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_136_188_Closed_Text.style.display='none'; Codehighlighter1_136_188_Open_Image.style.display='inline'; Codehighlighter1_136_188_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_136_188_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_136_188_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;fbi(begin,mid);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fbi(mid</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,end);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(sum[end]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">sum[begin</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">end</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">begin</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;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%c</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">I</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(sum[end]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">sum[begin</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%c</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">B</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%c</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">F</span><span style="COLOR: #000000">'</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></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br><img id=Codehighlighter1_368_565_Open_Image onclick="this.style.display='none'; Codehighlighter1_368_565_Open_Text.style.display='none'; Codehighlighter1_368_565_Closed_Image.style.display='inline'; Codehighlighter1_368_565_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_368_565_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_368_565_Closed_Text.style.display='none'; Codehighlighter1_368_565_Open_Image.style.display='inline'; Codehighlighter1_368_565_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_368_565_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_368_565_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;len</span><span style="COLOR: #000000">*=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">len;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%1d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">s[i]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">len;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sum[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">s[i];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;fbi(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,len);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</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></span></div>
<img src ="http://www.cppblog.com/rakerichard/aggbug/104965.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/rakerichard/" target="_blank">lee1r</a> 2010-01-06 19:14 <a href="http://www.cppblog.com/rakerichard/archive/2010/01/06/104965.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>