﻿<?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/menjitianya/category/20878.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 07 Aug 2014 10:55:08 GMT</lastBuildDate><pubDate>Thu, 07 Aug 2014 10:55:08 GMT</pubDate><ttl>60</ttl><item><title>Southeastern Europe 2004 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/08/06/207926.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Wed, 06 Aug 2014 13:23:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/08/06/207926.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207926.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/08/06/207926.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207926.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207926.html</trackback:ping><description><![CDATA[<p><div style="text-align: center;"><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/souer2004.png" width="907" height="206" alt="" /></span></strong></div><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A. Period</span></strong></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">PKU 1961 <a href="http://poj.org/problem?id=1961">http://poj.org/problem?id=1961</a></span></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一个长度为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 10<sup>6</sup>)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的字符串</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，求它的所有前缀中能够表示成</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">A<sup>K</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的前缀，并且要求求出每个前缀对应的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">KMP</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">利用</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">KMP</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">求出该串的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Next</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数组，然后枚举每个前缀，根据</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">Next</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数组的定义，对于某个前缀</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S[1...i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，有</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S[1...Next[i]] = S[i-Next[i]+1...i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，假设前缀</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S[1...i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">能够表示长</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A<sup>K</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的形式，则</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A = S[Next[i]+1...i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，所以必须满足</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">能够被</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i - Next[i] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">整除，满足条件后</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K = i/( i - Next[i])</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p><strong>&nbsp;</strong></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B. Corporative Network</span></strong></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">PKU 1962 <a href="http://poj.org/problem?id=1962">http://poj.org/problem?id=1962</a></span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 20000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">M(M &lt;= 200000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">次操作，每次操作有两种类型：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I a b&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">将</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">a</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的父结点设为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">b</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且合并距离为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> |a-b| mod 1000</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E a&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">询问</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">a</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">到根结点的合并距离。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：并查集</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">利用路径压缩的思想，用</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">dist[p]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的父结点的合并距离，每次查询的时候累加</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">到根结点的合并距离，并且将</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">到</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">所在树的根结点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的路径上的所有点的父结点都设为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">R</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，然后更新各自的合并距离。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">合并操作</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">O(1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，查询操作总复杂度</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">O(N)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C. Cave Exploration</span></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">PKU 1963 <a href="http://poj.org/problem?id=1963">http://poj.org/problem?id=1963</a></span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给出</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 1000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">条水平或者垂直的走廊，再给定走廊上任意一个坐标点作为起点以及方向，按照以下策略走：能够左转就左转，不能则笔直走，不能笔直走就右转，都不能就掉头。这样走最后绕一圈又会回到起点，问哪些走廊是没有经过的，只要有一个点走过就算经过。<br /></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="text-indent: 0px; font-family: 宋体;">题解：模拟</span><span style="text-indent: 0px; font-family: 'Times New Roman', serif;"> + </span><span style="text-indent: 0px; font-family: 宋体;">哈希。</span></p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">将水平线段和竖直线段分开存，分两种情况讨论：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、水平线段</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于任意一根水平线段，枚举所有的竖直线段，计算出交点和水平线段的端点，保存下来并且按</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">x</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">坐标递增排序，去掉重复点，利用双向链表将两个相邻点连接起来，由于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">x</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">y</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">坐标范围为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">-32767~32767</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，而交点数不会超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N<sup>2</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，所以可以采用哈希将二维的点映射到一位数组中。每个点记录水平走廊的编号。</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、竖直线段</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">同上操作，不同的是每个点记录竖直走廊的编号。</span></p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">经过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">两步操作后，走廊上的关键点已经被离散化了，并且所有点都通过四向链表串接起来，然后只需要从起点开始模拟行走即可，走到一个关键点，将关键点所在的两个走廊编号标记掉，最后统计没有标记的走廊编号就是答案了。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">D. City Game</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1964 <a href="http://poj.org/problem?id=1964">http://poj.org/problem?id=1964</a></span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">M*N(M &lt;= 1000</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N &lt;= 1000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">01</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">矩阵，求它的一个子矩阵，满足矩阵元素全为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且面积最大。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：枚举行，对于第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">行，以第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">行为起点，扫描每一列</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">j</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，找到第一个不是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的数所在的位置</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">P[j]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，令</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K[j] = P[j] - i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，于是问题转化成了一个一维的问题。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L[i] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> K [ L[i]+1 ... i] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中的元素都大于等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，但是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">小于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R[i] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> K [i ... R[i]-1] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中的元素都大于等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K[i],</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">但是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">小于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Max{&nbsp; (R[i] - L[i] - 1) * K[i],&nbsp; 1 &lt;= i &lt;= N }</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">就是以当前枚举行为起点的最大矩阵，枚举</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">M</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">次取最大值就是全局的最大子矩阵了。</span></p>  <p style="text-indent:21.0pt">&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">E. Cube Root</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1965 <a href="http://poj.org/problem?id=1965">http://poj.org/problem?id=1965</a></span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一个不超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">150</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数字的正整数，求它的三次方根，精确到小数点后</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">10</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">位。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：大数模拟</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">将输入的数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">X</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">用字符串存储，乘上</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">10<sup>30</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，利用二分求出最大的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Y</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，使得</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Y<sup>3 </sup>&lt;= X</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。然后在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Y</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的后十位前插入一个小数点，输出即可。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">F. Cable TV Network</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1966 <a href="http://poj.org/problem?id=1966">http://poj.org/problem?id=1966</a></span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：求图的点连通度。给定一个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 50)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点的图，求去掉至少多少个点能够将它变成一个非连通图。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：搜索</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> + </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">剪枝</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> (</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">或者</span> <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">最大流</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">枚举每个点去掉或不去掉，总共</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2<sup>50</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">种状态，每次去掉点后判断当前图的连通性，一旦破坏了连通，去掉的点数即为答案；如果发现某个点去掉后，剩下点组成的图变成了一个完全图，那么不用继续搜索了，因为当前状态下不可能将剩下的图变成非连通图了；如果去掉的点数超过目前的最优解也直接剪枝。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">好吧</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">...</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一定是数据弱了-_-||，正解是最大流拆点。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">G. Alibaba</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1967 <a href="http://poj.org/problem?id=1967">http://poj.org/problem?id=1967</a></span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 10<sup>4</sup>)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个整数对</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(P<sub>i</sub>, D<sub>i</sub>)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">P<sub>i</sub></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位置有一个宝物，并且需要在</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">D<sub>i</sub> </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时间之前取走</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">给出顺序为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">P<sub>i</sub></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">递增的顺序</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。起始可以任意选择一个位置，往左或者往右取宝物，问是否能够保证每个物品都在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">D<sub>i</sub></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时间之前取走</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时间和距离关系为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1:1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果可以，给出取完所有宝物的最少时间。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：搜索</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> + </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">剪枝</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">首先可以想到的是，起始位置一定是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个宝物所在位置中的其中一个，所以首先可以枚举每个宝物的起始点，比如当前位置为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么在第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">秒内，访问过的区间为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">[pos, pos]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，可以选择往左走，也可以选择往右走，那么是不是只要选择某个方向走完，然后再反方向走到底如果能够满足所有点都在截止时间内完成一定是对的呢？答案是否定的，来看一组数据，如图</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，起始点只能选择</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">3</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">号位置，并且只能选择往右走，走到</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">4</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">后再折回走到</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，然后再折回走到</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">5</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，以此类推，并且只有这一种路径才能满足所有宝物都在截至时间内取完。</span></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/se2004_g1.png" width="373" height="107" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-size:9.0pt;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span><span style="font-size:9.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span></p>  <p align="left"><span style="font-size:9.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">按照这个思路，进行状态的划分，假设当前已经访问的区间为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">[L, R]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且现在的位置处于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位置</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">要么等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，要么等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，所以可以用三维来表示状态</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[s][l][r](l</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">r</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示访问过的区间的左右端点，如果当前位置在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">l</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">则</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">s = 0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果当前位置在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">r</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">s=1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，总共状态数目</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N<sup>2</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，状态转移的时候由大状态推小状态，即</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[s][l][r]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一定是由</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[0][l-1][r]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[0][l][r+1]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[1][l-1][r]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[1][l][r+1]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这四个状态得出。</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">考虑到</span><span style=" font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">比较大，所以把所有状态存储到数组中再利用动态规划进行递推，如果数据量不多的话，可以卡过，但是状态存储需要用滚动数组，否则内存吃不消，也可以采用搜索</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> + </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">剪枝，思路是沿用了动态规划的思想，假设当前已经访问的区间为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">[L, R]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，现在的位置处于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位置</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">要么等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，要么等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且已经使用了</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时间，无论当前的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是在左区间端点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">上还是在右区间端点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">上，他都可以选择走到</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L-1(L &gt; 1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，或者</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R+1(R &lt; N)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，于是就可以递归求解了，递归出口为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L=1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R=N</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时候。</span></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/se2004_g2.png" width="362" height="106" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-size:9.0pt;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span><span style="font-size:9.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如图，已经访问的宝物为红色标记的点，灰色标记的为未曾访问过的，并且现在的位置在已经访问区间的左端点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">上，已经使用了</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时间，我们需要判断这个状态是否合法，则需要满足以下的几个不等式。</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、保证右边未访问的都能在截止时间内访问到：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T + (P[R] - P[L]) +&nbsp; (P[R+1] - P[R])&nbsp; &lt; D[R+1]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T + (P[R] - P[L]) +&nbsp; (P[R+2] - P[R])&nbsp; &lt; D[R+2]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T + (P[R] - P[L]) +&nbsp; (P[N] - P[R])&nbsp; &lt; D[N]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">将这些等式化简，可得：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T - P[L]&nbsp; &lt;&nbsp; D[R+1] - P[R+1]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T - P[L]&nbsp; &lt;&nbsp; D[R+2] - P[R+2]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T - P[L]&nbsp; &lt;&nbsp; D[N] - P[N]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">再进行进一步化简，得：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T - P[L]&nbsp; &lt;&nbsp; Min{ D[k] - P[k],&nbsp; R &lt; k &lt;= N }</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、保证左边未访问的都能在截止时间内访问到：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">同理，可以得出：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T + P[R]&nbsp; &lt;&nbsp; Min{ D[k] + P[k],&nbsp; 1 &lt;= k &lt; R }</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">那么，令</span><span style=" font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> POSTM[i] = Min{ D[k] - P[k],&nbsp; i &lt; k &lt;= N }</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;PREM[i] = Min{ D[k] + P[k],&nbsp; 1 &lt;= k &lt; i }</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这两个数组可以分别通过一次逆序和顺序的线性扫描求出来，用于搜索的时候判断可行性。例如，当</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T - P[L] &gt;= POSTM[R] </span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">表示在右边未访问的宝物中有至少一个宝物不能在截止时间前被访问到，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T + P[R] &gt;= PREM [R]</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">表示在左边未访问的宝物中有至少一个宝物不能在截止时间前被访问到，直接剪枝。</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">还需要一个剪枝，就是在当前时间</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">加上<strong><span style="color:red">当前状态下预计访问完所有宝物的最小时间</span></strong>已经比之前求出的最小时间大，直接剪枝。</span></p>  <p align="left">&nbsp;</p>  <p align="left"><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">H . Booklets</span></strong></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1968 <a href="http://poj.org/problem?id=1968">http://poj.org/problem?id=1968</a></span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：</span><span style=" font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 3000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">本小册子需要分配给</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个学校，每个学校得到的是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N/S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的上整本册子或者</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N/S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的下整本册子，每本册子有一个页数，并且规定分配册子的时候按照页数递增来分配，先把上整本册子分完再分下整的，对于每个学校的分书规则，按照输入的顺序进行分配。求问第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个学校分到的第一本册子的页数。</span></p>  <p align="left">&nbsp;</p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：需要求出几个量：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">上整册子的数目</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">UIP = (N+S-1) / S;</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">下整册子的数目</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">LIP = N/S;</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分到上整册子数目的学校个数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">UIPC = N % S;</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分到下整册子数目的学校个数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">LIPC = N - N % S;</span></p>  <p align="left">&nbsp;</p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">首先对所有的册子按页数递增来排序</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果页数相同按照下标递增排序</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，然后减去前</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T-1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个学校的册子总数，容易得出第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个学校分到的册子数目</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，从接下来的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个册子中找到之前下标最小的册子，它对应的页数就是答案。</span></p>  <p align="left">&nbsp;</p>  <p align="left"><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">I. Count on Canton</span></strong></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1969 <a href="http://poj.org/problem?id=1969">http://poj.org/problem?id=1969</a></span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定下图所示的无限分数序列，并且按照蛇形方式编号，即第一个为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1/1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，第二个为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1/2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，第三个为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2/1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，第四个为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">3/1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，以此类推，问第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个分数是什么。</span></p>  <pre><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1/1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1/2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1/3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1/4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  1/5 ...</span></pre><pre><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2/1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2/2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2/3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2/4</span></pre><pre><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3/1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3/2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3/3</span></pre><pre><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4/1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4/2</span></pre><pre><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5/1</span></pre><pre><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp; </span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">题解：数学题。</span></pre><pre><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp; </span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">首先二分求出在第几条斜线上，即</span><span style="font-size: 10.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">(K-1)K/2 &lt; N</span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">的最大的</span><span style="font-size:10.5pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">K</span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">，然后求根据</span><span style="font-size:10.5pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">K</span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">的奇偶性求出蛇形在第</span><span style="font-size:10.5pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">K</span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">条斜线的行走方向，第</span><span style="font-size:10.5pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">N - (K-1)K/2 </span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">个数就是答案。</span></pre><pre>&nbsp;</pre><img src ="http://www.cppblog.com/menjitianya/aggbug/207926.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-08-06 21:23 <a href="http://www.cppblog.com/menjitianya/archive/2014/08/06/207926.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>South Central USA 2002 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/07/31/207869.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Thu, 31 Jul 2014 03:31:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/07/31/207869.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207869.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/07/31/207869.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207869.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207869.html</trackback:ping><description><![CDATA[<p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><div align="center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/soutcenusa2002.png" width="950" height="160" alt="" /></div><br />A . The Hardest Problem Ever</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1298 <a href="http://poj.org/problem?id=1298">http://poj.org/problem?id=1298</a></span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;">题意：解码题，按照如下对应关系解码：</span></p>  <p><span style="font-size: 11.5pt; font-family: 'Times New Roman', serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 11.5pt; font-family: 宋体;">密文</span><span style="font-size: 11.5pt; font-family: 'Times New Roman', serif;"> A B C D E F G H I J K L M N O P Q R S T U V W X Y Z&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 11.5pt; font-family: 宋体;">原文</span><span style="font-size: 11.5pt; font-family: 'Times New Roman', serif;"> V W X Y Z A B C D E F G H I J K L M N O P Q R S T U&nbsp;</span><a href="http://poj.org/problem?id=1299"></a></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：简单题。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B. Polar Explorer</span></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">PKU 1299 </span><a href="http://poj.org/problem?id=1299"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">http://poj.org/problem?id=1299</span></a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定圆的半径</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;;">X</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，求圆周上两个点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">A</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">B</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的距离，其中圆心角</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">AOB</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的角度为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">Z(0 &lt;= Z &lt;= 360)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：核心是</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;;">Z</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">如果大于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">180</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，则</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">Z = 360 - Z</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，即走劣弧。而且题目求的是来回一次，所以计算的时候弧长要乘</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">。</span></p>  <p><strong>&nbsp;</strong></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C. Door Man</span></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">PKU 1300 </span><a href="http://poj.org/problem?id=1300"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">http://poj.org/problem?id=1300</span></a><strong></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定一些边和起点</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;;">s</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，求能否找到一条从</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">s</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">到</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的通路，并且要求访问所有的边。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：欧拉回路可行解判定。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">首先利用</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">flood fill</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">从</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">s</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">遍历全图，如果</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">点没有被访问到则必定不存在；然后判断度数不为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的点是否有未被访问到的，如果有，说明图不连通，也必定不存在解；最后统计度数为奇数的点的个数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">P</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，以及具体的点：</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">1)&nbsp; P = 0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，则必定有解；</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">2)&nbsp; P &gt; 2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，则无解；</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">3)&nbsp; P =2, </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">那么有解的前提是两个奇度数点中一个是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">s</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，另一个是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">；否则无解。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">D . The Umbrella Problem 2054</span></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">PKU 1301 </span><a href="http://poj.org/problem?id=1301"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">http://poj.org/problem?id=1301</span></a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定一个</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;;">10X10</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的地图，玩家从第一行的某一个点出发，每一步行编号</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">+1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，列编号增量有三种选择</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">(-1, 0, 1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，图中标记为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">S(laser gun)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的点不能走，并且</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的点会发出镭射光，第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">秒朝上发射，第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">秒朝右，第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">秒朝下，第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">3</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">秒朝左，循环往复，发射长度一直到地图边缘。问能否走到最后一行标记为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">G(grass)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的地方。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：广搜。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">hash[4][R][C]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">表示状态，每走一步，利用步数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;"> mod 4</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">计算出镭射光的方向，然后将所有的镭射光可达区域全部标记出来，未标记的点为可达点，枚举三个方向进行搜索。<br /><br /></span></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">E. Blue Gene, Jr.</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1302 </span><a href="http://poj.org/problem?id=1302"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">http://poj.org/problem?id=1302</span></a></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：一个长度为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 20)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的病毒基因串</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A[1...N]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">进行变异，变异过程从左往右，分情况讨论：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个字符是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> A-Z</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则它将变异成数字</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">n mod 10</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">n</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A[i+1...N]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中变异基因的数目；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个字符是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> 1-9</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则它变异成</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A[i] - 1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且如果第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p (p = i + A[i])</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个基因存在的话，从第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个基因开始变异；否则从第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i+1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个基因开始变异；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：题意理解后就是个水题了，递归求解。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">F . Byte Me!</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1303 </span><a href="http://poj.org/problem?id=1303"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">http://poj.org/problem?id=1303</span></a></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：二进制二十一点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">二进制黑杰克</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是由两种牌组成的游戏，一种称为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">bytes(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">8</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">比特的序列表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">0-255</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">之间的数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，一种称为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">nibbles((</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">4</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">比特的序列表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">0-15</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">之间的数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，游戏玩法如下：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">游戏的目标是获得尽量接近</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分，并且不能超过它；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每个玩家有两张牌，一张面朝上，一张面朝下</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">庄家不知道是什么牌</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每个玩家有四次叫牌机会，可以叫</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">bytes</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，也可以叫</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">nibbles</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，但是如果分数超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">则不能再叫牌；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">所有的叫牌都是面朝上的；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果玩家分数超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，立即判为输；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">庄家最后一个叫牌；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">平局的情况庄家胜</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果所有人都超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分，庄家还是赢的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:red">庄家的规则</span></strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如下：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">当看到自己和其他人面朝上的牌，判断已经必胜时不要再叫牌了；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果总分小于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">382</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">需要叫一次</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">byte</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">牌；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果总分小于等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">500</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">需要叫一次</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">nibble</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">牌；</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">还有两个隐藏规则：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">你是庄家；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每个非庄家的玩家面朝下的牌是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">11111111</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（但是庄家不知道），面朝上的牌给定；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">非庄家不会叫牌</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">因为他们比较笨</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">给定庄家的牌和其他玩家面朝上的牌，以及牌堆中的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">bytes</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">牌和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">nibble</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">牌，求庄家的四次叫牌能否获胜；</span></p>  <p>&nbsp;</p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：题目说了一大堆，最后非庄家的玩家都不会叫牌，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">o(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#9583;&#9633;&#9584;</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)o...</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">所以只要根据庄家的规则进行叫牌，然后判断是否能够胜出即可；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">因为其他人都不叫牌，每个人都有两张牌，所以其他人的总分不可能超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分，所以，如果庄家叫牌超过</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分直接被判为负。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每次叫牌前先判断所有玩家的朝上的卡片分数加上</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">255</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和庄家当前得分进行比较，如果有一个玩家分数大于庄家分数，则庄家按照</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">382</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">500</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这两个区间进行叫牌。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">四次叫牌结束，如果所有玩家分数都小于等于庄家分数，则判断庄家分数是否大于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果是，输出</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Bust!</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，否则输出</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Win!</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；如果小于某个玩家的分数，那么输出</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">Lose!</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">G . World's Worst Bus Schedule</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1304 </span><a href="http://poj.org/problem?id=1304"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">http://poj.org/problem?id=1304</span></a></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：公交车站有</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 20)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">辆车，每辆车的发车时间间隔为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">a1 a2 a3 a4... a1 a2 a3 a4... a1 a2 a3 a4...</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，循环发车，问某人在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时刻赶到公交车站，最少需要等待多少时间能够乘上公交车。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：对于每辆公交车，设它的所有时间间隔之和为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，令</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T' = T mod S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，然后枚举所有的发车间隔，前</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个发车间隔</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">a[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">之和减去</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T'</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中的最小正值就是等这辆公交车需要的时间，取所有公交车的最小时间就是所求。</span></p>  <p>&nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207869.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-07-31 11:31 <a href="http://www.cppblog.com/menjitianya/archive/2014/07/31/207869.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ulm local 1998 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/07/19/207722.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sat, 19 Jul 2014 14:42:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/07/19/207722.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207722.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/07/19/207722.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207722.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207722.html</trackback:ping><description><![CDATA[<p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="text-align: center; margin-bottom: 0pt; margin-top: 0pt;">&nbsp;<img src="http://www.cppblog.com/images/cppblog_com/menjitianya/ulm1998.png" width="860" height="183" alt="" /></p><p style="margin-bottom:0pt; margin-top:0pt; "><br /></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">A</span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">.&nbsp;</span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">Artificial&nbsp;Intelligence?</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">2256</span>&nbsp;<a href="http://poj.org/problem?id=2256"><span style="color: #0000ff; font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2256</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：功率的计算公式为P&nbsp;=&nbsp;UI</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">，给定一句话，这句话中一定会包含三个变量中的两个，求另外一个，并且单位会有三种前缀m(毫)，k(千)，M(兆)。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：字符串扫描。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">gets读入字符串，进行一次遍历，查找是否包含子串</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8217;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">P=</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8217;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">,&nbsp;</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8216;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">U=</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8217;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">,&nbsp;</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8216;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">I=</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8217;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">,&nbsp;格式化它后面的数字，需要用double来存，然后检查单位前缀，m需要将原值除上10</span><span style="font-size: 10.5pt; font-family: 宋体; vertical-align: super; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">3</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">，k需要将原值乘上10</span><span style="font-size: 10.5pt; font-family: 宋体; vertical-align: super; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">3</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">，M需要将原值常上10</span><span style="font-size: 10.5pt; font-family: 宋体; vertical-align: super; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">6</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">。然后分三种情况计算未知的那个值即可。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">B.&nbsp;Balancing&nbsp;Bank&nbsp;Accounts</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2257&nbsp;</span><a href="http://poj.org/problem?id=2257"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2257</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：给定N(N&nbsp;&lt;=&nbsp;20)个人，以及M(M&nbsp;&lt;=&nbsp;1000)条关系，每条关系的描述为nameA&nbsp;nameB&nbsp;C，表示nameA这个人给了nameB这个人C块钱，为了让所有人都不亏，需要再给出至多N-1条关系，使得所有人都收支平衡。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：贪心。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">首先将所有人分成两堆，from_set表示收入大于支出的人的集合，to_set表示支出大于收入的人的集合，并且记录他们各自的&nbsp;|收入-支出|，然后对于所有的from_set的人按&nbsp;|收入-支出|&nbsp;进行递增排序，枚举每个from_set中的人f，去to_set中找到一个人t，满足f剩余的钱小于等于t亏损的钱，并且t是to_set中亏损最少的人，如果找不到这样的人，那么找到亏损最多的那个人，将f的钱给t，循环往复，直到f的钱给完为止。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">当from_set中的所有人将钱全部给了to_set中的人后，to_set中也就没有人亏损了，所有人达到收支平衡。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">C.&nbsp;The&nbsp;Settlers&nbsp;of&nbsp;Catan</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2258&nbsp;</span><a href="http://poj.org/problem?id=2258"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2258</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：给定一个N(N&nbsp;&lt;=&nbsp;25)个点，M(M&nbsp;&lt;=&nbsp;25)条边的图，求图的最长路，点允许重复，边不允许重复。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：前向星&nbsp;+&nbsp;dfs。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">利用前向星存双向边，以每个点为起点深搜遍历整个图，访问过的边哈希，搜索过程更新最长路即可。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">D.&nbsp;Team&nbsp;Queue</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2259&nbsp;</span><a href="http://poj.org/problem?id=2259"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2259</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：Team&nbsp;Queue是这样一种queue，每个元素都有一个Team。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">对于queue的push操作，被push的元素从queue中从头到尾扫描，如果扫到一个元素和它属于同一个Team，那么直接将它插入到这个元素后面；如果没有扫到，直接插到对列尾。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">对于queue的pop操作，等同于普通queue的pop操作。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">队伍数N小于等于1000。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：模拟，开1000个队列。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">对于插入操作，每个Team的元素插入到对应的队列中，并且记录当前Team的最早插入时间。O(1)</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">对于弹出操作，枚举所有Team的队列首元素，从中找时间最早的，然后对那个队列执行弹出操作。O(N)。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">E.&nbsp;Error&nbsp;Correction</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2260&nbsp;</span><a href="http://poj.org/problem?id=2260"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2260</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：给定N*N(N&nbsp;&lt;&nbsp;100)的01矩阵，问是否所有&nbsp;行和&nbsp;和&nbsp;列和&nbsp;都是偶数，如果是输出OK，如果不是，是否能够通过改变一个值保证&nbsp;都是偶数，&nbsp;都不行输出Corrupt。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：扫描。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">扫描所有&nbsp;行和&nbsp;和&nbsp;列和，如果正好有其中一行R是奇数，并且其中一列C是奇数，那么改变(R,&nbsp;C)的值就能保证全是偶数，否则要么是OK，要么是Corrupt。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">F.&nbsp;France&nbsp;'98</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2261&nbsp;</span><a href="http://poj.org/problem?id=2261"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2261</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：给定16个国家进行淘汰赛，以及一个16*16的矩阵A，其中A[i][j]表示i号国家打败j号国家的概率，问每个国家取得冠军的概率。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：动态规划。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">dp[0][i]&nbsp;&nbsp;&nbsp;表示&nbsp;1/2决赛&nbsp;第i个人获胜的概率</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">dp[1][i]&nbsp;&nbsp;&nbsp;表示&nbsp;1/4决赛&nbsp;第i个人获胜的概率</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">dp[2][i]&nbsp;&nbsp;&nbsp;表示&nbsp;1/8决赛&nbsp;第i个人获胜的概率</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">dp[3][i]&nbsp;&nbsp;&nbsp;表示&nbsp;&nbsp;总决赛&nbsp;第i个人获胜的概率&nbsp;</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">1)&nbsp;那么显然dp[0][i]&nbsp;=&nbsp;A[i][i^1]</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">2)&nbsp;dp[1][i]的概率取决于1/2决赛时第i个人获胜的概率乘上他打败1/4决赛中同组的那两个人的概率；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">3)&nbsp;dp[2][i]的概率取决于1/4决赛时第i个人获胜的概率乘上他打败1/8决赛中同组的那四个人的概率；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">4)&nbsp;dp[3][i]的概率取决于1/8决赛时第i个人获胜的概率乘上他打败&nbsp;总决赛中同组的那八个人的概率；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">直接递推求解，dp[3][i]就是所求。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">G.&nbsp;Goldbach's&nbsp;Conjecture</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2262&nbsp;</span><a href="http://poj.org/problem?id=2262"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2262</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：将一个数分解成两个奇素数的和。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：素数筛选，枚举。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">H.&nbsp;Heavy&nbsp;Cargo</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2263&nbsp;</span><a href="http://poj.org/problem?id=2263"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2263</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：给定一个有向图，边权W(u,&nbsp;v)表示从u到v的最大载重为W(u,&nbsp;v)，在给定s和t，求s到t&nbsp;的最大可能载重。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：二分答案&nbsp;+&nbsp;判断连通性。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">二分枚举答案T，然后从起点到终点进行连通性判定，如果边权小于T的边不可达，二分的最大值就是答案。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207722.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-07-19 22:42 <a href="http://www.cppblog.com/menjitianya/archive/2014/07/19/207722.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Asia Hefei Online 2008 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/06/28/207449.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sat, 28 Jun 2014 11:48:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/06/28/207449.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207449.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/06/28/207449.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207449.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207449.html</trackback:ping><description><![CDATA[<p><strong><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asia_online2008.PNG" width="913" height="183" alt="" /><br />A. Constellations</strong></p>  <p style="text-indent:21.0pt">PKU 3690 <a href="http://poj.org/problem?id=3690">http://poj.org/problem?id=3690</a><strong></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>N*M(N&lt;=1000, M &lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的</span>01<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">矩阵</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，再给定</span>T(T &lt;= 100)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个</span>P*Q(P &lt;= 50, Q &lt;= 50)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的</span>01<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">矩阵，问</span>P*Q<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的矩阵中有多少个是</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的子矩阵。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：位压缩</span> + KMP</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">由于</span>P &lt;= 50<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，所以我们可以把所有</span>P*Q<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的矩阵进行二进制位压缩，将</span>P*Q<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的矩阵的每一列压缩成一个</span>64<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位整数，这样</span>P*Q<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的矩阵就变成了一个长度为</span>Q<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的整数序列，用同样的方式对</span>N*M<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的矩阵进行压缩，总共可以产生</span>(N-P+1)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个长度为</span>M<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的整数序列，剩下的就是进行最多</span>(N-P+1)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">次</span>KMP<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">匹配了。</span><strong></strong></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KMP</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">相关算法可以参阅：</span></strong></p>  <p style="text-indent:21.0pt"><a href="http://www.cppblog.com/menjitianya/archive/2014/06/20/207354.html">http://www.cppblog.com/menjitianya/archive/2014/06/20/207354.html</a></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_1.PNG" width="209" height="186" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">图</span>1 &#8216;*&#8217;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">代表二进制的</span>1, &#8217;0&#8217;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">代表二进制的</span>0</p>  <p align="center" style="text-align:center"><strong>&nbsp;</strong></p>  <p><strong>B. DNA repair</strong></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>PKU 3691<strong> </strong><a href="http://poj.org/problem?id=3691">http://poj.org/problem?id=3691</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定</span>N(N &lt;= 50)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个长度不超过</span>20<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的模式串，再给定一个长度为</span>M(M &lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的目标串</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，求在目标串</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">上最少改变多少字符，可以使得它不包含任何的模式串（所有串只有</span>ACGT<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">四种字符）。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：</span>AC<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">自动机</span> + <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">动态规划</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">利用模式串建立</span>trie<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">图，</span>trie<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">图的每个结点</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">即下文讲到的状态</span>j)<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">维护三个结构，</span></p>  <p style="text-indent:21.0pt">Node{</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node *next[4];&nbsp;&nbsp; // <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">能够到达的四个状态</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的结点指针</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp; id;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">状态</span>ID<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">，用于到数组下标的映射</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp; val;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">当前状态是否是一个非法状态</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">（以某些模式串结尾）</span></p>  <p style="text-indent:21.0pt">}</p>  <p>&nbsp;</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">用</span>DP[i][j]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">表示长度为</span>i (i &lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，状态为</span>j(j &lt;= 50*20 + 1)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的字符串变成目标串</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">需要改变的最少字符，设初始状态</span>j = 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，那么</span>DP[0][0] = 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，其他均为无穷大。从长度</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">到</span>i+1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">进行状态转移，每次转移枚举共四个字符</span>(A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>C<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>G<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>T)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，如果枚举到的字符和</span>S<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">对应位置相同则改变值</span>T=1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，否则</span>T=0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">；那么有状态转移方程</span> DP[i][j] = Min{ DP[i-1][ fromstate ] + T, fromstate<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">为所有能够到达</span>j<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的状态</span> };<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">最后</span>DP[n][j]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">中的最小值就是答案。</span></p>  <p><strong>&nbsp;</strong></p>  <p><strong>C. Kindergarten</strong></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>PKU 3692 <a href="http://poj.org/problem?id=3692">http://poj.org/problem?id=3692</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定</span>G(G &lt;= 200)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个女孩和</span>B(B &lt;= 200)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个男孩，以及</span>M(0 &lt;= M &lt;= G*B)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">条记录</span>(x, y)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">表示</span>x<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">号女孩和</span>y<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">号男孩互相认识。并且所有的女孩互相认识，所有的男孩互相认识，求找到最大的一个集合使得所有人都认识。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：二分图最大匹配</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">一个点集中所有人都认识表示这个点集是个完全图，该问题就是求原图的一个最大团</span>(<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">最大完全子图</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，可以转化为求补图的最大独立集，而补图恰好是个二分图。二分图的最大独立集</span> = <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">总点数</span> - <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">二分图的最大匹配。于是问题就转化成了求补图的最大匹配了。</span></p>  <p style="text-indent:21.0pt">&nbsp;</p>  <p><strong>D. Maximum repetition substring</strong></p>  <p style="text-indent:21.0pt">PKU 3693 <a href="http://poj.org/problem?id=3693">http://poj.org/problem?id=3693</a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定长度为</span>N(N &lt;= 10<sup>5</sup>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的字符串</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，求它的一个最多重复子串</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">注意：最多重复子串不等于最长重复子串，即</span>ababab<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>aaaa<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">应该取后者</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：后缀数组</span> + RMQ</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">枚举重复子串的长度</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果对于某个</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，有</span>S[i*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>S[(i+1)*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最长公共前缀大于等于</span>L(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这一步可以利用后缀数组求解</span>height<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数组，然后通过</span>RMQ<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">查询区间最小值来完成</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么以</span>i*L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首，长度为</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的子串至少会重复两次。</span></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_2.PNG" width="386" height="200" alt="" /><br /></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>2</p>  <p align="left" style="text-indent: 21pt;"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如图，</span>L=3<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">，</span>i=3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的情况，</span>S[3...10]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>S[6...10]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最长公共前缀为</span>3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，即</span>S[3...5]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>S[6...8]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">完全匹配，所以</span>S[3...5]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">重复了两次。反之，如果最长公共前缀小于</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，必定不会重复（因为两个子串之间出现了断层）。</span></p>  <p align="left" style="text-indent: 21pt;"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">推广到更一般的情况，如果</span>S[i*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>S[(i+1)*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最长公共前缀为</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么以</span>S[i*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首的重复子串的重复次数为</span>T / L + 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，而且我们可以发现如果以</span>S[i*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首，长度为</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的子串的重复次数大于等于</span>2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么它一定不会比以</span>S[(i+1)*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首的子串的重复次数少，这个是显然的，比如</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为</span>2<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的时候，</span>ababab<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一定比</span>abab<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">多重复一次，基于这个性质，我们定义一个</span>new_flag<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">标记，表示是否需要计算接下来匹配到的串</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如</span>ababab<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>abab<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的情况，前者计算过了，就把</span>new_flag<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">置为</span>false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，就不会计算</span>abab<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的情况了</span>)<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">，得出完整算法：</span></p>  <p align="left" style="margin-left: 0cm; text-indent: 21pt;">1) <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">枚举重复子串的长度</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，初始化</span>new_flag<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">标记为</span>true<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p align="left" style="margin-left: 0cm; text-indent: 21pt;">2) <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">枚举</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，计算</span>S[i*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>S[(i+1)*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最长公共前缀</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p align="left" style="margin-left: 21pt; text-indent: 21pt;">a) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果</span>T &lt; L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span>new_flag<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">标记为</span>true<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt">b) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果</span>T &gt;= L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，判断</span>new_flag<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是不是为</span>false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果为</span>false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，说明以</span>S[i*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首的串和</span>S[(i-1)*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首的串的最长公共前缀大于等于</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，跳转到</span>2)<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">；否则转</span>3)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="text-indent:21.0pt">3) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">因为</span>S[i*L, (i+1)*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">有重复子串，但是字典序不一定最小，所以还需要枚举区间</span> [i-L+1, i+L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，看是否存在字典序更小的子串，比较字典序这一步可以直接使用后缀数组计算出来的</span>rank<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">值进行比较。</span></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RMQ</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">相关算法可以参阅：</span></strong></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><a href="http://www.cppblog.com/menjitianya/archive/2014/06/26/207420.html">http://www.cppblog.com/menjitianya/archive/2014/06/26/207420.html</a></p>  <p>&nbsp;</p>  <p><strong>E. Network</strong></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 3694 <a href="http://poj.org/problem?id=3694">http://poj.org/problem?id=3694</a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定</span>N(N &lt;= 10<sup>5</sup>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个点和</span>M(N-1 &lt;= M &lt;= 2*10<sup>5</sup>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">条边的无向连通图，进行</span>Q(Q &lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">次加边，每次加入一条边要求输出当前图中有多少条割边。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：无向图割边、最近公共祖先</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">利用</span>tarjan<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">求出原图的割边，由于这题数据量比较大，所以用递归可能会爆栈，需要栈模拟实现递归过程，</span>tarjan<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">计算的时候用</span>parent[u]<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">保存</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的父结点，每个结点进出栈各一次，出栈时表示以它为根结点的子树访问完毕，然后判断</span>(u, parent[u])<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">是否为割边。每次询问</span>u, v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">加入后会有多少割边，其实就是求</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">和</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的到它们的最近公共祖先</span>lca(u, v)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的路径上有多少割边，由于在进行</span>tarjan<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">计算的时候保存了每个结点的最早访问时间</span>dfn[u]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，那么有这么一个性质：</span>dfn[ parent[u] ] &lt; dfn[u]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，这是显然的</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">父结点的访问先于子结点</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">。于是当</span>dfn[u] &lt; dfn[v]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，将</span>parent[v]<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">赋值给</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，反之，将</span>parent[u]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">赋值给</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，因为是一棵树，所以进过反复迭代，一定可以出现</span>u == v <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的情况，这时候的</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">就是原先</span>u<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">和</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的最近公共祖先，在迭代的时候判断路径上是否存在割边，路径上的割边经过</span>(u, v)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">这条边的加入都将成为非割边，用一个变量保存割边数目，输出即可。</span></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_3.PNG" width="301" height="410" alt="" /><br /></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">图</span>3</p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">如图</span>3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，图中实线表示树边，虚线表示原图中的边，但是进行</span>tarjan<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">计算的时候</span>7<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">这个结点被</span>(6, 7)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">这条边&#8220;捷足先登&#8221;了，于是</span>(4, 7)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">成为了一条冗余边，计算完后这个图的割边为</span>(1, 2)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>(1,3)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>(3, 4)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>(3, 5)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，分别标记</span>bridge[2]<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>bridge[3]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>bridge[4]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>bridge[5]<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">为</span>true<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">当插入一条边</span>(7, 5)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，那么沿着</span>7<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">的祖先路径和</span>5<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的祖先路径最后找到的最近公共祖先为</span>3(<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">路径为</span>7 -&gt; 6 -&gt; 4 -&gt; 3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">和</span> 5 -&gt; 3)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，</span>(3, 4)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>(3, 5)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">这两条割边因为加入了</span>(7, 5)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">这条边而变成了普通边，将标记</span>bridge[4]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>bridge[5]<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">置为</span>false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">。</span></p>  <p><strong>&nbsp;</strong></p>  <p><strong>F. Rectangles</strong></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>PKU 3695 <a href="http://poj.org/problem?id=3695">http://poj.org/problem?id=3695</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定</span>N(N &lt;= 20)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个矩形，以及</span>M(M &lt;= 10<sup>5</sup>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">次询问，询问</span>R(R &lt;= N)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个矩形的并。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：离散化</span> + <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">暴力</span>( <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">或</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">容斥原理</span> )</p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">离散化：由于矩形很少，所以可以将它们的</span>XY<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">坐标分别离散到整点，两个维度分别离散，点的总数不会超过</span>2N<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，对于本次询问，利用前一次询问的结果进行面积的增减，对每个矩形进行判断，一共有两种情况：</span></p>  <p style="text-indent:21.0pt">1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">）这个矩形前一次询问出现，本次询问不出现，对它的所有离散块进行自减操作，如果某个离散块计数减为</span>0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">，则总面积减去这个离散块的面积；</span></p>  <p style="text-indent:21.0pt">2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">）这个矩形前一次询问没出现，本次询问出现，对它的所有离散块进行自增操作，如果某个离散块计数累加后为</span>1<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">，则总面积加上这个离散块的面积；</span></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">容斥原理：对于每个询问，利用</span>dfs<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">枚举每个矩形取或不取，取出来的所有矩形作相交操作，所有</span>[<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">奇数个矩形交</span>]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的面积和</span> &#8211; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">所有</span>[<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">偶数个矩形交</span>]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的面积和</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">就是答案，因为是</span>dfs<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">枚举，所以在枚举到某次相交矩形面积为</span>0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">的时候就不需要再枚举下去了，算是一个比较强的剪枝。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">如图</span>4<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，红色区域为被覆盖了一次的区域，橙色区域为被覆盖了两次的区域，黄色区域为被覆盖了三次的区域，那么先将所有的三个矩形加起来，然后需要减掉重叠的部分，重叠的减掉后发现，重叠的部分多减了，即图中黄色的部分被多减了一次，需要加回来。所以容斥原理可以概括为：奇数加，偶数减。</span></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_4.PNG" width="301" height="410" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">图</span>4</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>  <p><strong></strong></p><p><strong>G. The Luckiest number</strong></p>  <p style="text-indent:21.0pt">PKU 3696 <a href="http://poj.org/problem?id=3696">http://poj.org/problem?id=3696</a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>L(L &lt;= 2*10<sup>9</sup>)<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，求一个最小的数</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，满足</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">仅由数字</span>&#8217;8&#8217;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">组成，并且</span>T<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的倍数。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：欧拉定理</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">首先，长度为</span><span style="color:#333333;background:white">N</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">的仅由</span><span style="color:#333333;background:white">8</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">组成的数字可以表示为</span><span style="color:#333333;background:white">8*(10<sup>N</sup>-1)/9</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">如果它能被</span><span style="color:#333333;background:white">L</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">整除，则可以列出等式</span><span style="color:#333333;background:white">(1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">：</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="color:#333333;background:white">8*(10<sup>N</sup>-1)/9 = KL&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">其中</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">为任意正整数</span><span style="color:#333333;background:white">)&nbsp; (1) </span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">将等式稍作变形得到等式</span><span style="color:#333333;background:white">(2)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">：</span> </p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="color:#333333;background:white">(10<sup>N</sup>-1) = 9KL/8&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; (2)</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">由于存在分母，所以我们需要先对分数部分进行约分，得到等式</span><span style="color:#333333;background:white">(3)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">：</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">令</span><span style="color:#333333;background:white">A = L/GCD(8, L),&nbsp; B = 8/GCD(8, L)</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="color:#333333;background:white">(10<sup>N</sup>-1) = 9K*A / B&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; (3)</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">因为</span><span style="color:#333333;background:white">A</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">和</span><span style="color:#333333;background:white">B</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">已经互质，所以如果</span><span style="color:#333333;background:white">B</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">不为</span><span style="color:#333333;background:white">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，为了保证等式右边仍为整数，</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">必须能被</span><span style="color:#333333;background:white">B</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">整除，而</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">为任意整数，所以一定能够找到一个</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">正好是</span><span style="color:#333333;background:white">B</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">的倍数，所以可以在等式两边同时模</span><span style="color:#333333;background:white">9A</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，得到</span><span style="color:#333333;background:white">(10<sup>N</sup>-1) mod (9A) = 0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">，稍作变形，得到等式</span><span style="color:#333333;background:white">(4):</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="color:#333333;background:white"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_6.PNG" width="122" height="33" alt="" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(4)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">于是需要引入一个定理，即欧拉定理。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">欧拉定理的描述为：若</span><span style="color:#333333;background:white">n, a</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">为正整数，且</span><span style="color:#333333;background:white">n, a</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">互质，则：</span></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_5.PNG" width="116" height="22" alt="" /><br /></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>5</p>  <p align="center" style="text-align:center;text-indent:21.0pt">(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#968;</span>(n)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span>n<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的欧拉函数，即小于等于</span>n<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">并且和</span>n<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">互素的数的个数</span>)</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这样一来，我们发现只要</span>10<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>9A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">互质，</span><span style="font-size: 10.5pt; font-family: 宋体;">只需要求</span><span style="font-size: 10.5pt; font-family: 'Times New Roman';">9A</span><span style="font-size: 10.5pt; font-family: 宋体;">的欧拉函数，但是求出来的欧拉函数是不是一定使得</span><span style="font-size: 10.5pt; font-family: 'Times New Roman';">N</span><span style="font-size: 10.5pt; font-family: 宋体;">最小呢，并不是，所以还需要枚举欧拉函数的因子，如果它的某个因子</span><span style="font-size: 10.5pt; font-family: 'Times New Roman';">T也</span><span style="font-size: 10.5pt; font-family: 宋体;">满足(4)的等式，那么T肯定不会比</span><span style="text-align: center; font-family: 宋体;">&#968;</span><span style="text-align: center;">(9A)大，所以T一定更优。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里</span>9A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">有可能超过</span>32<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位整数，所以计算过程中遇到的乘法操作不能直接相乘</span>(<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">两个超过</span>32<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位整数的数相乘会超过</span>64<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位整数</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，需要用到二分乘法，即利用二进制加法模拟乘法，思想很简单，就直接给出一段代码吧。</span></p><p>&nbsp;</p>  <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: #008080; ">&nbsp;1</span>&nbsp;<span style="color: #0000FF; ">#define</span>&nbsp;LL&nbsp;__int64<br /><span style="color: #008080; ">&nbsp;2</span>&nbsp;&nbsp;<br /><span style="color: #008080; ">&nbsp;3</span>&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">计算&nbsp;a*b&nbsp;%&nbsp;mod</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">&nbsp;4</span>&nbsp;<span style="color: #008000; "></span>LL&nbsp;Produc_Mod(LL&nbsp;a,&nbsp;LL&nbsp;b,&nbsp;LL&nbsp;mod)&nbsp;{<br /><span style="color: #008080; ">&nbsp;5</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LL&nbsp;sum&nbsp;=&nbsp;0;<br /><span style="color: #008080; ">&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>(b)&nbsp;{<br /><span style="color: #008080; ">&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(b&nbsp;&amp;&nbsp;1)&nbsp;sum&nbsp;=&nbsp;(sum&nbsp;+&nbsp;a)&nbsp;%&nbsp;mod;<br /><span style="color: #008080; ">&nbsp;8</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;=&nbsp;(a&nbsp;+&nbsp;a)&nbsp;%&nbsp;mod;<br /><span style="color: #008080; ">&nbsp;9</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b&nbsp;&gt;&gt;=&nbsp;1;<br /><span style="color: #008080; ">10</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">11</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;sum;<br /><span style="color: #008080; ">12</span>&nbsp;}<br /><span style="color: #008080; ">13</span>&nbsp;&nbsp;<br /><span style="color: #008080; ">14</span>&nbsp;&nbsp;<br /><span style="color: #008080; ">15</span>&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">计算a^b&nbsp;%&nbsp;mod</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">16</span>&nbsp;<span style="color: #008000; "></span>LL&nbsp;Power(LL&nbsp;a,&nbsp;LL&nbsp;b,&nbsp;LL&nbsp;mod)&nbsp;{<br /><span style="color: #008080; ">17</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LL&nbsp;sum&nbsp;=&nbsp;1;<br /><span style="color: #008080; ">18</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>(b)&nbsp;{<br /><span style="color: #008080; ">19</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(b&nbsp;&amp;&nbsp;1)&nbsp;sum&nbsp;=&nbsp;Produc_Mod(sum,&nbsp;a,&nbsp;mod);<br /><span style="color: #008080; ">20</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;=&nbsp;Produc_Mod(a,&nbsp;a,&nbsp;mod);<br /><span style="color: #008080; ">21</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b&nbsp;&gt;&gt;=&nbsp;1;<br /><span style="color: #008080; ">22</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">23</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;sum;<br /><span style="color: #008080; ">24</span>&nbsp;}</div>  <p>&nbsp;</p>  <p><strong>H. USTC campus network</strong></p>  <p style="text-indent:21.0pt">PKU 3697 <a href="http://poj.org/problem?id=3697">http://poj.org/problem?id=3697</a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>N, M(N &lt;= 10<sup>4</sup>, M &lt;= 10<sup>6</sup>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，求</span>N<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个点的完全图删掉</span>M<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">条边后，和</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这个结点相邻的点的数目。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span>BFS</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">利用前向星存边</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里边的含义是反的，</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>j<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">有边表示</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>j<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">不直接连通</span>)<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">。然后从</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">开始广搜，将和</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">有边的点</span>hash<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">掉，然后枚举</span>hash<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数组中没有</span>hash<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">掉的点</span>(<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">这些点是和</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">连通的</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果点没有被访问过，标记已访问，入队；然后不断弹出队列首元素进行相同的处理。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里可以加入一个小优化，将所有点分组，编号</span>0-9<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的分为一组，</span>10-19<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的分为一组，</span>20-29<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的分为一组，然后用一个计数器来记录每个组中的点是否被访问，每次访问到一个点的时候计数器自增，当某个组的计数器为</span>10<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时候表示这个组内所有点都被访问过了，不需要再进行枚举了，这样可以把最坏复杂度控制在</span> O( N*N/10 ) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">以下。</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207449.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-06-28 19:48 <a href="http://www.cppblog.com/menjitianya/archive/2014/06/28/207449.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Southeastern Europe 2007 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/06/01/207161.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sat, 31 May 2014 16:03:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/06/01/207161.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207161.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/06/01/207161.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207161.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207161.html</trackback:ping><description><![CDATA[<div align="center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/souer2007.png" width="821" height="205" alt="" /></div><br /><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">A&nbsp;.&nbsp;John</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3480&nbsp;<a href="http://poj.org/problem?id=3480">http://poj.org/problem?id=3480</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：N堆石子，两人轮流从其中一堆中取任意石子，最后一个取完石子的人输。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：博弈。</span></p><p style="margin-left:42.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">1)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">当所有石子的SG值异或和不等于0时：</span></p><p style="margin-left:42.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">a)&nbsp;个数大于1的堆数=0，必定是奇数个1，所以先手必输；</span></p><p style="margin-left:63.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">b)&nbsp;个数大于1的堆数=1，总能想办法将局面变成奇数个1，所以先手必胜；</span></p><p style="margin-left:42.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">c)&nbsp;个数大于1的堆数&gt;1，总能取掉某些石子，使得所有石子的SG值异或和为0，并且个数大于1的堆数至少还剩两堆；</span></p><p style="margin-left:42.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">2)&nbsp;当所有石子的SG值异或和等于0时：</span></p><p style="margin-left:42.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">a)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">个数大于1的堆数=0，必定是偶数个1，先手必胜；</span></p><p style="margin-left:42.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">b)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">个数大于1的堆数=1（不存在）；</span></p><p style="margin-left:42.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">c)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">个数大于1的堆数&gt;1，无论怎么取，SG值异或和都不可能为0。并且无论先手怎么移，后手可以要么进入偶数个1的状态，要么保持SG值和为0并且非全1的状态（</span><span style="mso-spacerun:'yes'; color:#ff0000; font-size:10.5000pt; font-family:'宋体'; ">该状态先手必输</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">），所以这种情况，先手必败。</span></p><p style="margin-left:21.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">由于1)&nbsp;的c)情况可以到达2的c)情况，所以1的c)情况为先手必胜点。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">B&nbsp;.&nbsp;Double&nbsp;Queue</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3481&nbsp;<a href="http://poj.org/problem?id=3481">http://poj.org/problem?id=3481</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定一些数据(K,P)和一些询问，K为数据值，P为优先级，每次询问输出当前优先级最高或者最低的数据的K的值，询问完删除这个数据。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：平衡树。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">可以用SLT的set(内部也是平衡树的实现)水过去。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">C&nbsp;.&nbsp;</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'Times New Roman'; ">&#8216;</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">JBC</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'Times New Roman'; ">&#8217;</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3482&nbsp;<a href="http://poj.org/problem?id=3482">http://poj.org/problem?id=3482</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：进制转换，数字位可以是任何的可见ASCII码，求所有可能进制下的串转换成十进制后的和。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：模拟进制转换，模拟大数运算。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">D&nbsp;.&nbsp;</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">Loan&nbsp;Scheduling</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3483&nbsp;<a href="http://poj.org/problem?id=3483">http://poj.org/problem?id=3483</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定N(N&nbsp;&lt;=&nbsp;10000)个任务，每个任务是一个二元组(Pi,</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">&nbsp;Di</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)，表示如果在[0,&nbsp;Di]的某个时刻内完成则可以得到Pi的利润，每个时间点最多只能有L(L&nbsp;&lt;=&nbsp;100)个任务，求取一个任务子集来完成的的最大利润总和。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：贪心。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">初始化每个时间点的可用任务数为L，初始化任务利润和S。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">将所有任务按Pi从大到小排序，对于每个任务，从Di到0枚举它的完成时间t，如果t这个时间点还有可用任务，累加Pi到S，并且将t这个时间点的可用任务数减1，枚举完所有任务后S即为所求。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">E&nbsp;.&nbsp;Showstopper</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3484&nbsp;<a href="http://poj.org/problem?id=3484">http://poj.org/problem?id=3484</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定一些三元组(X,&nbsp;Y,&nbsp;Z)，一个三元组表示满足X&nbsp;+&nbsp;K*Z&nbsp;&lt;=&nbsp;Y&nbsp;(K&nbsp;=&nbsp;0,&nbsp;1,&nbsp;2,&nbsp;3&nbsp;...&nbsp;)&nbsp;的所有正整数&nbsp;X&nbsp;+&nbsp;K*Z出现了一次。对于多个三元组，保证所有数中至多只有一个数出现奇数次，求这个数以及它出现的次数。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：二分答案。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">对于出现奇数次的那个数T，那么如果小于T的所有数的和必定是偶数，大于等于T的所有数的和必定是奇数，利用这一点可以二分枚举这个T，然后利用所有小于等于T的数的个数的奇偶性进行二分判定。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">对于某个三元组(X,&nbsp;Y,&nbsp;Z)，小于等于T的个数分几种情况讨论：</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">1)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">当T&nbsp;&gt;=&nbsp;Y，个数为&nbsp;(Y-X)/Z&nbsp;+&nbsp;1;</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">2)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">当T&nbsp;&lt;&nbsp;X，个数为0;</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">3)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">当&nbsp;X&nbsp;&lt;=&nbsp;T&nbsp;&lt;&nbsp;Y，个数为&nbsp;(T-X)/Z&nbsp;+&nbsp;1;</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">每次枚举T，将所有区间的数相加判断奇偶性即可。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">F&nbsp;.&nbsp;Highway</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3485&nbsp;<a href="http://poj.org/problem?id=3485">http://poj.org/problem?id=3485</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定一条高速公路的长度L(范围为0到L)和N个村庄，要求在高速公路上建一些出口，使得每个村庄到高速公路至少有一个出口的距离不大于D，并且出口总数最少。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：贪心。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">计算出每个村庄到高速公路距离D范围内的左右区间[L</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">i</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">,&nbsp;R</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">i</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">]，对这些区间进行排序，排序规则为如果左端点一致则按照右端点递增排序，否则按照左端点递增排序。然后按左端点递增枚举每个区间（每个区间对应一个村庄），对于尚未有高速公路可达的村庄，在其右端点建立一个出口（贪心所在，因为是从左往右扫描，所以在右端点建出口肯定比左端点建更优），然后将它之后的左端点坐标小于这个出口的区间全部hash掉（因为那些村庄可以用这个出口，无须建立新的出口），直到所有区间枚举完毕，出口数也就得出了。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">G&nbsp;.&nbsp;Computers</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3486&nbsp;<a href="http://poj.org/problem?id=3486">http://poj.org/problem?id=3486</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：故事背景是每年都要更换电脑或者进行一次维修，如果换电脑需要c的花费，如果不换电脑，那么第y年到第z年(&nbsp;1&nbsp;&lt;=&nbsp;y&nbsp;&lt;=&nbsp;z&nbsp;&lt;=&nbsp;n)的总维修费用为m[y][z]，求经过n年的最小花费。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：动态规划。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">DP[i]表示经过i年的总开销，假设从第j年开始买了一台新的电脑，一直用到了第i年，那么前j年的总开销为DP[j]，从第j+1年到第i年的维修开销加上购买花费c，即DP[j]&nbsp;+&nbsp;m[j+1][i]&nbsp;+&nbsp;c，DP[i]就是这些开销中的最小值，即。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">DP[i]&nbsp;=&nbsp;min{&nbsp;DP[j]&nbsp;+&nbsp;m[j+1][i]&nbsp;+&nbsp;c,&nbsp;0&nbsp;&lt;=&nbsp;j&nbsp;&lt;&nbsp;i&nbsp;};</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">H&nbsp;.&nbsp;The&nbsp;Stable&nbsp;Marriage&nbsp;Problem</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3487&nbsp;<a href="http://poj.org/problem?id=3487">http://poj.org/problem?id=3487</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：n(n&nbsp;&lt;&nbsp;27)对男女，每个男人有对所有女人的好感度，每个女人也有对所有男人的好感度，A对B的好感度记为G(A,&nbsp;B),&nbsp;求找出一种稳定的婚配关系，使得对于任意一对夫妇X(M,&nbsp;W)，不存在&nbsp;G(X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">M</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">,&nbsp;Y</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">W</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)&nbsp;&gt;&nbsp;G(X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">M</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">,&nbsp;X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">W</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)&nbsp;并且&nbsp;G(X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">W</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">,&nbsp;Z</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">M</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)&nbsp;&gt;&nbsp;G(X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">W</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">,&nbsp;X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">M</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)，并且要求男士优先考虑（即男方如果能找到好的一定不会更差的）。通俗的讲，就是X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">M</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">更加喜欢别人的老婆，X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">w</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">更加喜欢别人的老公，这样的婚姻是不稳定的，双方都有可能出现外遇。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：稳定婚姻经典算法。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">由于是男士最优，所以需要模拟男士求爱的方式。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">用L[i][j]表示i号男子喜欢的第j个女子的编号；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">用R[i][j]表示i号女子对j号男子的评分（越大评分越高，且对于确定的i肯定互不相同）；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">算法如下：</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">1)&nbsp;将所有的男子以及他们向多少个女人求过婚的信息入队，每次弹出一个男子M，找到他下一个要求婚的对象（求婚顺序按照对女生的好感度顺序进行）。</span></p><p style="margin-left:21.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">a)&nbsp;如果当前求婚对象W没有配偶，直接配对，记Match[&nbsp;W&nbsp;]&nbsp;=&nbsp;M;</span></p><p style="margin-left:21.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">b)&nbsp;如果当前求婚对象有老公，即Match[&nbsp;W&nbsp;]，那么检查M&nbsp;和&nbsp;Match[&nbsp;W&nbsp;]在W的评分，如果M的评分大于W的老公，则迫使其改嫁，前夫入队，Match[&nbsp;W&nbsp;]&nbsp;=&nbsp;M；否则，该男子M继续入队；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">2)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">反复进行1)直到所有人都找到的对象。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">I&nbsp;.&nbsp;Arne&nbsp;Saknussemm</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3488&nbsp;<a href="http://poj.org/problem?id=3488">http://poj.org/problem?id=3488</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：简单字符串模拟。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：根据题意做就行了。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207161.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-06-01 00:03 <a href="http://www.cppblog.com/menjitianya/archive/2014/06/01/207161.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Greater New York Regional 2009 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/05/28/207124.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Wed, 28 May 2014 00:25:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/05/28/207124.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207124.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/05/28/207124.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207124.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207124.html</trackback:ping><description><![CDATA[<div style="text-align: center;"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/gnyork2009.png" width="796" height="184" alt="" /></div> <p><span style="color: #333333; background-color: white;"><strong>A.Nth Largest Value</strong><br /><strong>&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3781<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3781">http://poj.org/problem?id=3781</a></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">水题，求</span><span style="color:#333333;background:white">10</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">个数中第</span><span style="color:#333333;background:white">3</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">大的数。</span></p>  <p><strong>&nbsp;</strong></p>  <p><strong><span style="color:#333333;background:white">B.Equal Sum Partitions<br />&nbsp; &nbsp; &nbsp; &nbsp;</span></strong><span style="color: #333333; background-color: white;">PKU 3782<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3782">http://poj.org/problem?id=3782</a></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题意：给定一个</span><span style="color:#333333;background:white">M(M &lt;= 10000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">个元素的序列，将它切割成</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">块，每块的和相等，求最大的</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">。</span></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题解：枚举。</span></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">首先，切成</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">块，每块和相等，那么这个和必定是</span><span style="color:#333333;background:white">M</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">个元素总和的一个因子，那么可以枚举第一个块的长度（</span><span style="color:#333333;background:white">M</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">种），判断当前块的和是否能被所有数的总和整除，如果可以，顺序判断可行性，看似复杂度是</span><span style="color:#333333;background:white">O(M^2)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，但是能否整除这个剪枝可以筛选掉绝大部分情况。</span></p>  <p>&nbsp;</p>  <p><strong><span style=" color:#333333;background:white">C.Balls<br />&nbsp; &nbsp; &nbsp; &nbsp;</span></strong><span style="color: #333333; background-color: white;">PKU 3783<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3783">http://poj.org/problem?id=3783</a></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题意：给定</span><span style="color:#333333;background:white">B (B &lt;= 50) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333; background:white">个一样的球，从</span><span style="color:#333333;background:white"> M (M &lt;= 1000) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">层楼上一个一个往下扔，存在某个楼层</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，使得低于它的楼层往下扔球，球不会碎，在第</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">层扔下去会碎。求最坏情况下，需要扔几次才能确定这个</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题解：动态规划。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">令</span><span style="color:#333333;background:white">DP[i][j]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">表示总楼层为</span><span style="color:#333333;background:white">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，持有</span><span style="color:#333333;background:white">j</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">个球时，最坏情况需要的次数；</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">那么如果从</span><span style="color:#333333;background:white">k ( 1 &lt;= k &lt;= i) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">层进行扔球，有两种情况：</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">1) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">如果球不碎，则还需要进行</span><span style="color:#333333;background:white">DP[i-k][j]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">次测试（向更高的楼层进发）；</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">如果球碎，那么还可以进行的次数为</span><span style="color:#333333;background:white">DP[k-1][j-1] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333; background:white">（损失了一个球）；</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">由于要考虑最坏情况，所以每次测试必须取</span><span style="color:#333333;background:white">(1) (2)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333; background:white">中的大者</span><span style=" color:#333333;background:white">+1</span><span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，每次选定一个楼层，使得这个楼层往下扔球的结果的最大值最小，也即状态转移方程为：</span></p>  <p style="text-indent:25.0pt"><span style="color:#333333;background:white">DP[i][j] = Min( DP[i][j],&nbsp; Max(DP[i-k][j], DP[k-1][j-1]) + 1 );</span></p>  <p style="text-indent:25.0pt"><span style="color:#333333;background:white">Pku</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">上有道和这题想法类似的题：</span><span style="color:#333333;background:white"><a href="http://poj.org/problem?id=1243">http://poj.org/problem?id=1243</a></span></p>  <p>&nbsp;</p>  <p><strong><span style="color:#333333;background:white">D.Running Median<br />&nbsp; &nbsp; &nbsp; &nbsp;</span></strong><span style="color: #333333; background-color: white;">PKU 3784<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3784">http://poj.org/problem?id=3784</a></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题意：一个长度为</span><span style="color:#333333;background:white">M(M &lt;= 9999)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">的序列，每次奇数位的数读入的时候计算前面整个序列的中位数。</span></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题解：二分</span><span style="color:#333333;background:white"> + </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">树状数组。</span></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">由于数字是</span><span style="color:#333333;background:white">int32</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">范围，所以首先需要将所有数离散到下标，枚举每一个数字读入，将对应位的数字下标插入到树状数组中，每当读到奇数个的时候，利用树状数组的成端求和的性质，如果要找第</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">大的数，那么就二分一个答案，然后查询树状数组，如果求和大于等于</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，表示是一个候选解（因为要保证大于等于</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">的数最小，才是第</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">大的数），反复二分，直到找到最小的值</span><span style="color:#333333;background:white">V</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">满足</span><span style="color:#333333;background:white">sum(V) &gt;= K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333; background:white">，时间复杂度</span><span style=" color:#333333;background:white">O(2 *M * log(M) )</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">。</span></p>  <p>&nbsp;</p>  <p><strong><span style=" color:#333333;background:white">E.The Next Permutation<br />&nbsp; &nbsp; &nbsp;&nbsp;</span></strong><span style="color: #333333; background-color: white;">PKU 3785<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3785">http://poj.org/problem?id=3785</a></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题意：给定一个可重复元素的排列</span><span style="color:#333333;background:white">A[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，求下一个排列。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题解：从后往前扫描，对于第</span><span style="color:#333333;background:white">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">个元素</span><span style="color:#333333;background:white">A[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，如果能够找到一个</span><span style="color:#333333;background:white">j</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，使得</span><span style="color:#333333;background:white">A[j] &gt; A[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">，并且满足</span><span style="color:#333333;background:white">A[j]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">是继第</span><span style="color:#333333;background:white">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">位之后最小的数，那么将</span><span style="color:#333333;background:white">A[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">和</span><span style="color:#333333;background:white">A[j]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">进行交换，然后将</span><span style="color:#333333;background:white">A[i+1]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">到末尾的元素进行一次不降序排序，最后得到的串就是解。</span></p>  <p style="text-indent:25.0pt">&nbsp;</p>  <p><strong>F.Adjacent Bit Counts<br />&nbsp; &nbsp; &nbsp;&nbsp;</strong><span style="color: #333333; background-color: white;">PKU 3786<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3786">http://poj.org/problem?id=3786</a></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：求长度为</span>n<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的二进制整数中，相邻两个</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数有</span>k<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对（可重复使用）的整数个数。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：动态规划。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">令长度为</span>n<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，相邻</span>1<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数为</span>k<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的数的个数为</span>DP[n][k]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，其中以</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">结尾的为</span>DP[n][k][0]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，以</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">结尾的为</span>DP[n][k][1]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么</span> DP[n][k] = DP[n][k][0] + DP[n][k][1]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">并且有如下状态转移方程：</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">1) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">长度为</span>n-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的二进制数在末尾加上一个</span>0<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，相邻</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数不变，所以有：</span></p>  <p style="text-indent:25.0pt">DP[n][k][0] = DP[n-1][k][0] + DP[n-1][k][1];</p>  <p style="margin-left:0cm;text-indent:25.0pt;">2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">长度为</span>n-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的二进制数在末尾加上一个</span>1<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，相邻</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数取决于，第</span>n-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位是</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">还是</span>1<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，当第</span>n-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位是</span>1<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，相邻</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数</span>+1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；当第</span>n-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位是</span>0<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，相邻</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数不变，所以有：</span></p>  <p style="text-indent:25.0pt">DP[n][k][1] = DP[n-1][k][0] + DP[n-1][k-1][1];</p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">并且初始状态下</span>DP[0][0][0] = 1,&nbsp; DP[0][0][1] = 0</p>  <p style="text-indent:25.0pt">&nbsp;</p>  <p><strong>G.Convex Hull of Lattice Points</strong></p>  <p style="text-indent:25.0pt"><span style="text-indent: 0px; color: #333333; background-color: white;">PKU 3787<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3787" style="text-indent: 0px;">http://poj.org/problem?id=3787</a><br /><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&nbsp; &nbsp; &nbsp;题意：凸包。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span><span style=" color:#333333;background:white">Graham</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">扫描法求解即可。</span></p>  <p><strong>&nbsp;</strong></p>  <p>&nbsp;</p>  <p><strong><span style=" color:#333333;background:white">H.Interior Points of Lattice Polygons</span></strong></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white"><span style="font-family: verdana, 'courier new'; text-indent: 0px;">PKU 3788<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3788" style="font-family: verdana, 'courier new'; text-indent: 0px;">http://poj.org/problem?id=3788</a><br />&nbsp; &nbsp; &nbsp;题意：给定一个凸多边形，求它内部所有的水平线段。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题解：从多边形第一个点的</span><span style="color:#333333;background:white">y</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">坐标开始，递减枚举水平线段的</span><span style="color:#333333;background:white">y</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">坐标，分别和多边形的</span><span style="color:#333333;background:white">n</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">条边进行求交点；</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">1) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">如果水平线段和多边形某条边共线，说明正好到了多边形的边缘，无须往下枚举，跳出循环。</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">如果水平线段和多边形小于一个交点，那么当</span><span style="color:#333333;background:white">y</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">轴再次减小的时候，必然没有交点，也无须继续枚举。</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">3) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">否则，将左端点坐标取上整</span><span style="color:#333333;background:white">x1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，右端点取下整</span><span style="color:#333333;background:white">x2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，如果</span><span style="color:#333333;background:white">x1 &lt;= x2 </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">将它插入到解集中。</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207124.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-05-28 08:25 <a href="http://www.cppblog.com/menjitianya/archive/2014/05/28/207124.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mid-Central USA 2009 解题报告 </title><link>http://www.cppblog.com/menjitianya/archive/2014/05/25/207098.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sun, 25 May 2014 12:33:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/05/25/207098.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207098.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/05/25/207098.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207098.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207098.html</trackback:ping><description><![CDATA[<p>&nbsp;</p><div style="text-align: center;"><strong><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/midc2009.png" width="814" height="204" alt="" /></strong></div><strong>A. Up and Down<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3912<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3912">http://poj.org/problem?id=3912</a><p>&nbsp;</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一个一维的棋盘，范围为</span>[0, W] (W &lt;= 1000,000,000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，某两个点之间有梯子或虫洞，梯子的下端点到上端点以及虫洞的上端点到下端点花费的步数为</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，其它任意点之间的距离通过跳跃来计算，最多每次跳跃不超过</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">格（</span>S&lt;= 6<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">），跳跃的过程中如果跳到梯子的下端点或者虫洞的上端点就会被直接传送到另一端，并且每次跳跃只能从小的点跳到大的点（虫洞是个例外），求从</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">到</span>W<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最短距离。</span></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/1.png" border="0" alt="" width="373" height="323" /></p>  <p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>A-1</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">离散化</span> + SPFA<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">将所有梯子和虫洞的两端点、</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>W<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">以及他们往前往后</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">步以内的数全部记录下来，梯子和虫洞有</span>P<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>P &lt;= 40<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）个，加上起点终点，总共</span>82<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点，算上前后各六步，总共</span>82 * 13 = 1066<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点，然后将这些点排序后离散化，最后就是要构建一个网络图，通过网络求</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">到</span>W<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的最短路，最短路可以用</span>SPFA<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">求解。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">谈谈建图的过程，对于任意两个点，他们之间必定可以连一条边，然后有一个步数表示边的权值（这里的步数也可能是正无穷，也即永远都无法到达）。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于任意两个点</span>(u, v)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，他们的步数</span>w(u, v)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（边权）我们做如下讨论（这里的</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>v<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">是离散化后的点）：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果</span>u<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">是梯子的下端点，</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是梯子的上端点</span> <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">或者</span> u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是虫洞的上端点，</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是虫洞的下端点，那么</span>w(u, v) = 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，否则进入</span>2)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的判断</span>;</p>  <p style="text-indent:21.0pt">2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果</span>u<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的编号大于</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span>w(u, v) = inf<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，表示永远不可达，因为某次跳跃只能从小的点跳到大的点，否则进入</span>3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）的判断</span>;</p>  <p style="text-indent:21.0pt">3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果</span>u<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的实际位置和</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的实际位置差值小于等于</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则</span>w(u, v) = 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="text-indent:21.0pt">4<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）检查</span>u<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">之间是否有虫洞的上端点或者梯子的下端点，之后将这两种点称为</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt">a<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果有，判断他们是否连续，</span></p>  <p style="margin-left:42.0pt;text-indent:21.0pt">i) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果不连续</span>w(u, v) = inf<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（这一步这么做是为了简单化，试想一下，如果</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点不是全部连续，说明</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">可以先跳到他们中间的某个非</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的点，然后再跳到</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点，这一步是通过</span>SPFA<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">来实现迭代的，建边的时候可以不考虑）。</span></p>  <p style="margin-left:42.0pt;text-indent:21.0pt">ii<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果连续，判断他们连续的格子的数目，如果大于等于</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">说明这个连续的块必定跳不过去，所以</span>w(u, v) = inf<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，否则可以先跳到最先的一个</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点的前面一个点，然后经过一步</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">跳跃将这个连续块跳过去，再跳到</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果没有</span>X<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">点，那么直接从</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点跳到</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里我们需要计算从</span>a<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点跳到</span>b<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">点不考虑虫洞和梯子的最短距离，可以贪心的跳，每次往大的跳，直到剩余格子不足</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">格，即</span>(b-a + S-1) / S <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>b-a<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对</span>S<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">求商的上整）。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">边建立完成就可以利用广搜求解</span>0-W<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最短路了。</span></p>  <p>&nbsp;</p>  <p><strong>B. Gnome Sequencing<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3913<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3913">http://poj.org/problem?id=3913</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">水题，判断三个数是全递增还是全递减还是无序。</span></p>  <p>&nbsp;</p>  <p><strong>C. DuLL<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3914<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3914">http://poj.org/problem?id=3914</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一些</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件和它占用的内存空间，以及一些可执行程序占用的内存空间和它依赖的</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件，程序以进程为单位，两个相同的程序可能有不同的进程，进行一些下列的操作：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）某个程序运行的时候需要它依赖的</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件也加载到内存中，多个程序可以共用一个</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）某个程序退出的时候，如果它所依赖的</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件没有其它程序使用，需要释放这段内存空间；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">给定一系列的运行进程，求某个时刻的最大内存占用。</span></p>  <p>&nbsp;</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span>HASH<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的简单应用。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">初始化内存占用</span>V = 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于给定的输入进程：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果是新运行的进程，将</span>V<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">加上这个进程的内存占用，并将它所有依赖的</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件检查一遍，如果引用计数为</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则将对应</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件的内存累加到</span>V<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">上，引用计数</span>+1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果是退出进程，将</span>V<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">减去这个进程的内存占用，并将它所有依赖的</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件检查一遍，如果引用计数为</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则用</span>V<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">减去对应</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件的占用量，引用计数</span>-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每次操作记录最大的</span>V<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">就是最后的答案。</span></p>  <p><strong>D. Black Vienna<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3915<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3915">http://poj.org/problem?id=3915</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：三个人，每个人五张牌，互相不知道对方的牌，还有额外的三张牌放在一边（所有牌编号为</span>A - R<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）。每一轮，由</span> (i-1)%3+1 (1 &lt;= i &lt;= 15) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">号玩家进行发问，问</span>Ai &nbsp;(1 &lt;= Ai &lt;= 3) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">号玩家</span>XYZ<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">（代表任意三个牌号）三张牌中有多少张在他手上，然后他回答</span>Bi (0 &lt;= Bi &lt;= 3)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，问经过多少轮之后有某位玩家知道</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">额外</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的那三张牌是什么。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span>dfs<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">枚举</span> + <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">剪枝。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">首先枚举到某个询问</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时候玩家</span>j<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">能够猜出的那三张牌的情况，如果枚举完所有情况最后确定只有一个解满足条件的时候，那个询问的编号</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">就是答案了。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">类似</span>IDA*<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的思路，先枚举询问最大深度，如果到达那个询问不能确定额外的那三张牌或者有很多种情况，那么说明还需要更多的询问，迭代深度继续枚举。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于某个询问</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，找到询问的那三张牌中已经是</span>Ai<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">号选手的数量</span>ansCnt<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，以及尚未确定牌的归属的牌的数量</span>xCnt<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果已经确定位置的牌数量</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">大于</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">实际他回答的数量（</span>ansCnt &nbsp;&gt; &nbsp;Bi<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）或者</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">尚未确定位置的牌数量</span> + <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">已经确定为他的牌数量</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">小于</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">实际他回答的数量（</span>ansCnt + xCnt &lt; Bi<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）都是不合理的情况，剪枝，不用继续往下搜索；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">否则，将</span>(Bi - ansCnt)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">张牌分配给</span>Ai<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span>(xCnt - (Bi - ansCnt))<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">张牌分配给其它两位玩家以及额外的那一堆，这里需要用到嵌套</span>dfs<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">枚举，枚举完后进入下一个询问的枚举，每次询问的时候可以有几个剪枝：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果某个阶段某个人的牌数超过</span>5<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">张；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）枚举的解的数量超过</span>2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于一次完全枚举，枚举完所有询问后还是有无法确定三张额外的牌的情况；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>  <p><strong>E. Duplicate Removal<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3916<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3916">http://poj.org/problem?id=3916</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">水题，对输入的元素进行连续判重输出。</span></p>  <p>&nbsp;</p>  <p><strong>F. Rock, Paper, Scissors<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3917<strong></strong><a href="http://poj.org/problem?id=3917"><strong>&nbsp;</strong>http://poj.org/problem?id=3917</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">水题，剪刀石头布！</span>O_o<br /></p>  <p>&nbsp;</p>  <p><strong><span style="color:#C00000">G. A to Z Numerals<br />&nbsp; &nbsp; &nbsp; &nbsp;</span></strong>PKU 3918<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3918">http://poj.org/problem?id=3918</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：复杂模拟。（没做出来，</span>#-_-# <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">样例的</span>98<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">是怎么出来的呀！！！）</span></p>  <p>&nbsp;</p>  <p><strong>H. Cell Towers&nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3919<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3919">http://poj.org/problem?id=3919</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给出一条曲折的连续线段，曲线从起点开始每经过一个长度为</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的单位会放置一个守卫</span>K<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，在曲线以外的某些地方会有</span>T(T &lt;= 10)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个信号发射器，用</span>A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>B<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>C...<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">来表示，每个信号发射器有它的信号强度</span>Pi<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，每个信号发射器到守卫</span>K<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的距离如果是</span>D<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么它能接收到的信号值为</span>Pi / D<sup>2</sup><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最近整数，并且对于守卫</span>K<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，它只会接收最大的信号值，如果有多个发射器对于</span>K<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的信号值相同，那么选择字典序最小的发射器。需要求是一些守卫集合，这些守卫分别和它的前一个守卫所接收的信号发射器不一样。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：计算几何、向量的简单应用。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于每条射线，终点减去起点，再单位化后就可以得到这条射线的单位向量，利用这一点可以很简单的将所有守卫的坐标求出来，然后对于每个守卫判断接收的是哪个发射器，判断和之前那个守卫是否相同即可。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">需要注意的是最后一个守卫，当和上一个守卫距离小于</span>0.5<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时候不会建立新的守卫。</span></p>  <p>&nbsp;</p>  <p><strong>I. RIPOFF<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3920<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3920">http://poj.org/problem?id=3920</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>N(N &lt;= 200)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数的一维数组</span>A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，取不大于</span>T+2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数，每相邻两个数之间的下标不大于</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，问最大的取值总和</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">第</span>0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个和第</span>N+1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数必取，且权值为</span>0)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：动态规划。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DP[i][j] <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示第</span>j<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数取</span> A[i]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最大值，那么状态转移方程可以表示为：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DP[i][j] = max{ DP[k][j-1] + A[i], &nbsp;i &gt; k &gt; i-1-S &amp;&amp; k &gt;= 0};</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">特殊的，</span>DP[0][0] = 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，其他的</span>DP[i][j] <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">都初始化为</span>INF;</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">最后计算出的</span>DP[N+1][i]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中的最大值就是答案了。</span></p>  <p>&nbsp; &nbsp; &nbsp; &nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207098.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-05-25 20:33 <a href="http://www.cppblog.com/menjitianya/archive/2014/05/25/207098.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>South America 2002 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/05/18/207005.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sun, 18 May 2014 09:10:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/05/18/207005.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207005.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/05/18/207005.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207005.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207005.html</trackback:ping><description><![CDATA[<p>&nbsp;</p><div style="text-align: center;"><strong><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/soutame2009.png" width="761" height="185" alt="" /></strong></div><strong>A</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>Grandpa's Rubik Cube<br /></strong>&nbsp; &nbsp; &nbsp; &nbsp;PKU 1290<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1290">http://poj.org/problem?id=1290</a><br /><p>&nbsp;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一个</span>3X3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的六面魔方（每个面有</span>3X3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个块），求经过某些旋转之后能否使得所有面的颜色都相同，旋转包括对某个面进行顺时针和逆时针旋转（共</span>12<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">种情况）。</span></p><p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/wght.png" border="0" alt="" width="633" height="215" /></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>A-1</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如图</span>1<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">，输入数据为左图的形式，右图给对应的面编号，箭头方向为顺时针旋转方向。</span></p><p>+A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示对</span>A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这个面进行一次顺时针旋转，</span>-B<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示对</span>B<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">这个面进行一次逆时针旋转。问经过一定的</span>+A/-B<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">操作之后能否使得所有面的</span>3X3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个字母都相同。</span></p><p>&nbsp;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：模拟题</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">做法很多，这里介绍一种比较容易理解的状态记录方式，考虑某次旋转，一定是旋转某个面，然后对邻接的四个面的某条边进行顺次平移。如图</span>A-2, 2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">号面的旋转带动的是</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>5<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>6<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">四个面。</span></p><p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/acad.png" border="0" alt="" width="260" height="209" /></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>A-2</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">我用一个数组</span>rotate_n<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">来记录某个面旋转的时候带动的面的编号集合（编号为</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的数据为占位符），那么有：</span></p><p>int rotate_n [7][4] = {</p><p>&nbsp;&nbsp;&nbsp; {0, 0, 0, 0}, {4, 5, 2, 6}, {1, 5, 3, 6}, {2, 5, 4, 6}, {3, 5, 1, 6}, {1, 4, 3, 2}, {1, 2, 3, 4}</p><p>};</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">光记录带动的面是哪些还不够，还需要知道带动面的对应边，对于一个魔方的一个面，我们编号如下：</span></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>0,0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>0,1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>0,2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>1,0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>1,1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>1,2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>2,0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>2,1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>2,2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分别用</span>1<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">到</span>4<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">来代表一个面的四条边（注意，有方向）：</span></p><p align="center" style="text-align:center">1 (0,2) - (0,0)</p><p align="center" style="text-align:center">2 (2,2) - (0,2)</p><p align="center" style="text-align:center">3 (2,0) - (2,2)</p><p align="center" style="text-align:center">4 (0,0) - (2,0)</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">那么同样用</span>rotate_p<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">来记录某个面旋转的时候带动的面对应的边，则有：</span></p><p>int rotate_p[7][4] = {</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {0, 0, 0, 0}, {2, 4, 4, 4}, {2, 3, 4, 1}, {2, 2, 4, 2}, {2, 1, 4, 3}, {1, 1, 1, 1}, {3, 3, 3, 3},</p><p>};</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这样一来，我们只需要考虑一个面的旋转，然后套用对应的数据即可，还有一个比较巧妙的是，逆时针旋转不需要特殊处理，直接将顺时针旋转执行三次即可。</span></p><p><strong>B</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>This Sentence is False<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1291<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1291">http://poj.org/problem?id=1291</a></p><p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一些句子形如&#8220;</span>Sentence X is true/false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#8221;的句子，</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示第几个句子，问所有的情况是否合法，如果合法，输出最大的可能为真的句子。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span>2-sat<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每个句子抽象成两个结点，为真的时候为</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，为假的时候为</span>X '<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于第</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个句子，如果是</span> Sentence Y is true<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">则这个句子为真的时候，</span> X -&gt;Y<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">连边；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">当这个句子为假的时候，</span>X ' -&gt; Y '<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">连边；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于第</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个句子，如果是</span> Sentence Y is false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">则这个句子为真的时候，</span> X -&gt;Y '<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">连边；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">当这个句子为假的时候，</span>X ' -&gt; Y<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">连边；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">然后求一次强连通，如果最后有某个点</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>X ' <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">在同一个连通图中，说明逻辑错误，说明必然存在不合法的情况，否则对于每个连通分量，求出为真的点的个数和为假的点的个数，然后将他们之中的大者累加，最后答案除</span>2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">就是最大的可能为真的句子（除</span>2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的原因是因为真假是对称的）。</span></p><p><strong>C</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>Will Indiana Jones Get There?<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1292<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1292">http://poj.org/problem?id=1292</a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：营救公主，营救路线要么绕着墙走，要么走两面墙的最短距离（这种情况下需要在两面墙之间搭一块木板，并且可以反复使用）。问营救过程中木板的最短长度。</span></p><p align="center" style="text-align:center"><strong><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/adasd.png" border="0" alt="" width="378" height="215" /></strong></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>C-1</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：线段距离</span> + <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">二分答案</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">因为木板可以反复使用，所以我们可以假设如果木板越长，能够营救公主的概率就越大，反之则越小，所以问题就是求满足两点可达的最小木板长度，可以二分枚举这个长度</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果两面墙的最短距离大于这个</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，表明两面墙不可达，将墙抽象成点，两面墙之间的最短距离可以通过线段和线段的最短距离预处理出来，然后每次二分答案后通过一次搜索就可以找出起点和终点是否可达，复杂度为</span>O<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>n^2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）即计算两线段距离时候的复杂度。</span></p><p><strong>&nbsp;</strong></p><p><strong>D.</strong> <strong>Duty Free Shop<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1293<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1293">http://poj.org/problem?id=1293</a></p><p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>M(M &lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个白巧克力和</span>L(L&lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个黑巧克力，然后给定</span>N(N &lt;= M + L)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个容量为</span>Ci<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的盒子，问能否找到一种方案，使得某些盒子放满白巧克力，剩下的盒子放满黑巧克力。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：背包问题。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">由于需要将每个盒子都放满，于是可以利用一维背包的求法将</span>Ci<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的所有小于等于</span>M<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的可行组合求出来，找到最大的</span>M ' &lt;= M<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且</span>M ' <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">能够通过某种方式被组合出来，那么所有盒子的容量</span>Sum <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">减去</span> M ' <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的差小于等于</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的话，必定能将剩下的盒子填满黑巧克力，否则无解。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这题需要记录前驱，并且注意</span>M = 0 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">以及</span> L = 0 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的情况（主要是在输入的时候判断退出条件，</span>M+L==0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">退出而并非</span> (M&amp;&amp;L) == 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）。</span></p><p>&nbsp;</p><p><strong>E</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>Not Too Convex Hull<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1294<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1294">http://poj.org/problem?id=1294</a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>N(N&lt;=101)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点（没有三点共线的情况），要求用</span>B(B&lt;=50)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">根皮条将这</span>N<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个点圈成</span>B<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个部分，每个部分为一个凸多边形，并且所有凸多边形公用一个点（这个点会给出），求众多方案中满足所有多边形面积和最小的方案。图</span>E-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示用两根皮条圈住</span>19<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点的情况（原点共用了两次）。</span></p><p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asdasdsd.png" border="0" alt="" width="323" height="230" /></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>E-1</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：环形动态规划。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">首先将所有点按照给定的原点进行极坐标排序，那么第</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点到第</span>N<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点必定是按照极坐标严格逆时针排布的（因为没有三点共线），用</span>DP[i][b]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示第</span>i<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个点到第</span>N<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点经过</span>b<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">次分割后分割完的凸多边形的面积总和最小值，那么：</span></p><p>DP[i][b] =min{ area[i][k] +DP[k+1][b-1]&nbsp;&nbsp; (i &lt; k &lt; N) }; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">特殊的，</span>DP[0][0] = 0;</p><p>&nbsp;&nbsp;&nbsp;&nbsp; area[i][j] <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示极坐标在第</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点和第</span>j<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个点之间的所有点</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">包含这两个点</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">加上原点组成的凸包的面积，可以通过初始化预处理出来；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">由于点是极坐标排列的，也就是第一个点不一定是凸包边上的点（有可能是第</span>N-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点到第</span>2<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个点组成的凸包达到整体最优），所以需要做</span>N<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">次</span>DP<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，可以将所有点复制一份，枚举起点</span>i ( 1 &lt;= i &lt;= N)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，终点即</span>i+N, <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">然后分别做一次</span>DP<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">取最小值。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时间复杂度</span>O(N^2 * B)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p><p><strong>&nbsp;</strong></p><p><strong>F</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>I hate SPAM, but some people love it<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1295<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1295">http://poj.org/problem?id=1295</a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：</span>N(N&lt;=20)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个人互发邮件，某个人收到邮件后一定会回复给他所有的好友，回复的数量决定他的称号，按顺序给定首先发起邮件的人，要求按顺序输出所有人得到的称号。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：深搜枚举。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数据量很小，对于给定的初始者作为起点进行遍历，每个人只访问一次，访问到的时候根据他的朋友数量计算他的称号即可。</span></p><p><strong>&nbsp;</strong></p><p><strong>G</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>Noise Effect<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1296<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1296">http://poj.org/problem?id=1296</a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定两个正方形矩阵，求他们的最大相似度，相似度的定义为矩阵元素对应位差值小于等于</span>100<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的个数占所有矩阵元素的百分比（可以进行旋转和翻转）。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：模拟题。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每个矩阵可以进行四次旋转，每次旋转可以有水平翻转、竖直翻转、水平竖直翻转、保持原样四种状态，一共十六种情况（实际小于</span>16<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">种，因为有些状态经过翻转和旋转之后是一样的），对每种情况模拟计算相似度取最大值即可。</span></p><p>&nbsp;</p><p><strong>H</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>Supermarket<br />&nbsp; &nbsp; &nbsp;&nbsp;</strong><strong>&nbsp;</strong>PKU 1297<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1297">http://poj.org/problem?id=1297</a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：约翰需要买</span>M(M&lt;=100)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">件物品，超级市场上的物品都排成一排，一共</span>N(N&lt;=100000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">件物品，他从左向右开始选物品，但是为了不麻烦，不想走回头路，而且第</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个物品买的条件是，前</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">－</span>1<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个物品必须已经买了，但是每个物品在超级市场中的价格不一样，即使同一个物品也有不同的价格，为了花费最少，他想要一个方案使得：</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">按顺序购买</span>M<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个物品；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">总价值最少，并输出这个最小值，如果方案不存在，输出</span>Impossible<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p><p>&nbsp;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：动态规划。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DP[i][j]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示第</span>i<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个购买列表中的物品和第</span>j<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个市场中的物品匹配时的最小消费（</span>1&lt;=i&lt;=M,1&lt;=j&lt;=N<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span>;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Min[i][j]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span>min{ DP [i][x]&nbsp; x&lt;=j };</p><p>&nbsp;&nbsp;&nbsp; a)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">当第</span>i<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个物品和第</span>j<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个市场物品编号相同时，</span>DP[i][j] = Min[i-1][j-1] +cost[j];</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">否则</span>DP[i][j] = inf; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">计算</span>DP<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">数组同时更新</span>Min<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数组，由于每次的状态最多和上一行有关，所以在进行状态转移的时候可以采用滚动数组。时间复杂度</span>O(NM)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p><p>                                                                                                                                                                        </p><p><strong>&nbsp;</strong></p><img src ="http://www.cppblog.com/menjitianya/aggbug/207005.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-05-18 17:10 <a href="http://www.cppblog.com/menjitianya/archive/2014/05/18/207005.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>