﻿<?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++博客-51isoft's ACM Journey</title><link>http://www.cppblog.com/51isoft/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 14 Apr 2026 23:06:15 GMT</lastBuildDate><pubDate>Tue, 14 Apr 2026 23:06:15 GMT</pubDate><ttl>60</ttl><item><title>PKU 3076 Sudoku Dancing Links (DLX) 果然很生猛……</title><link>http://www.cppblog.com/51isoft/archive/2009/07/28/91401.html</link><dc:creator>51isoft</dc:creator><author>51isoft</author><pubDate>Mon, 27 Jul 2009 18:37:00 GMT</pubDate><guid>http://www.cppblog.com/51isoft/archive/2009/07/28/91401.html</guid><wfw:comment>http://www.cppblog.com/51isoft/comments/91401.html</wfw:comment><comments>http://www.cppblog.com/51isoft/archive/2009/07/28/91401.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/51isoft/comments/commentRss/91401.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/51isoft/services/trackbacks/91401.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Sudoku                        Time Limit:&nbsp;10000MS                        Memory Limit:&nbsp;65536K                            Total Submissions:&nbsp;638                  ...&nbsp;&nbsp;<a href='http://www.cppblog.com/51isoft/archive/2009/07/28/91401.html'>阅读全文</a><img src ="http://www.cppblog.com/51isoft/aggbug/91401.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/51isoft/" target="_blank">51isoft</a> 2009-07-28 02:37 <a href="http://www.cppblog.com/51isoft/archive/2009/07/28/91401.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>TOPCODER SRM405 DIV1 250分题 Relative Path</title><link>http://www.cppblog.com/51isoft/archive/2008/11/13/66852.html</link><dc:creator>51isoft</dc:creator><author>51isoft</author><pubDate>Thu, 13 Nov 2008 12:37:00 GMT</pubDate><guid>http://www.cppblog.com/51isoft/archive/2008/11/13/66852.html</guid><wfw:comment>http://www.cppblog.com/51isoft/comments/66852.html</wfw:comment><comments>http://www.cppblog.com/51isoft/archive/2008/11/13/66852.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/51isoft/comments/commentRss/66852.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/51isoft/services/trackbacks/66852.html</trackback:ping><description><![CDATA[
崩溃了&#8230;&#8230;这个破题写了这么久&#8230;&#8230;&#8230;&#8230;但是确实自己要注意这些字符串处理的问题&#8230;&#8230;&#8230;&#8230;<div><span style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><font color="#ffffff">4eZepuWr</font></span><br><div>
<table>
    <tbody>
        <tr>
            <td colspan="2" class="statText">
            <h3>Problem Statement</h3>
            </td>
        </tr>
        <tr>
            <td class="statText">&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td class="statText">
            <p>In
            a typical filesystem, there are files, representing complete units of
            data. These files are contained in directories, and these directories,
            in turn, may be contained in other directories, and so on. A <em>path</em> is a pointer to a specific file or directory in this stucture. Most Unix-like OSes have a single <em>root</em>
            directory, that has all other directories and files directly or
            indirectly (via other directories) inside it. Such OSes use the
            following structure for file paths:</p>
            <p>/&lt;directory-name&gt;/&lt;directory-name&gt;/.../&lt;directory-name&gt;/&lt;file-name&gt;</p>
            <p>and, correspondingly, the following structure for directory paths:</p>
            <p>/&lt;directory-name&gt;/&lt;directory-name&gt;/.../&lt;directory-name&gt;</p>
            <p>For example, "/etc/passwd" (all quotes here and below are for
            clarity only) points to a file named "passwd" inside a directory named
            "etc" inside the root directory. Other valid file names might be
            "/home/user/pictures/me" or just "/file". In this problem, we allow
            only nonempty sequences of lowercase letters ('a'-'z') as file and
            directory names.</p>
            <p>A special case is the root directory itself, which is referred to as just "/".</p>
            <p>When a user works with such an OS, one of the directories is chosen
            as 'current'. Such a designation allows her to refer to the files in
            that directory without specifying the full path to the current
            directory. For example, if the current directory is
            "/home/user/pictures", then one might refer to the file
            "/home/user/pictures/me" as just "me" (note that such a short form can
            be easily spotted by the absence of the starting '/' character).
            Moreover, the files in subdirectories of the current directory can also
            be referred to in a short manner: "/home/user/pictures/others/she" can
            be referred to as "others/she".</p>
            <p>And even more exciting is the ability to have short references for
            files outside the current folder. More specifically, ".." means "the
            directory one level above the current directory", "../.." means "the
            directory two levels above the current directory", and so on. For
            example, if the current directory is "/home/user/pictures", and you
            want to refer to "/home/top/data/file", you can express that as
            "../../top/data/file".</p>
            <p>Given a String <strong>path</strong>, indicating the complete path to the file that needs to be referred to, and a String <strong>currentDir</strong>,
            indicating the current directory, return a String that contains the
            relative path to that file according to the above rules. You should
            choose the shortest of all possible relative paths (for example, if the
            current directory is "/home/user/pictures", you should use
            "../movies/title" and not "../../user/movies/title" as a pointer to
            "/home/user/movies/title").</p>
            <p>Some files and/or directories may have coinciding names, but it is
            impossible to have two files or two directories or a file and a
            directory with the same name inside the same directory, so file and
            directory paths are not ambiguous. It is guaranteed that the given data
            describes a valid file and directory according to the above rules. In
            particular, they will not contradict - for example, <strong>path</strong>="/home/user/some" and <strong>currentDir</strong>="/home/user/some/other"
            are a contradiction, since it implies that a file and a directory both
            named "some" exist inside the directory "/home/user".</p>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="statText">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2" class="statText">
            <h3>Definition</h3>
            </td>
        </tr>
        <tr>
            <td class="statText">&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td class="statText">
            <table>
                <tbody>
                    <tr>
                        <td class="statText">Class:</td>
                        <td class="statText">RelativePath</td>
                    </tr>
                    <tr>
                        <td class="statText">Method:</td>
                        <td class="statText">makeRelative</td>
                    </tr>
                    <tr>
                        <td class="statText">Parameters:</td>
                        <td class="statText">String, String</td>
                    </tr>
                    <tr>
                        <td class="statText">Returns:</td>
                        <td class="statText">String</td>
                    </tr>
                    <tr>
                        <td class="statText">Method signature:</td>
                        <td class="statText">String makeRelative(String path, String currentDir)</td>
                    </tr>
                    <tr>
                        <td colspan="2" class="statText">(be sure your method is public)</td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
        <tr>
            <td class="statText">&nbsp;&nbsp;&nbsp;&nbsp;</td>
        </tr>
        <tr>
            <td class="statText"><br></td>
        </tr>
        <tr>
            <td colspan="2" class="statText">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2" class="statText">
            <h3>Notes</h3>
            </td>
        </tr>
        <tr>
            <td class="statText" align="center" valign="top">-</td>
            <td class="statText">A
            file name never ends with the '/' character. A directory name never
            ends with the '/' character, with the exception of the root directory,
            which is specified as just "/".</td>
        </tr>
        <tr>
            <td colspan="2" class="statText">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2" class="statText">
            <h3>Constraints</h3>
            </td>
        </tr>
        <tr>
            <td class="statText" align="center" valign="top">-</td>
            <td class="statText"><strong>path</strong> and <strong>currentDir</strong> will each contain between 1 and 50 characters, inclusive.</td>
        </tr>
        <tr>
            <td class="statText" align="center" valign="top">-</td>
            <td class="statText">Each character of <strong>path</strong> and <strong>currentDir</strong> will be '/', or a lowercase letter ('a'-'z').</td>
        </tr>
        <tr>
            <td class="statText" align="center" valign="top">-</td>
            <td class="statText"><strong>path</strong> will contain a valid file path according to the above rules.</td>
        </tr>
        <tr>
            <td class="statText" align="center" valign="top">-</td>
            <td class="statText"><strong>currentDir</strong> will contain a valid directory path according to the above rules.</td>
        </tr>
        <tr>
            <td class="statText" align="center" valign="top">-</td>
            <td class="statText"><strong>path</strong> and <strong>currentDir</strong> will not contradict (see the last paragraph of the statement).</td>
        </tr>
        <tr>
            <td colspan="2" class="statText">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2" class="statText">
            <h3>Examples</h3>
            </td>
        </tr>
        <tr>
            <td class="statText" align="center" nowrap="true">0)</td>
            <td class="statText"><br></td>
        </tr>
        <tr>
            <td class="statText">&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td class="statText">
            <table>
                <tbody>
                    <tr>
                        <td class="statText">
                        <table>
                            <tbody>
                                <tr>
                                    <td class="statText">
                                    <pre>"/home/top/data/file"</pre>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="statText">
                                    <pre>"/home/user/pictures"</pre>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                    <tr>
                        <td class="statText">
                        <pre>Returns: "../../top/data/file"</pre>
                        </td>
                    </tr>
                    <tr>
                        <td class="statText">
                        <table>
                            <tbody>
                                <tr>
                                    <td colspan="2" class="statText">The example from the problem statement.</td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
        <tr>
            <td class="statText" align="center" nowrap="true">1)</td>
            <td class="statText"><br></td>
        </tr>
        <tr>
            <td class="statText">&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td class="statText">
            <table>
                <tbody>
                    <tr>
                        <td class="statText">
                        <table>
                            <tbody>
                                <tr>
                                    <td class="statText">
                                    <pre>"/home/user/movies/title"</pre>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="statText">
                                    <pre>"/home/user/pictures"</pre>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                    <tr>
                        <td class="statText">
                        <pre>Returns: "../movies/title"</pre>
                        </td>
                    </tr>
                    <tr>
                        <td class="statText">
                        <table>
                            <tbody>
                                <tr>
                                    <td colspan="2" class="statText">And another one from the statement.</td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
        <tr>
            <td class="statText" align="center" nowrap="true">2)</td>
            <td class="statText"><br></td>
        </tr>
        <tr>
            <td class="statText">&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td class="statText">
            <table>
                <tbody>
                    <tr>
                        <td class="statText">
                        <table>
                            <tbody>
                                <tr>
                                    <td class="statText">
                                    <pre>"/file"</pre>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="statText">
                                    <pre>"/"</pre>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                    <tr>
                        <td class="statText">
                        <pre>Returns: "file"</pre>
                        </td>
                    </tr>
                    <tr>
                        <td class="statText">
                        <table>
                            <tbody>
                                <tr>
                                    <td colspan="2" class="statText">Remember about the root directory.</td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
        <tr>
            <td class="statText" align="center" nowrap="true">3)</td>
            <td class="statText"><br></td>
        </tr>
        <tr>
            <td class="statText">&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td class="statText">
            <table>
                <tbody>
                    <tr>
                        <td class="statText">
                        <table>
                            <tbody>
                                <tr>
                                    <td class="statText">
                                    <pre>"/a/b/a/b/a/b"</pre>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="statText">
                                    <pre>"/a/b/a/a/b/a/b"</pre>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                    <tr>
                        <td class="statText">
                        <pre>Returns: "../../../../b/a/b"</pre>
                        </td>
                    </tr>
                    <tr>
                        <td class="statText">
                        <table>
                            <tbody>
                                <tr>
                                    <td colspan="2" class="statText">Some file and directory names may be the same.</td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
        <tr>
            <td class="statText" align="center" nowrap="true">4)</td>
            <td class="statText"><br></td>
        </tr>
        <tr>
            <td class="statText">&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td class="statText">
            <table>
                <tbody>
                    <tr>
                        <td class="statText">
                        <table>
                            <tbody>
                                <tr>
                                    <td class="statText">
                                    <pre>"/root/root/root"</pre>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="statText">
                                    <pre>"/root"</pre>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                    <tr>
                        <td class="statText">
                        <pre>Returns: "root/root"</pre>
                        </td>
                    </tr>
                    <tr>
                        <td class="statText">
                        <table>
                            <tbody>
                                <tr>
                                    <td colspan="2" class="statText">Some files and/or directories can be named "root" - but that doesn't make them root directories.</td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>
<br><br>代码：<br>
<div style="border-left-color: rgb(204, 204, 204); padding-top: 4px; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%; "><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#include&nbsp;</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&nbsp;</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&nbsp;</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&nbsp;</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&nbsp;</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&nbsp;</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&nbsp;</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&nbsp;</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&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">functional</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br>#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">numeric</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br>#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">utility</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br>#include&nbsp;</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&nbsp;</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&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">iomanip</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br>#include&nbsp;</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&nbsp;</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&nbsp;</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&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">ctime</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br><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;">class</span><span style="color: #000000;">&nbsp;RelativePath&nbsp;{<br></span><span style="color: #0000ff;">public</span><span style="color: #000000;">:<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">&nbsp;makeRelative(</span><span style="color: #0000ff;">string</span><span style="color: #000000;">,&nbsp;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">);<br>};<br><br></span><span style="color: #0000ff;">string</span><span style="color: #000000;">&nbsp;RelativePath::makeRelative(</span><span style="color: #0000ff;">string</span><span style="color: #000000;">&nbsp;path,&nbsp;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">&nbsp;cD)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;sz1</span><span style="color: #000000;">=</span><span style="color: #000000;">path.size();<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;sz2</span><span style="color: #000000;">=</span><span style="color: #000000;">cD.size();<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;td1</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;td2</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;i;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;cloc,cdepth</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">,tmp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">&nbsp;ret</span><span style="color: #000000;">=</span><span style="color: #000000;">""</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</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;">sz1;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(path[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;">)&nbsp;td1</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(sz1</span><span style="color: #000000;">==</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;td1</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</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;">sz2;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(cD[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;">)&nbsp;td2</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(sz2</span><span style="color: #000000;">==</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;td2</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</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;">sz2;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;">&nbsp;(path[i]</span><span style="color: #000000;">!=</span><span style="color: #000000;">cD[i])&nbsp;</span><span style="color: #0000ff;">break</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;">&nbsp;(path[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;">)&nbsp;cdepth</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(i</span><span style="color: #000000;">==</span><span style="color: #000000;">sz2</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">sz2</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">sz1</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">path[sz2]</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;">)&nbsp;cdepth</span><span style="color: #000000;">--</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(i</span><span style="color: #000000;">!=</span><span style="color: #000000;">sz2)&nbsp;cdepth</span><span style="color: #000000;">--</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(i</span><span style="color: #000000;">==</span><span style="color: #000000;">0</span><span style="color: #000000;">||</span><span style="color: #000000;">sz2</span><span style="color: #000000;">==</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;cdepth</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</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;">td2</span><span style="color: #000000;">-</span><span style="color: #000000;">cdepth;i</span><span style="color: #000000;">++</span><span style="color: #000000;">)&nbsp;ret</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;tmp</span><span style="color: #000000;">=-</span><span style="color: #000000;">1</span><span style="color: #000000;">;cloc</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</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;">sz1</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">tmp</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">cdepth;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;">&nbsp;(path[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;">)&nbsp;tmp</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cloc</span><span style="color: #000000;">=</span><span style="color: #000000;">i;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;ret</span><span style="color: #000000;">+=</span><span style="color: #000000;">path.substr(cloc</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;">return</span><span style="color: #000000;">&nbsp;ret;<br>}<br><br><br></span><span style="color: #008000;">//</span><span style="color: #008000;">Powered&nbsp;by&nbsp;[KawigiEdit]&nbsp;2.0!</span></div>
<br>
</div></div><img src ="http://www.cppblog.com/51isoft/aggbug/66852.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/51isoft/" target="_blank">51isoft</a> 2008-11-13 20:37 <a href="http://www.cppblog.com/51isoft/archive/2008/11/13/66852.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PKU2318 TOYS</title><link>http://www.cppblog.com/51isoft/archive/2008/09/18/62201.html</link><dc:creator>51isoft</dc:creator><author>51isoft</author><pubDate>Thu, 18 Sep 2008 09:45:00 GMT</pubDate><guid>http://www.cppblog.com/51isoft/archive/2008/09/18/62201.html</guid><wfw:comment>http://www.cppblog.com/51isoft/comments/62201.html</wfw:comment><comments>http://www.cppblog.com/51isoft/archive/2008/09/18/62201.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/51isoft/comments/commentRss/62201.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/51isoft/services/trackbacks/62201.html</trackback:ping><description><![CDATA[<p class=pst>Description</p>
<div class=ptx lang=en-US>Calculate the number of toys that land in each bin of a partitioned toy box. <br>Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave John a rectangular box to put his toys in, but John is rebellious and obeys his parents by simply throwing his toys into the box. All the toys get mixed up, and it is impossible for John to find his favorite toys. <br><br>John's parents came up with the following idea. They put cardboard partitions into the box. Even if John keeps throwing his toys into the box, at least toys that get thrown into different bins stay separated. The following diagram shows a top view of an example toy box. <br><img src="http://acm.pku.edu.cn/JudgeOnline/images/2318_1.jpg"> <br>For this problem, you are asked to determine how many toys fall into each partition as John throws them into the toy box.</div>
<p class=pst>Input</p>
<div class=ptx lang=en-US>The input file contains one or more problems. The first line of a problem consists of six integers, n m x1 y1 x2 y2. The number of cardboard partitions is n (0 &lt; n &lt;= 5000) and the number of toys is m (0 &lt; m &lt;= 5000). The coordinates of the upper-left corner and the lower-right corner of the box are (x1,y1) and (x2,y2), respectively. The following n lines contain two integers per line, Ui Li, indicating that the ends of the i-th cardboard partition is at the coordinates (Ui,y1) and (Li,y2). You may assume that the cardboard partitions do not intersect each other and that they are specified in sorted order from left to right. The next m lines contain two integers per line, Xj Yj specifying where the j-th toy has landed in the box. The order of the toy locations is random. You may assume that no toy will land exactly on a cardboard partition or outside the boundary of the box. The input is terminated by a line consisting of a single 0.</div>
<p class=pst>Output</p>
<div class=ptx lang=en-US>The output for each problem will be one line for each separate bin in the toy box. For each bin, print its bin number, followed by a colon and one space, followed by the number of toys thrown into that bin. Bins are numbered from 0 (the leftmost bin) to n (the rightmost bin). Separate the output of different problems by a single blank line.</div>
<p class=pst>Sample Input</p>
<pre class=sio>5 6 0 10 60 0
3 1
4 3
6 8
10 10
15 30
1 5
2 1
2 8
5 5
40 10
7 9
4 10 0 10 100 0
20 20
40 40
60 60
80 80
5 10
15 10
25 10
35 10
45 10
55 10
65 10
75 10
85 10
95 10
0
</pre>
<p class=pst>Sample Output</p>
<pre class=sio>0: 2
1: 1
2: 1
3: 1
4: 0
5: 1
0: 2
1: 2
2: 2
3: 2
4: 2
</pre>
<p class=pst>Hint</p>
<div class=ptx lang=en-US>As the example illustrates, toys that fall on the boundary of the box are "in" the box.</div>
<p class=pst>Source</p>
<div class=ptx lang=en-US><a href="http://acm.pku.edu.cn/JudgeOnline/searchproblem?field=source&amp;key=Rocky+Mountain+2003"><u><font color=#0066cc>Rocky Mountain 2003</font></u></a></div>
<br>题意：给出一个盒子以及N条线，把这个格子划分成N+1部分。然后给出一些坐标，统计这些坐标落在各个格子的次数。<br><br>线性规划，左上顶点一定是在每根线的左手边。这样就可以从左到右算出每根线的方程后，拿顶点坐标和当前坐标代入后计算其正负性，第一个同号的时刻就是他所在的格子。<br><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#include&nbsp;</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&nbsp;</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><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,m,x1,y1,x2,y2,x,y;<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;loc[</span><span style="COLOR: #000000">5000</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/None.gif" align=top></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;a[</span><span style="COLOR: #000000">5000</span><span style="COLOR: #000000">],b[</span><span style="COLOR: #000000">5000</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;num[</span><span style="COLOR: #000000">5001</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,j;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;v1,v2;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;pd;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br><img id=Codehighlighter1_167_793_Open_Image onclick="this.style.display='none'; Codehighlighter1_167_793_Open_Text.style.display='none'; Codehighlighter1_167_793_Closed_Image.style.display='inline'; Codehighlighter1_167_793_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_167_793_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_167_793_Closed_Text.style.display='none'; Codehighlighter1_167_793_Open_Image.style.display='inline'; Codehighlighter1_167_793_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_167_793_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_167_793_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">while</span><span style="COLOR: #000000">&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)</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">n)<br><img id=Codehighlighter1_197_780_Open_Image onclick="this.style.display='none'; Codehighlighter1_197_780_Open_Text.style.display='none'; Codehighlighter1_197_780_Closed_Image.style.display='inline'; Codehighlighter1_197_780_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_197_780_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_197_780_Closed_Text.style.display='none'; Codehighlighter1_197_780_Open_Image.style.display='inline'; Codehighlighter1_197_780_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_197_780_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_197_780_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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(m</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;printf(</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(num,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(num));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf&nbsp;(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d&nbsp;%d&nbsp;%d&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">m,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">x1,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">y1,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">x2,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">y2);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_324_448_Open_Image onclick="this.style.display='none'; Codehighlighter1_324_448_Open_Text.style.display='none'; Codehighlighter1_324_448_Closed_Image.style.display='inline'; Codehighlighter1_324_448_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_324_448_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_324_448_Closed_Text.style.display='none'; Codehighlighter1_324_448_Open_Image.style.display='inline'; Codehighlighter1_324_448_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_324_448_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_324_448_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">loc[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">loc[i][</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">(loc[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">loc[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">/</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">(y1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y2);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b[i]</span><span style="COLOR: #000000">=-</span><span style="COLOR: #000000">a[i]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">y1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">loc[i][</span><span style="COLOR: #000000">0</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;&nbsp;}</span></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;</span><span style="COLOR: #0000ff">for</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">m;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_472_723_Open_Image onclick="this.style.display='none'; Codehighlighter1_472_723_Open_Text.style.display='none'; Codehighlighter1_472_723_Closed_Image.style.display='inline'; Codehighlighter1_472_723_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_472_723_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_472_723_Closed_Text.style.display='none'; Codehighlighter1_472_723_Open_Image.style.display='inline'; Codehighlighter1_472_723_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_472_723_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_472_723_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">x,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">y);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pd</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</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;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</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">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_536_697_Open_Image onclick="this.style.display='none'; Codehighlighter1_536_697_Open_Text.style.display='none'; Codehighlighter1_536_697_Closed_Image.style.display='inline'; Codehighlighter1_536_697_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_536_697_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_536_697_Closed_Text.style.display='none'; Codehighlighter1_536_697_Open_Image.style.display='inline'; Codehighlighter1_536_697_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_536_697_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_536_697_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(x</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">loc[j][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">loc[j][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])&nbsp;</span><span style="COLOR: #0000ff">continue</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">a[j]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">y1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">b[j];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">a[j]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">b[j];<br><img id=Codehighlighter1_645_692_Open_Image onclick="this.style.display='none'; Codehighlighter1_645_692_Open_Text.style.display='none'; Codehighlighter1_645_692_Closed_Image.style.display='inline'; Codehighlighter1_645_692_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_645_692_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_645_692_Closed_Text.style.display='none'; Codehighlighter1_645_692_Open_Image.style.display='inline'; Codehighlighter1_645_692_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&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">&nbsp;(v1</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">v2</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;</span><span id=Codehighlighter1_645_692_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_645_692_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pd</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[j]</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">pd)&nbsp;num[n]</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;&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;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d:&nbsp;%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,i,num[i]);<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">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><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<img src ="http://www.cppblog.com/51isoft/aggbug/62201.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/51isoft/" target="_blank">51isoft</a> 2008-09-18 17:45 <a href="http://www.cppblog.com/51isoft/archive/2008/09/18/62201.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PKU1077 Eight</title><link>http://www.cppblog.com/51isoft/archive/2008/09/18/62196.html</link><dc:creator>51isoft</dc:creator><author>51isoft</author><pubDate>Thu, 18 Sep 2008 09:31:00 GMT</pubDate><guid>http://www.cppblog.com/51isoft/archive/2008/09/18/62196.html</guid><wfw:comment>http://www.cppblog.com/51isoft/comments/62196.html</wfw:comment><comments>http://www.cppblog.com/51isoft/archive/2008/09/18/62196.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/51isoft/comments/commentRss/62196.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/51isoft/services/trackbacks/62196.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: DescriptionThe 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, a...&nbsp;&nbsp;<a href='http://www.cppblog.com/51isoft/archive/2008/09/18/62196.html'>阅读全文</a><img src ="http://www.cppblog.com/51isoft/aggbug/62196.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/51isoft/" target="_blank">51isoft</a> 2008-09-18 17:31 <a href="http://www.cppblog.com/51isoft/archive/2008/09/18/62196.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDOJ2185 Chess</title><link>http://www.cppblog.com/51isoft/archive/2008/09/18/62191.html</link><dc:creator>51isoft</dc:creator><author>51isoft</author><pubDate>Thu, 18 Sep 2008 09:20:00 GMT</pubDate><guid>http://www.cppblog.com/51isoft/archive/2008/09/18/62191.html</guid><wfw:comment>http://www.cppblog.com/51isoft/comments/62191.html</wfw:comment><comments>http://www.cppblog.com/51isoft/archive/2008/09/18/62191.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/51isoft/comments/commentRss/62191.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/51isoft/services/trackbacks/62191.html</trackback:ping><description><![CDATA[<div class=panel_title align=left>Problem Description</div>
<div class=panel_content>The Association of Chess Monsters (ACM) is planning their annual team match up against the rest of the world. The match will be on 30 boards, with 15 players playing white and 15 players playing black. ACM has many players to choose from, and they try to pick the best team they can. The ability of each player for playing white is measured on a scale from 1 to 100 and the same for playing black. During the match a player can play white or black but not both. The value of a team is the total of players' abilities to play white for players designated to play white and players' abilities to play black for players designated to play black. ACM wants to pick up a team with the highest total value. <br></div>
<div class=panel_bottom>&nbsp;</div>
<br>
<div class=panel_title align=left>Input</div>
<div class=panel_content>Input consists of a sequence of lines giving players' abilities. Each line gives the abilities of a single player by two integer numbers separated by a single space. The first number is the player's ability to play white and the second is the player's ability to play black. There will be no less than 30 and no more than 1000 lines on input. <br></div>
<div class=panel_bottom>&nbsp;</div>
<br>
<div class=panel_title align=left>Output</div>
<div class=panel_content>Output a single line containing an integer number giving the value of the best chess team that ACM can assemble. <br></div>
<div class=panel_bottom>&nbsp;</div>
<br>
<div class=panel_title align=left>Sample Input</div>
<div class=panel_content>
<pre>87 84
66 78
86 94
93 87
72 100
78 63
60 91
77 64
77 91
87 73
69 62
80 68
81 83
74 63
86 68
53 80
59 73
68 70
57 94
93 62
74 80
70 72
88 85
75 99
71 66
77 64
81 92
74 57
71 63
82 97
76 56</pre>
</div>
<div class=panel_bottom>&nbsp;</div>
<br>
<div class=panel_title align=left>Sample Output</div>
<div class=panel_content>
<pre>2506</pre>
</div>
<div class=panel_bottom>&nbsp;</div>
<br>题意大概是在一堆人里选择30个人（一半执黑，另一半执白），使棋力和最大。<br><br>算法：DP。f[i][j][k]表示前i个人中选j个执黑k个执白的最大棋力。<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&nbsp;</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&nbsp;</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><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;f[</span><span style="COLOR: #000000">2000</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">16</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">16</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;a[</span><span style="COLOR: #000000">2000</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/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><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;i,j,k;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br><img id=Codehighlighter1_108_1191_Open_Image onclick="this.style.display='none'; Codehighlighter1_108_1191_Open_Text.style.display='none'; Codehighlighter1_108_1191_Closed_Image.style.display='inline'; Codehighlighter1_108_1191_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_108_1191_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_108_1191_Closed_Text.style.display='none'; Codehighlighter1_108_1191_Open_Image.style.display='inline'; Codehighlighter1_108_1191_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_108_1191_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_108_1191_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;n</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">&nbsp;(scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[n][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">],</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a[n][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">EOF)&nbsp;n</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">for</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">16</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;f[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">0</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">&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">16</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;f[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">0</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">for</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><img id=Codehighlighter1_287_1139_Open_Image onclick="this.style.display='none'; Codehighlighter1_287_1139_Open_Text.style.display='none'; Codehighlighter1_287_1139_Closed_Image.style.display='inline'; Codehighlighter1_287_1139_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_287_1139_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_287_1139_Closed_Text.style.display='none'; Codehighlighter1_287_1139_Open_Image.style.display='inline'; Codehighlighter1_287_1139_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_287_1139_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_287_1139_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;</span><span style="COLOR: #0000ff">for</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">16</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_324_1133_Open_Image onclick="this.style.display='none'; Codehighlighter1_324_1133_Open_Text.style.display='none'; Codehighlighter1_324_1133_Closed_Image.style.display='inline'; Codehighlighter1_324_1133_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_324_1133_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_324_1133_Closed_Text.style.display='none'; Codehighlighter1_324_1133_Open_Image.style.display='inline'; Codehighlighter1_324_1133_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_324_1133_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_324_1133_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</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">16</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_369_1123_Open_Image onclick="this.style.display='none'; Codehighlighter1_369_1123_Open_Text.style.display='none'; Codehighlighter1_369_1123_Closed_Image.style.display='inline'; Codehighlighter1_369_1123_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_369_1123_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_369_1123_Closed_Text.style.display='none'; Codehighlighter1_369_1123_Open_Image.style.display='inline'; Codehighlighter1_369_1123_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_369_1123_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_369_1123_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(j</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;f[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][k]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">f[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">][k]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">a[i][</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(k</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;f[i][j][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">a[i][</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(j</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(f[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">][k]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">a[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j][k])&nbsp;<br><img id=Codehighlighter1_598_719_Open_Image onclick="this.style.display='none'; Codehighlighter1_598_719_Open_Text.style.display='none'; Codehighlighter1_598_719_Closed_Image.style.display='inline'; Codehighlighter1_598_719_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_598_719_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_598_719_Closed_Text.style.display='none'; Codehighlighter1_598_719_Open_Image.style.display='inline'; Codehighlighter1_598_719_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_598_719_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_598_719_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(f[i][j][k]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">f[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">][k]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">a[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])&nbsp;f[i][j][k]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">f[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">][k]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">a[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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">&nbsp;(f[i][j][k]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j][k])&nbsp;f[i][j][k]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j][k];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(k</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j][k</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">a[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j][k])&nbsp;<br><img id=Codehighlighter1_909_1030_Open_Image onclick="this.style.display='none'; Codehighlighter1_909_1030_Open_Text.style.display='none'; Codehighlighter1_909_1030_Closed_Image.style.display='inline'; Codehighlighter1_909_1030_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_909_1030_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_909_1030_Closed_Text.style.display='none'; Codehighlighter1_909_1030_Open_Image.style.display='inline'; Codehighlighter1_909_1030_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_909_1030_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_909_1030_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(f[i][j][k]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j][k</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">a[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])&nbsp;f[i][j][k]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j][k</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">a[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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">&nbsp;(f[i][j][k]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j][k])&nbsp;f[i][j][k]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j][k];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&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">%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,f[n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">15</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">15</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">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/51isoft/aggbug/62191.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/51isoft/" target="_blank">51isoft</a> 2008-09-18 17:20 <a href="http://www.cppblog.com/51isoft/archive/2008/09/18/62191.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>