﻿<?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++博客-英雄哪里出来-随笔分类-Sgu 题解</title><link>http://www.cppblog.com/menjitianya/category/20894.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 20 Aug 2014 20:53:17 GMT</lastBuildDate><pubDate>Wed, 20 Aug 2014 20:53:17 GMT</pubDate><ttl>60</ttl><item><title>SGU 150 - 159 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/08/14/208001.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Thu, 14 Aug 2014 01:33:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/08/14/208001.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/208001.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/08/14/208001.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/208001.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/208001.html</trackback:ping><description><![CDATA[<strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=150">150&nbsp;Mr. Beetle II</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;">枚举<br /></strong><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=151">151&nbsp;Construct a triangle</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;">解析几何</strong><br /><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=152">152&nbsp;Making round</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</strong><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;">贪心</strong><br /><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=153">153&nbsp;Playing With Matches</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</strong><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;">博弈 + 规律</strong><br /><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=154">154&nbsp;Factorial</a> &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;</strong><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;">初等数论<br /><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=155">155 Cartesian Tree</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RMQ<br /></strong><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=156">156 Strange Graph</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 欧拉回路</strong><br /><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=157">157 Patience</a> &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;模拟打表</strong><br /><div><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=158">158 Commuter &nbsp;Train</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 二分枚举</strong><br /><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=159">159 Self-Replicating Numbers</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 深度优先搜索<br /><br /></strong><br /><div></div></div><strong>150 Mr. Beetle II</strong><br /><p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">枚举<br /><br /></span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;Times New Roman&quot;;">题意：给定两个二维坐标上的点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(x1, y1)</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;">(x2, y2)</span><span style="font-family:宋体;Times New Roman&quot;;">，坐标范围为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;;">[-10<sup>6</sup>, 10<sup>6</sup>]</span><span style="font-family:宋体;Times New Roman&quot;;">。求从一个点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(x1, y1)</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;">(x2, y2)</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;">no solution</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/sgu150_0.png" width="395" height="252" alt="" /><br />图1<br /><br /></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<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;">(x1, y1)</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;">(x2, y2)</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;">(x1, y1)</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, 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><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">x1 &lt; x2</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;">(x1, x2]</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;">[x, x+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;">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;">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;">x1 &gt; x2</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;">(x2, x1]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，用同样的方法进行计算。<br /><br /><br /></span><strong><span style="text-indent: 0px;">151 </span>Construct a triangle</strong></p>  <p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">解析几何<br /><br /></span><span lang="EN-US" style="font-family:
&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p><p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;Times New Roman&quot;;">题意：给定三角形的两条边</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">AB = c</span><span style="font-family:宋体;Times New Roman&quot;;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> AC = b </span><span style="font-family:宋体;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;;">一条中线</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;"> AM = m </span><span style="font-family:宋体;Times New Roman&quot;;">的长度，求一个满足条件的三角形的坐标。</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;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;;">点定在坐标原点，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B</span><span style="font-family:宋体;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;;">轴正方向，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C</span><span style="font-family:宋体;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;;">假设</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A</span><span style="font-family:宋体;Times New Roman&quot;;">在原点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(0, 0)</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; B</span><span style="font-family:宋体;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;;">轴上，则有</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B</span><span style="font-family:宋体;Times New Roman&quot;;">点坐标</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(c, 0)</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;;">假设</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C</span><span style="font-family:宋体;Times New Roman&quot;;">点坐标为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(x, y), </span><span style="font-family:宋体;Times New Roman&quot;;">中线坐标为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> (B + C) / 2</span><span style="font-family:宋体;Times New Roman&quot;;">，即</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> ( (x+c)/2, y/2 ) </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;;">已知</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">AM</span><span style="font-family:宋体;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;;">和</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">AC</span><span style="font-family:宋体;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;;">，则有：</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">x<sup>2</sup> + y<sup>2</sup> = b<sup>2</sup>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(1)</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">((x+c)/2)<sup>2</sup> + (y/2)<sup>2</sup> = m<sup>2</sup> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(2)</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;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;;">，则有</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">-2cx - c<sup>2</sup> = b<sup>2</sup> - 4 * m<sup>2</sup>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (3)</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">x = (4*m<sup>2</sup> -b<sup>2</sup> - c<sup>2</sup>)/2/c;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (4)</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">y<sup>2</sup> = b<sup>2</sup> - x<sup>2</sup>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(5)</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;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;;">，可以推出</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> y<sup>2</sup> = b<sup>2</sup> - x<sup>2</sup> = b<sup>2</sup> - ((4*m<sup>2</sup> -b<sup>2</sup> - c<sup>2</sup>)/2/c ) <sup>2</sup> =&gt;</span><span style="font-family: 'Times New Roman', serif;">[ (b+c) </span><sup style="font-family: 'Times New Roman', serif;">2</sup><span style="font-family: 'Times New Roman', serif;"> - (2m)</span><sup style="font-family: 'Times New Roman', serif;">2</sup><span style="font-family: 'Times New Roman', serif;"> ] * [ - (b-c)</span><sup style="font-family: 'Times New Roman', serif;">2</sup><span style="font-family: 'Times New Roman', serif;"> + (2m)</span><sup style="font-family: 'Times New Roman', serif;">2</sup><span style="font-family: 'Times New Roman', serif;"> ] &gt; 0</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">b+c &gt; 2m </span><span style="font-family:宋体;Times New Roman&quot;;">并且</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> 2m &gt; fabs(b-c)</span><span style="font-family:宋体;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;;">才有解</span><font face="Times New Roman, serif">，</font><span style="font-family: 宋体;">所以当</span><span style="font-family: 'Times New Roman', serif;"> 2*m &gt; (b+c) </span><span style="font-family: 宋体;">或者</span><span style="font-family: 'Times New Roman', serif;">2*m &lt; fabs(b-c) </span><span style="font-family: 宋体;">为无解的情况。</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;;">而我们假设</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C</span><span style="font-family:宋体;Times New Roman&quot;;">在第一象限或者第二象限，所以</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">y&gt;0</span><span style="font-family:宋体;Times New Roman&quot;;">，于是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(x, y)</span><span style="font-family:宋体;Times New Roman&quot;;">可通过</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">(4) (5)</span><span style="font-family:宋体;Times New Roman&quot;;">求得。</span></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/sgu151_0.png" width="409" height="321" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;">图</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2</span></p><p><br /><strong>152 Making round</strong></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">贪心</span><span lang="EN-US" style="font-family:
&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p><p>&nbsp;</p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;Times New Roman&quot;;">题意：给定</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 10000)</span><span style="font-family:宋体;Times New Roman&quot;;">个数，求每个数在所有数中所占百分比，要求输出的数之和为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">100</span><span style="font-family:宋体;Times New Roman&quot;;">，每个数可以进行上下取整。如：给定三个数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">3 3 3</span><span style="font-family:宋体;Times New Roman&quot;;">，那么输出为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> 34 33 33</span><span style="font-family:宋体;Times New Roman&quot;;">。</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">34</span><span style="font-family:宋体;Times New Roman&quot;;">为向上取整的结果，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">33</span><span style="font-family:宋体;Times New Roman&quot;;">为向下取整的结果。</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;Times New Roman&quot;;">题解：</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 'Times New Roman', serif;">1</span><span style="font-family: 宋体;">）首先求得所有数之和</span><span style="font-family: 'Times New Roman', serif;">S</span><span style="font-family: 宋体;">，将每个数</span><span style="font-family: 'Times New Roman', serif;">a[i]</span><span style="font-family: 宋体;">除上</span><span style="font-family: 'Times New Roman', serif;">S</span><span style="font-family: 宋体;">得到商</span><span style="font-family: 'Times New Roman', serif;">B[i]</span><span style="font-family: 宋体;">和余数</span><span style="font-family: 'Times New Roman', serif;">M[i]</span><span style="font-family: 宋体;">。</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;;">）如果余数为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">0</span><span style="font-family:宋体;Times New Roman&quot;;">表示为整除，不能进行上下取整。</span><span style="font-family: 宋体;">如果余数不为</span><span style="font-family: 'Times New Roman', serif;">0</span><span style="font-family: 宋体;">，说明它有</span><span style="font-family: 'Times New Roman', serif;"> +1 </span><span style="font-family: 宋体;">或者</span><span style="font-family: 'Times New Roman', serif;"> +0 </span><span style="font-family: 宋体;">的机会。</span> <span style="font-family: 宋体;">（因为题目说可以上取整，也可以下取整）</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">3) </span><span style="font-family:宋体;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;;">。</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">4</span><span style="font-family:宋体;Times New Roman&quot;;">）将所有数的商之和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Sum{B[i]} </span><span style="font-family:宋体;Times New Roman&quot;;">和</span> <span style="font-family:宋体;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;;">相加，如果小于</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">100</span><span style="font-family:宋体;Times New Roman&quot;;">，则表明必定无解。</span><span style="font-family: 宋体;">否则扫描数组，将</span><span style="font-family: 'Times New Roman', serif;"> X = 100-Sum{B[i]}-T </span><span style="font-family: 宋体;">的值分派给每个不能整除的数即可（每个数只可分派</span><span style="font-family: 'Times New Roman', serif;">1</span><span style="font-family: 宋体;">）。</span></p>  <p>&nbsp;</p><p><strong>153 Playing with matches</strong><br /></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">博弈</span><span lang="EN-US" style="font-family:
&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p><p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<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;">(N &lt;= 10<sup>9</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;; background:white">1,P1,P2,...,Pm (2&lt;=Pi&lt;=9, 0&lt;=m&lt;=8)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;background:white">根，两人分别轮次进行拾取，并且总是按照最优策略去取，最后取完火柴的人为输的人，问当前状态是否是一个必胜状态。</span></p>  <p><span style=" font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;; background:white">题解：经典博弈，对于给定状态</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;background:white">X</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;background:white">：</span></p>  <p><span style=" font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;background:white">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1)&nbsp;</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;; background:white">如果按照所有方式取，最后都只能让对手到达必胜状态，那么</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;; background:white">X</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;; background:white">为必败状态；</span></p>  <p><span style=" font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;background:white">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2)&nbsp;</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;; background:white">如果对于某种取法，可以让对手达到必败状态，那么</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;; background:white">X</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;; background:white">为必胜状态；</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=" font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">3)&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;">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></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<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;= 10<sup>9</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;">Pi</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;">9</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;">5000</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;">len</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;">N % len</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的状态值。</span></p>  <p>&nbsp;</p><p><strong>154 Factorial</strong></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">二分统计</span><span lang="EN-US" style="font-family: 'Times New Roman', serif; color: #ff6600;"> + </span><span style="font-family: 宋体; color: #ff6600;">初等数论</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p><p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp;<br /></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;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;;">，求一个最小的数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K</span><span style="font-family:宋体;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;;">末尾正好有</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N</span><span style="font-family:宋体;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;;">。</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;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;;">中的质因子中</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">5</span><span style="font-family:宋体;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;;">的个数少，所以求末尾有多少个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">0</span><span style="font-family:宋体;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;;">中有多少个质因子</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">5</span><span style="font-family:宋体;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;;">、</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">10</span><span style="font-family:宋体;Times New Roman&quot;;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">15</span><span style="font-family: 宋体;Times New Roman&quot;;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">25</span><span style="font-family:宋体;Times New Roman&quot;;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">30</span><span style="font-family:宋体;Times New Roman&quot;;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">35</span><span style="font-family:宋体;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;;">中，对于</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;"> K!</span><span style="font-family:宋体;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;;">的倍数提出来，剩下部分为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;">，则有：</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K! = 1*2*3*4*5*...(K-1)*K = 5 * 10 * 15 * ... * (1*2*3*4*6*7*8*9*11*12*13*14*16*...K) = 5*10*15*...* T = 5* (1*2*3...) * T = 5 * T * K'! </span><span style="font-family:宋体;Times New Roman&quot;;">，</span> <span style="font-family:宋体;Times New Roman&quot;;">我们发现</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">5*T</span><span style="font-family: 宋体;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;;">的质因子个数为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;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;;">中的</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">5</span><span style="font-family:宋体;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;;">中质因子为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">5</span><span style="font-family:宋体;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;;">的问题，递归方程为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> S[ K ] = K/5 + S[K/5] ( K &gt; 0 ) </span><span style="font-family:宋体;Times New Roman&quot;;">当</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K = 0</span><span style="font-family:宋体;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;;">，即递归出口。</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;;">那么就可以二分枚举一个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K</span><span style="font-family:宋体;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;;">中</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">5</span><span style="font-family:宋体;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;;">比较，如果找不到一个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K</span><span style="font-family:宋体;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;;">质因子的个数为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N</span><span style="font-family:宋体;Times New Roman&quot;;">则无解，否则找一个最小的。</span></p>  <p>&nbsp;</p><p><strong>155 Cartesian Tree</strong></p><p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span lang="EN-US" style="color: #ff6600;">RMQ(or ZigZag)</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>N(N &lt;= 50000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个整数对</span>(key, a)<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>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>(<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;2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">当前结点的</span>key<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">值大于左子树的</span>key<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">值，并且小于右子树的</span>key<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;&nbsp;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题目保证所有的</span>key<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></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：首先将所有整数对按</span>key<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>[1, t-1]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">必定是它的左子树集合，</span>[t+1, N]<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>a<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>a<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">值最小的，于是可以规约出一个递归算法，对于当前区间</span>[l, r]<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>[1, N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，当</span>[l, r]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">满足</span> l &gt; r<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: 宋体;">总的时间复杂度为排序的时间复杂度</span>O(N log N)<span style="font-family: 宋体;">。</span></p>  <p>&nbsp; &nbsp; &nbsp; RMQ 资料参阅 <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><br /></p><p><br /><strong>156 Strange Graph</strong></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">欧拉回路<br /></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体;">题意：给定一个</span>N(N &lt;= 10000)<span style="font-family: 宋体;">个点的连通图，这个图满足以下性质：<br /></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1) <span style="font-family: 宋体;">每个顶点</span>v<span style="font-family: 宋体;">的度数都大于等于</span>2<font face="宋体">；<br /></font>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2) <span style="font-family: 宋体;">如果顶点</span>v<span style="font-family: 宋体;">的度数等于</span>2<span style="font-family: 宋体;">，那么它连接的两个顶点不相邻；<br /></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3) <span style="font-family: 宋体;">如果顶点</span>v<span style="font-family: 宋体;">的度数大于</span>2<span style="font-family: 宋体;">，那么和</span>v<span style="font-family: 宋体;">相邻的点</span>u<span style="font-family: 宋体;">满足以下条件之一；<br /></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a) u<span style="font-family: 宋体;">的度数等于</span>2<span style="font-family: 宋体;">；<br /></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b) <span style="font-family: 宋体;">任何和</span>v<span style="font-family: 宋体;">相邻的点</span>(<span style="font-family: 宋体;">除了</span>u)<span style="font-family: 宋体;">中都两两相邻；</span></p>  <p>&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></p>  <p style="text-indent:21.0pt"><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;</p>  <p><strong>157 Patience</strong></p><p class="MsoNormal"><span style="color: #ff6600;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 宋体; color: #ff6600;">打表题<br /></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体;">题意：给定</span><span style="font-family: 'Times New Roman', serif;">N(1 &lt;= N &lt;= 13)</span><span style="font-family: 宋体;">，表示</span><span style="font-family: 'Times New Roman', serif;">(1 2 3 ... N </span><span style="font-family: 宋体;">空</span><span style="font-family: 'Times New Roman', serif;">)</span><span style="font-family: 宋体;">这</span><span style="font-family: 'Times New Roman', serif;">N+1</span><span style="font-family: 宋体;">个位置，其中</span><span style="font-family: 'Times New Roman', serif;">N</span><span style="font-family: 宋体;">个位置随机排放着</span><span style="font-family: 'Times New Roman', serif;">1-N</span><span style="font-family: 宋体;">中的某一张牌，每次可以在&#8220;空&#8221;左边的位置找到一张牌</span><span style="font-family: 'Times New Roman', serif;">K</span><span style="font-family: 宋体;">，然后将</span><span style="font-family: 'Times New Roman', serif;">K+1</span><span style="font-family: 宋体;">这张牌放在&#8220;空&#8221;的位置上，问哪些初始状态可以到达一个状态使得前</span><span style="font-family: 'Times New Roman', serif;">N</span><span style="font-family: 宋体;">个格子的牌有序排列（第</span><span style="font-family: 'Times New Roman', serif;">N+1</span><span style="font-family: 宋体;">个位置留空）。<br /></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体;">题解：从</span><span style="font-family: 'Times New Roman', serif;">(1 2 3 ... N </span><span style="font-family: 宋体;">空</span><span style="font-family: 'Times New Roman', serif;">)</span><span style="font-family: 宋体;">这个状态起，反向模拟，能够到达的状态都是可达状态，统计所有可达状态的个数，</span><span style="font-family: 'Times New Roman', serif;">N</span><span style="font-family: 宋体;">的最大值为</span><span style="font-family: 'Times New Roman', serif;">13</span><span style="font-family: 宋体;">，时间上不允许可以客户端计算出值然后打表！</span></p>  <p><br /><strong>158 Commuter Train</strong></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">二分枚举</span></p><p><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：车站长度为</span>L(L &lt;= 5000)<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&lt;= 300<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;= 300<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><span style="font-family: 宋体;">仔细想一下，最大值不一定出现在整点上，也有可能出现在</span>0.5<span style="font-family: 宋体;">的位置上，所以可以将所有坐标都乘</span>2<span style="font-family: 宋体;">，然后最后答案再除二避免精度误差。</span></p>  <p>&nbsp;</p><p><strong>159 Self-Replicating Numbers</strong><br /></p><p class="MsoNormal"><span style="color: #ff6600;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 宋体; color: #ff6600;">深度优先搜索</span><span lang="EN-US" style="font-family:
&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p><p><br /></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;Times New Roman&quot;;">题意：</span><span style="font-family:宋体;Times New Roman&quot;;">求</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 2000)</span><span style="font-family:宋体;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;;">进制数中平方的最后几位等于</span><span style="font-family: 宋体;">该数本身的数的个数。</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;Times New Roman&quot;;">题解：利用</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">dfs</span><span style="font-family:宋体;Times New Roman&quot;;">从最后面一位</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">digit</span><span style="font-family:宋体;Times New Roman&quot;;">开始枚举</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">[0, B)</span><span style="font-family:宋体;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;;">位完毕，则将解保存，这里需要注意当</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N</span><span style="font-family:宋体;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;;">的时候，最高位可以为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">0</span><span style="font-family:宋体;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;;">的情况需要去掉（最高位为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">0</span><span style="font-family:宋体;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;;">位数（</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N&gt;1</span><span style="font-family:宋体;Times New Roman&quot;;">））。</span></p><p><br /><br /></p><img src ="http://www.cppblog.com/menjitianya/aggbug/208001.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-14 09:33 <a href="http://www.cppblog.com/menjitianya/archive/2014/08/14/208001.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SGU 140 - 149 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/07/06/207542.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sun, 06 Jul 2014 05:00:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/07/06/207542.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207542.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/07/06/207542.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207542.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207542.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 140 Integer Sequences&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;数论：扩展欧几里得141 Jumping Joe&nbsp; &n...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2014/07/06/207542.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/207542.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-06 13:00 <a href="http://www.cppblog.com/menjitianya/archive/2014/07/06/207542.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SGU 130 - 139 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/06/23/207386.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Mon, 23 Jun 2014 11:08:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/06/23/207386.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207386.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/06/23/207386.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207386.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207386.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 130 Circle &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; &n...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2014/06/23/207386.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/207386.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-23 19:08 <a href="http://www.cppblog.com/menjitianya/archive/2014/06/23/207386.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SGU 120 - 129 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/06/17/207316.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Tue, 17 Jun 2014 11:07:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/06/17/207316.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207316.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/06/17/207316.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207316.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207316.html</trackback:ping><description><![CDATA[<strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><font color="#1d58d1"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=120">120 Archipelago</a></font>&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;</strong><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;">计算几何：射线旋转</strong><br /><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><font color="#1d58d1" style="color: #1d58d1; text-decoration: none;"></font><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=121"><font color="#1d58d1" style="color: #1d58d1; text-decoration: none;">121</font><font color="#1d58d1">&nbsp;Bridges painting</font></a><font color="#1d58d1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">图论：染色问题</span></font></strong><br /><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=122">122 The Book</a>&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;图论：哈密尔顿回路</strong><br /><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=123">123 The Sum</a>&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;递推</strong><br /><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=124">124 Broken Line</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 计算几何：线段判交<a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=123"><br /></a></strong><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=125">125 shtirlits</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;搜索：深度优先搜索</strong><br /><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=126">126&nbsp;boxes</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;初等数论</strong><br /><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=127">127&nbsp;Telephone directory</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 排序</strong><br /><span style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"><strong><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=128">128&nbsp;Snake</a></strong></span><strong style="background-color: #ffffff; font-family: Tahoma; font-size: 12pt;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;排序 + HASH</strong><br /><strong style="font-family: Tahoma; font-size: 16px;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=129">129&nbsp;Inheritance</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 计算几何：凸包+线段判交</strong><br /><br /><br /><strong>120 Archipelago</strong><br /><p>&nbsp; &nbsp; &nbsp; &nbsp;<span style="font-family: 宋体; color: #ff6600;">计算几何：射线旋转<br /><br /></span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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>&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></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">然后就是要求某个点绕中心点旋转</span>360/N<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></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>alpha<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">角度后的单位向量</span>I<sub>a</sub><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>alpha<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">已知，</span>I<sub>x</sub><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是我们需要求的。那么有以下两个方程：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) I.x * I<sub>a</sub>.x + I.y * I<sub>a</sub>.y = cos( alpha )</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) I<sub>a</sub>.x<sup>2</sup> + I<sub>a</sub>.y<sup>2</sup> = 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>I<sub>a</sub>.x<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">用</span>I<sub>a</sub>.y<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>I<sub>a</sub>.x<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，但是解肯定只有一个，可以用叉乘关系排除掉另外一个解。<br /><br /></span></p>  <p><strong>121 Bridges painting</strong><br /></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">图论：DFS构造</span></p><p><br /></p><p style="text-indent:21.0pt"><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>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></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></p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><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="margin-left:21.0pt;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">度数</span> &gt; 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，说明必然存在环；</span></p>  <p style="margin-left:42.0pt;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果是偶数环，那么经过一系列的交错染色，最后必然能够在该结点上收获两条颜色不一样的边；</span></p>  <p style="margin-left:42.0pt;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></p>  <p style="text-indent:21.0pt"><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>1<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>7<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>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>1<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/sgu121_0.png" width="372" height="289" 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>1</p>  <p align="center" style="text-align:center;text-indent:21.0pt"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/sgu121_1.png" width="374" height="258" 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<br /><br /></p><div style="text-align: left;"><strong>122 The book</strong><br /><p>&nbsp; &nbsp; &nbsp; <span style="color: #ff6600;">哈密尔顿回路问题：Ore</span><span style="font-family: 宋体; color: #ff6600;">定理</span><span style="color: #ff6600;"> + </span><span style="font-family: 宋体; color: #ff6600;">构造</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;"><br /><br /></span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>N(N &lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点连成的图，每个点度数大于等于</span>(N+1)/2<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">1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）首先假设已经得到了一个环</span>R<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>R<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的顶点个数为</span>r<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">），那么在未选到环内的点集</span>R<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#8217;中必然能够找到某个点</span>k<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和环</span>R<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>R<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和环外的点集</span>R<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#8217;互不连通，为两个连通分量，和题意相左（因为每个点的度数大于等于（</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>R&#8217;<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>R<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>j<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>r+1<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>s<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>r+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>k<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>k<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>k<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>k<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">和剩下点集</span>R<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#8217;没有点相连，所以我们只能在这条长链上找和</span>k<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>k<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">本身不就有个链内的点连着嘛，不然它就是个孤立点了）</span><span style="text-indent: 0px; font-family: 宋体;">。所以找到</span><span style="text-indent: 0px;">(k , t)</span><span style="text-indent: 0px; font-family: 宋体;">相连，并且</span><span style="text-indent: 0px;">(s, t+1) </span><span style="text-indent: 0px; font-family: 宋体;">相连，然后删掉</span><span style="text-indent: 0px;">(t, t+1)</span><span style="text-indent: 0px; font-family: 宋体;">这条边，就能够得到一个新的环了，如果此时环的长度为</span><span style="text-indent: 0px;">n</span><span style="text-indent: 0px; font-family: 宋体;">就结束了，否则继续</span><span style="text-indent: 0px;">1</span><span style="text-indent: 0px; font-family: 宋体;">）。</span></p>  <p>&nbsp;</p><div style="text-align: center;"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/sgu122_0.png" width="540" height="140" alt="" /></div><div style="text-align: center;">图3</div><br /><strong>123 The sum</strong><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">递推</span><span lang="EN-US" style="font-family:
&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p><p><br /></p><p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family:宋体;Times New Roman&quot;;">题意：求斐波那契数列的第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 40)</span><span style="font-family:宋体;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;">__int64</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数组预处理即可。<br /></span></p>  <p><br /><strong>124 Broken line</strong></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">计算几何</span><font face="宋体"><span style="color: #ff6600;">:</span></font><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;</span><span style="font-family: 宋体; color: #ff6600;">线段判交</span><span lang="EN-US" style="font-family:
&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p><p><br /></p><p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family:宋体;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;;">是否在这个闭合线段内。</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;;">题解：其实就是判断一个点是否在多边形内；</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;;">首先，虚拟出一个无穷远的点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Q</span><span style="font-family:宋体;Times New Roman&quot;;">，然后用</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">PQ</span><span style="font-family:宋体;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;;">两线段判交在黑书上有详尽的解释</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">,</span><span style="font-family:宋体;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;;">。</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;;">如果</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">P</span><span style="font-family:宋体;Times New Roman&quot;;">在某条线段上，输出</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">BORDER</span><span style="font-family:宋体;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;;">如果</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">PQ</span><span style="font-family:宋体;Times New Roman&quot;;">和所有线段交点个数为奇数，说明在多边形内，输出</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">INSIDE</span><span style="font-family:宋体;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;;">如果</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">PQ</span><span style="font-family:宋体;Times New Roman&quot;;">和所有线段交点个数为偶数，说明在多边形外，输出</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">OUTSIDE</span><span style="font-family:宋体;Times New Roman&quot;;">；</span></p>  <p>&nbsp;</p></div><p><strong>125 Shtirlits</strong><br /></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">深度优先搜索</span><span lang="EN-US" style="font-family: 'Times New Roman', serif; color: #ff6600;"> + </span><span style="font-family: 宋体; color: #ff6600;">剪枝</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></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;;">题意：给定一个矩阵</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B (3X3)</span><span style="font-family:宋体;Times New Roman&quot;;">，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B[i][j]</span><span style="font-family:宋体;Times New Roman&quot;;">表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A[i][j]</span><span style="font-family:宋体;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;;">。</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;;">题解：枚举</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A[i][j]</span><span style="font-family:宋体;Times New Roman&quot;;">的每个数字，数字的范围为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> [0,9]</span><span style="font-family:宋体;Times New Roman&quot;;">。复杂度</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">10<sup>9</sup></span><span style="font-family:宋体;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; a)&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;">首先，可以肯定这</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B[i][j]</span><span style="font-family:宋体;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;;">，因为总有一个数没有比它大的数（高处不胜寒啊~~）。</span><span style="font-family: 宋体;">对于</span><span style="font-family: 'Times New Roman', serif;">B[i][j] == 0</span><span style="font-family: 宋体;">的格子，将</span><span style="font-family: 'Times New Roman', serif;">A[i][j]</span><span style="font-family: 宋体;">设为最大值</span><span style="font-family: 'Times New Roman', serif;">9</span><span style="font-family: 宋体;">一定不会错，所以复杂度至少可以降到</span><span style="font-family: 'Times New Roman', serif;"> 10<sup>8</sup> </span><span style="font-family: 宋体;">了。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b)&nbsp;&nbsp; </span><span style="font-family:宋体;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;;">的每个非</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">9</span><span style="font-family: 宋体;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;;">，然后对每个格子进行枚举，枚举范围为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> [ 0, 8 ], </span><span style="font-family:宋体;Times New Roman&quot;;">因为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">B[i][j]</span><span style="font-family:宋体;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;;">如果</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A[i][j]==9</span><span style="font-family:宋体;Times New Roman&quot;;">，那么</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B[i][j]</span><span style="font-family:宋体;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;;">，复杂度降至</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;9<sup>8</sup></span><span style="font-family:宋体;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; c)&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;">每次枚举完毕，进入下一个数的枚举之前，进行全局的检测，对于每个格子统计以下数据：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="font-family: 'Times New Roman', serif;">i) &nbsp; &nbsp;</span><span style="font-family: 宋体;">已经枚举的邻居格子</span><span style="font-family: 'Times New Roman', serif;">&nbsp; &nbsp; &nbsp; H</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp;</span>&nbsp; &nbsp; &nbsp; &nbsp;<span style="font-family: 'Times New Roman', serif;">ii) &nbsp;&nbsp;</span><span style="font-family: 宋体;">总共有多少个邻居格子</span><span style="font-family: 'Times New Roman', serif;"> &nbsp;&nbsp;T</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iii) &nbsp;&nbsp;</span><span style="font-family:宋体;Times New Roman&quot;;">比自己大的邻居格子</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp;B</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;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;&nbsp;&nbsp; x) </span><span style="font-family:宋体;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;;">即</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> B &gt; B[i][j]</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; y) </span><span style="font-family:宋体;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;;">剩余未知邻居数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> &lt; </span><span style="font-family:宋体;Times New Roman&quot;;">给定比它大的邻居数，</span> <span style="font-family:宋体;Times New Roman&quot;;">即</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> B + (T-H) &lt; B[i][j]</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;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; d)&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;">直到所有数枚举完毕，输出解即可。</span></p>  <p>&nbsp;</p><p><strong>126 Boxes</strong></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">初等数论</span><span lang="EN-US" style="font-family:
&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></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;;">题意：对于给定的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A</span><span style="font-family:宋体;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;;">，</span></p>  <p><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;;">如果</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A &gt; B, </span><span style="font-family:宋体;Times New Roman&quot;;">则状态变为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;"> (A-B, 2*B)</span></p>  <p><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;;">如果</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A &lt; B, </span><span style="font-family:宋体;Times New Roman&quot;;">则状态变为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;"> (2*A, B-A)</span></p>  <p><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;;">当</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> A == B </span><span style="font-family:宋体;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; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;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;;">。</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;;">题解：根据题意，可以得出一些简单的推论：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp;</span>&nbsp; &nbsp;<span style="font-family: 'Times New Roman', serif;">a) </span><span style="font-family: 宋体;">当</span><span style="font-family: 'Times New Roman', serif;">A == 0 </span><span style="font-family: 宋体;">或者</span><span style="font-family: 'Times New Roman', serif;"> B == 0 </span><span style="font-family: 宋体;">时</span><span style="font-family: 'Times New Roman', serif;"> </span><span style="font-family: 宋体;">答案为</span><span style="font-family: 'Times New Roman', serif;"> 0</span><span style="font-family: 宋体;">。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;<span style="font-family: 'Times New Roman', serif;">&nbsp;b) </span><span style="font-family: 宋体;">最后</span><span style="font-family: 'Times New Roman', serif;">A == B</span><span style="font-family: 宋体;">的时候，必定是</span><span style="font-family: 'Times New Roman', serif;">K = (A+B)/2</span><span style="font-family: 宋体;">，所以当</span><span style="font-family: 'Times New Roman', serif;">A+B</span><span style="font-family: 宋体;">为奇数时答案不存在。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp;</span>&nbsp; &nbsp;<span style="font-family: 'Times New Roman', serif;">c) </span><span style="font-family: 宋体;">定义最后的状态二元组为</span><span style="font-family: 'Times New Roman', serif;"> (K, K),</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体;">倒数第二次的操作必定为</span><span style="font-family: 'Times New Roman', serif;"> (3K/2,K/2) &nbsp;</span><span style="font-family: 宋体;">或者</span><span style="font-family: 'Times New Roman', serif;">(K/2,3K/2)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(2</span><span style="font-family: 宋体;">种</span><span style="font-family: 'Times New Roman', serif;">)</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体;">倒数第三次的操作必定为</span><span style="font-family: 'Times New Roman', serif;"> (7K/4, K/4) </span><span style="font-family: 宋体;">或者</span><span style="font-family: 'Times New Roman', serif;"> (3K/4, 5K/4) </span><span style="font-family: 宋体;">或者</span><span style="font-family: 'Times New Roman', serif;"> (5K/4, 3K/4) </span><span style="font-family: 宋体;">或者</span><span style="font-family: 'Times New Roman', serif;"> (K/4, 7K/4) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (4</span><span style="font-family: 宋体;">种</span><span style="font-family: 'Times New Roman', serif;">)</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体;">倒数第四次操作</span><span style="font-family: 'Times New Roman', serif;">(15K/8,K/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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (8</span><span style="font-family: 宋体;">种</span><span style="font-family: 'Times New Roman', serif;">)</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体;">倒数第</span><span style="font-family: 'Times New Roman', serif;">i</span><span style="font-family: 宋体;">次操作</span><span style="font-family: 'Times New Roman', serif;"> ( (2<sup>(i-1)</sup>-1)/2<sup>(i-1)</sup> * K, 1/2<sup>(i-1)</sup> * K ) ... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(2<sup>(i-1)</sup> </span><span style="font-family: 宋体;">种</span><span style="font-family: 'Times New Roman', serif;">)</span></p>  <p>&nbsp;</p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp;</span>&nbsp; &nbsp;<span style="font-family: 'Times New Roman', serif;">d) A</span><span style="font-family: 宋体;">和</span><span style="font-family: 'Times New Roman', serif;">B</span><span style="font-family: 宋体;">的组合必定在这些情况中找。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span>&nbsp; &nbsp;<span style="font-family: 宋体;">于是定义</span><span style="font-family: 'Times New Roman', serif;"> A = L1 / 2<sup>n</sup> * K,&nbsp; B = L2 / 2<sup>n</sup> * K&nbsp; (</span><span style="font-family: 宋体;">其中</span><span style="font-family: 'Times New Roman', serif;">K = (A+B)/2, L1,L2</span><span style="font-family: 宋体;">为奇数，并且</span><span style="font-family: 'Times New Roman', serif;">(L1+L2) = 2<sup>(n+1)</sup>)</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体;">得：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 'Times New Roman', serif;">L1 = 2</span><sup style="font-family: 'Times New Roman', serif;">n </sup><span style="font-family: 'Times New Roman', serif;">* (A/K)</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 'Times New Roman', serif;">L2 = 2</span><sup style="font-family: 'Times New Roman', serif;">n</sup><span style="font-family: 'Times New Roman', serif;"> * (B/K)</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;">令</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> A = 2<sup>a</sup> * A', K = 2<sup>k</sup> * K'</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;">则有</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> L1 = 2<sup>(n+a-k)</sup> * A'/K' </span><span style="font-family:宋体;Times New Roman&quot;;">为奇数，所以</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">n+a-k = 0</span><span style="font-family:宋体;Times New Roman&quot;;">，并且要保证</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A' mod K' == 0，</span><span style="font-family: 'Times New Roman', serif;">A </span><span style="font-family: 宋体;">和</span><span style="font-family: 'Times New Roman', serif;"> K </span><span style="font-family: 宋体;">都为已知，则可以计算出</span><span style="font-family: 'Times New Roman', serif;"> a </span><span style="font-family: 宋体;">、</span><span style="font-family: 'Times New Roman', serif;">A'</span><span style="font-family: 宋体;">、</span><span style="font-family: 'Times New Roman', serif;">k</span><span style="font-family: 宋体;">、</span><span style="font-family: 'Times New Roman', serif;">K'</span><span style="font-family: 宋体;">，最终的步数就是</span><span style="font-family: 'Times New Roman', serif;">k-a+1</span><span style="font-family: 宋体;">。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-family:宋体;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;;">或</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B</span><span style="font-family:宋体;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;;">的情况，以及</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A+B</span><span style="font-family:宋体;Times New Roman&quot;;">为奇数的情况。</span></p>  <p><br /></p><p><strong>127 Telephone directory</strong></p><p>&nbsp; &nbsp; &nbsp; 将所有电话号码按首字母排序，统计每个首字母出现的次数Ai， Sum{ (Ai + K - 1 ) / K } + 2 就是答案。</p><p><br /><strong>128 Snake</strong><br /></p><p class="MsoNormal">&nbsp; &nbsp; &nbsp; &nbsp;<span style="font-family: 宋体; color: #ff6600;">想法题</span></p><p><br /></p><p>&nbsp; &nbsp; &nbsp; &nbsp;<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>4&lt;=N&lt;=10000<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></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">所有的点都是多边形上的点，并且只能被用一次；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">任何两个连续的线段需要组成一个</span>90<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">度的直角；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">多边形的所有边都要平行于坐标轴；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">多边形不能存在自交；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f) <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>PX<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>PY<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">，并且记录每个点在原数组的下标</span>index<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>PX<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>PY<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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对</span>PX<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中序号为奇数的点</span>PX[i]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和它的下一个点</span>PX[i+1]<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>y<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">值不相等，那么说明这个点无法加入多边形中（</span>PX[i]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">无法配对，被孤立了），无解。否则</span>PX[i].index<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>PX[i+1].index<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">必然有一条边（可以用邻接表来存边关系，因为最后求的是一个多边形，所以每个点有且仅有两条边，其实就是一个哈密尔顿回路）。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">并且加</span>PX[i+1].x - PX[i].index <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">累加到答案</span>ans<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对</span>PY<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>1<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>(1,1) - (2,1)&nbsp; (1,2) -(3, 2)&nbsp;&nbsp; (2,3) - (3,3)<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>(1,1)-(1,2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span> (3,2) - (3, 3)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">都是没问题的，唯独</span> (2,1) - (2,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> (1,2) -(3, 2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">会产生自交，违反了</span>e<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/sgu128_0.png" width="244" height="210" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>1</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>4)<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 align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/sgu128_1.png" width="179" height="162" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>2</p>  <p><strong>129 Inheritance</strong></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">解析几何</span><span lang="EN-US" style="color: #ff6600;">&nbsp;+&nbsp;</span><span style="font-family: 宋体; color: #ff6600;">凸包</span><span lang="EN-US" style="color: #ff6600;"> + </span><span style="font-family: 宋体; color: #ff6600;">线段判交</span><span style="font-family:宋体;mso-ascii-font-family:Calibri;
mso-hansi-font-family:Calibri"><br /><br /></span></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="font-family:宋体;">题意：给定一个多边形和若干线段，这个多边形内任意两点连线不会和多边形边界相交，分别求这些线段在多边形内部的长度。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;">题解：首先，根据&#8220;多边形内任意两点连线不会和多边形边界相交&#8221;可以肯定这是个凸多边形，于是问题就转化成了求某条线段和凸多边形相交后线段在多边形内部分的长度。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;">由于给定的点是乱序的，所以最简单的方法是求这些点集的一个凸包，构造出一个按点排序的多边形，相邻两点连线为原多边形的一条边。</span></p>  <p><span style="font-family:宋体;">那么枚举每条边和给定线段的相交情况：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) <span style="font-family:宋体;">不相交（平行），继续判断下一条边；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) <span style="font-family:宋体;">共线，直接跳出枚举，（由于是凸多边形，改线段肯定不可能在多边形内）；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) <span style="font-family:宋体;">相交，将这个交点存入集合</span>S<span style="font-family: 宋体;">；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;">将原线段的两个端点存入集合</span>S<span style="font-family:宋体;">，对集合</span>S<span style="font-family:宋体;">的点进行</span>x<span style="font-family:宋体;">坐标递增排序（</span>x<span style="font-family:宋体;">相同时</span>y<span style="font-family:宋体;">坐标递增排序），然后枚举相邻两个点的中点，判断是否在在原多边形内，如果在，那么将这两个相邻点练成的线段的长度累加到最后的答案中。如图</span>1<span style="font-family:宋体;">为两个交点的情况。</span></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/sgu129_0.png" width="408" height="368" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-family:宋体;">图</span>1</p><p><br /><br /><br /></p><img src ="http://www.cppblog.com/menjitianya/aggbug/207316.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-17 19:07 <a href="http://www.cppblog.com/menjitianya/archive/2014/06/17/207316.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SGU 110 - 119 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/06/12/207263.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Thu, 12 Jun 2014 04:49:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/06/12/207263.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207263.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/06/12/207263.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207263.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207263.html</trackback:ping><description><![CDATA[<strong style="font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=110">110 Dungeon</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 计算几何：射线和球体相交<br /></strong><strong style="font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=111">111 Very simple problem</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 二分枚举<br /></strong><strong style="font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=112">112 a^b-b^a</a> &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;</strong><br /><strong style="font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=113">113&nbsp;Nearly prime numbers</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 数论：素数筛选<br /></strong><strong style="font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=114">114&nbsp;Telecasting station</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 枚举</strong><br /><strong style="font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=115">115&nbsp;Calendar</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;简单模拟</strong><br /><strong style="font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=116">116&nbsp;Index of super-prime</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;动态规划：记忆化搜索</strong><br /><strong style="font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=117">117&nbsp;Counting</a>&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;</strong><strong style="font-family: Tahoma; font-size: 12pt;">二分求幂</strong><br /><strong style="font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=118">118&nbsp;Digital Root</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 数学题</strong><br /><strong style="font-family: Tahoma; font-size: 12pt;"><a href="http://acm.sgu.ru/problem.php?contest=0&amp;problem=119">119&nbsp;Magic Pairs</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;数论：扩展欧几里得</strong><br /><br /><br /><strong>110 Dungeon</strong><br /><p>&nbsp; &nbsp; &nbsp;&nbsp;<span style="font-family: Tahoma; font-size: 12pt; color: #ff6600;">计算几何：射线和球体相交</span><span style="font-family: Tahoma; font-size: 12pt;"><br /></span><br /><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">题意：给定一条</span><span style="font-size:12.0pt;font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">3D</span><span style="font-size:12.0pt;font-family: 宋体;Times New Roman&quot;;">射线</span> <span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">和</span><span style="font-size:12.0pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> N</span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">个球体，问射线的各种反弹经过的球体编号，如果反射超过</span><span style="font-size: 12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">10</span><span style="font-size: 12.0pt;font-family:宋体;Times New Roman&quot;;">次，只需要输出前十次。</span></p>  <p><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">题解：很明显，首先需要枚举每个球体和当前射线的相交情况，如果和多个球体相交肯定是取距离最近的球体进行相交计算，然后计算出空间反射射线，重复以上操作</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">11</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">次，如果某次的反射射线已经不能和任何球体相交那么直接跳出这个过程。</span></p>  <p>&nbsp;</p><div style="text-align: center;"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/sgu110_0.png" width="552" height="445" alt="" style="font-family: 'Times New Roman', serif; font-size: 12pt;" /><br />图1</div><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>1) </strong></span><strong><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">射线和球体相交</span></strong><p>&nbsp;</p>  <p><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">如图</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">，表示射线</span><span style="font-size: 12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">AB</span><span style="font-size: 12.0pt;font-family:宋体;Times New Roman&quot;;">和球</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">O</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">相交于</span><span style="font-size: 12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B</span><span style="font-size: 12.0pt;font-family:宋体;Times New Roman&quot;;">点，反射后的射线为</span><span style="font-size:12.0pt;font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">BC</span><span style="font-size:12.0pt;font-family: 宋体;Times New Roman&quot;;">，</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">BD</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">为球心</span><span style="font-size: 12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">O</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">到交点的延长线，那么必定满足以下几个条件：</span></p>  <p><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">已知</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">点坐标</span><span style="font-size: 12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(x<sub>a</sub>, y<sub>a</sub>, z<sub>a</sub>)</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">，单位向量</span><span style="font-size: 12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">t<sub>ab</sub></span></p>  <p><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; B</span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">点坐标</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> </span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">为</span><span style="font-size:12.0pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> (x<sub>b</sub>, y<sub>b</sub>, z<sub>b</sub>) &nbsp;= &nbsp;(x<sub>a</sub>, y<sub>a</sub>, z<sub>a</sub>) + |AB| * t<sub>ab&nbsp;&nbsp; </sub>(1)</span></p>  <p><sub><span style="font-size:12.0pt;font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></sub><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">点在球</span><span style="font-size: 12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">O</span><span style="font-size: 12.0pt;font-family:宋体;Times New Roman&quot;;">上，所以</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">点坐标满足</span></p>  <p><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | (x<sub>b</sub>, y<sub>b</sub>, z<sub>b</sub>)&nbsp; - (x<sub>o</sub>, y<sub>o</sub>, z<sub>o</sub>) | = OB = Ro&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (2)</span></p>  <p><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">将</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(1)</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">代入</span><span style="font-size:12.0pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(2)</span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">，可计算出</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">|AB|</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">的长度（由于是射线和球体求交，这两个方程求出来的是直线和球体的交点，所以还需要计算方向判断交点的可行性，如果交点有两个，则取距离小的那个，如果只有一个交点，说明是相切），然后利用</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(1)</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">式计算出</span><span style="font-size: 12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B</span><span style="font-size: 12.0pt;font-family:宋体;Times New Roman&quot;;">点坐标。</span></p>  <p><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>2) </strong></span><strong><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">射线经过球体的反射射线</span></strong><strong></strong></p>  <p><strong><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></strong><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">假设</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">点在</span><span style="font-size:12.0pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A</span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">经过</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">点反射后的反射射线上，并且</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">AB = BC</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">，那么</span><span style="font-size: 12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">AC</span><span style="font-size: 12.0pt;font-family:宋体;Times New Roman&quot;;">必定和</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">OB</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">延长线相交，假设交于</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">D</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">点；</span></p>  <p><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">单位向量</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">cos(ABD) = I<sub>ba &#173;&#173;</sub>* I&#173;&#173;<sub>bd</sub></span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">；</span></p>  <p style="text-indent: 21pt;"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">BD = AB * cos(ABD)</span><span style="font-size: 12pt; font-family: 宋体;">；</span></p>  <p style="text-indent:21.0pt"><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">向量</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">AD = </span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">向量</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">AB + </span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">向量</span><span style="font-size:12.0pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">BD</span><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">；</span></p>  <p style="text-indent:21.0pt"><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">向量</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">AC = 2 * AD</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">；</span></p>  <p style="text-indent:21.0pt"><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">点</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C (x&#173;<sub>c</sub>, y<sub>c</sub>, z<sub>c</sub>) = </span><span style="font-size: 12.0pt;font-family:宋体;Times New Roman&quot;;">向量</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">AC + (x<sub>a</sub>, y<sub>a</sub>, z<sub>a</sub>)</span><span style="font-size: 12.0pt;font-family:宋体;Times New Roman&quot;;">；</span></p>  <p style="text-indent:21.0pt"><span style="font-size:12.0pt; font-family:宋体;Times New Roman&quot;;">向量</span><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">BC</span><span style="font-size:12.0pt;font-family:宋体;Times New Roman&quot;;">求出后返回</span><span style="font-size: 12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1) </span><span style="font-size: 12.0pt;font-family:宋体;Times New Roman&quot;;">继续判断和别的球的相交情况；<br /><br /></span><strong style="text-indent: 0px;">111&nbsp;</strong><strong>Very simple problem</strong></p><p class="MsoNormal">&nbsp; &nbsp; &nbsp; &nbsp;<span style="font-family: 宋体; color: #ff6600;">二分答案</span><span lang="EN-US" style="color: #ff6600;"> + </span><span style="font-family: 宋体; color: #ff6600;">大数模拟</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;"><br /><br /></span></p><p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">题意：给定</span><span lang="EN-US">X( X &lt;= 10<sup>100</sup>)</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">，求</span><span lang="EN-US">X</span><span style="font-family:
宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">开方后的下取整。</span></p><p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">题解：数组模拟大数。二分答案</span><span lang="EN-US">A</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">，找满足</span><span lang="EN-US"> A*A &lt;= X </span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">最大的</span><span lang="EN-US">A</span><span style="font-family:
宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">即为答案。</span></p><p class="MsoNormal"><span lang="EN-US">&nbsp;<br /><strong>112&nbsp;</strong></span><strong>a^b-b^a</strong></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">二分求幂</span><span lang="EN-US" style="color: #ff6600;"> + </span><span style="font-family: 宋体; color: #ff6600;">大数模拟<br /><br /></span></p><p>&nbsp; &nbsp; &nbsp; &nbsp;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：求</span> a<sup>b</sup> - b<sup>a</sup> ( 0 &lt; a, b &lt; 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> A<sup>B</sup><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> B == 0 &nbsp;则 A<sup>B</sup> = 1;&nbsp;<span style="font-family: 宋体;">否则&nbsp;</span>A<sup>B</sup> = (A<sup>2</sup>)<sup>(B/2)</sup> * ( (B mod 2) ? A : 1 ); 递归求解。</p>  <p>&nbsp;</p><p class="MsoNormal"><strong><span lang="EN-US">113&nbsp;</span>Nearly prime numbers</strong></p><p class="MsoNormal">&nbsp; &nbsp; &nbsp; &nbsp;<span style="font-family: 宋体; color: #ff6600;">素数筛选</span><span lang="EN-US" style="color: #ff6600;"> + </span><span style="font-family: 宋体; color: #ff6600;">素数判定</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;"><br /><br /></span></p><p>&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-31623 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的素数筛选出来，</span>31623<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为平方大于等于</span>10<sup>9</sup><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最小整数，因为一个数的开方内找不到一个(非1或它本身)因子的话它本身就是素数，所以素数只需要筛选到</span> 10<sup>9</sup>&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>Yes<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，否则为</span>No<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p><br /></p><p class="MsoNormal"><strong><span lang="EN-US">114&nbsp;</span>Telecasting station</strong></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">枚举</span><span lang="EN-US" style="font-family: 'Times New Roman', serif; color: #ff6600;"> + </span><span style="font-family: 宋体; color: #ff6600;">统计</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p><p class="MsoNormal"><br /></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;;">题意：在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">X</span><span style="font-family:宋体;Times New Roman&quot;;">轴上规定一些有权值</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">a&#173;i</span><span style="font-family:宋体;Times New Roman&quot;;">的点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> (x1,a1), (x1,a1), (x2,a2) .. (xn,an)</span><span style="font-family:宋体;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;;">坐标上找到一个点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">X</span><span style="font-family:宋体;Times New Roman&quot;;">使得</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> M = |X-x1|*a1 + ... |X-xn|*an </span><span style="font-family:宋体;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;;">题解：细心观察可以发现，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">M</span><span style="font-family:宋体;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;;">的一次函数，所以可以确定</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">X</span><span style="font-family:宋体;Times New Roman&quot;;">必定为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> x1...xn</span><span style="font-family:宋体;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;;">由于原式中存在绝对值，为了将绝对值化简，可以将</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">X</span><span style="font-family:宋体;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;;">为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;"> xj</span><span style="font-family:宋体;Times New Roman&quot;;">时可以简化为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> M = (X-x1)*a1 + ...(X-xj)*aj + (xj+1-X)*aj+1 + ... + (xn-X)*an</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = (X * presum[j] - preproduct[j]) + (postproduct[j+1] - X * postsum[j+1])</span></p>  <p style="text-align: center; ">&nbsp;<img src="http://www.cppblog.com/images/cppblog_com/menjitianya/sgu114_0.png" width="248" height="361" alt="" /><br />图2<br /></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:Calibri">这些辅助数组可以通过四次线性扫描得出，复杂度</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">O(n)</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
Calibri">。</span><span style="font-family: 宋体;">然后，</span><span style="font-family: 宋体;">先将</span><span style="font-family: 'Times New Roman', serif;">xi</span><span style="font-family: 宋体;">递增排序，枚举每个</span><span style="font-family: 'Times New Roman', serif;">xi</span><span style="font-family: 宋体;">，计算最小值更新</span><span style="font-family: 'Times New Roman', serif;">M</span><span style="font-family: 宋体;">，就可以在</span><span style="font-family: 'Times New Roman', serif;">O(n)</span><span style="font-family: 宋体;">的时间内求解了。总体算法复杂度为排序复杂度</span><span style="font-family: 'Times New Roman', serif;">O(n log n)</span><span style="font-family: 宋体;">。<br /><br /><br /></span><strong>115 Calendar<br /></strong></p><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">简单模拟</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;"><br /><br /></span></p><p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">题意：给定一个月份</span><span lang="EN-US">M</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">和天数</span><span lang="EN-US">N</span><span style="font-family:
宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">，求</span><span lang="EN-US">2001</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">的那一天是星期几。</span></p><p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">题解：可以预处理出每个月的天数，如果天数大于那个月对应的天数或者月数大于</span><span lang="EN-US">12</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">肯定是不可行的，否则将给定月数</span><span lang="EN-US">M</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">之前的</span><span lang="EN-US"> 1</span><span style="font-family:
宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">到</span><span lang="EN-US">M-1</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">个月的天数相加再加上</span><span lang="EN-US">N</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">得到</span><span lang="EN-US">Sum</span><span style="font-family:
宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">，</span><span lang="EN-US">Sum mod 7</span><span style="font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">就可以定位到星期几了。</span></p><p class="MsoNormal">



<strong><br /></strong></p><div><strong>116 Index of super-prime<br /></strong><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">素数筛选</span><span lang="EN-US" style="font-family: 'Times New Roman', serif; color: #ff6600;"> + </span><span style="font-family: 宋体; color: #ff6600;">记忆化搜索</span><span lang="EN-US" style="font-family: 'Times New Roman', serif; color: #ff6600;">(</span><span style="font-family: 宋体; color: #ff6600;">或</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> </span><span style="font-family: 宋体; color: #ff6600;">动态规划</span><span lang="EN-US" style="font-family: 'Times New Roman', serif; color: #ff6600;">)</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p>

<p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family:宋体;
mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:Calibri">题意：超级素数是素数下标也是素数的数，给定一个数</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
Calibri">，问这个数能不能被一些超级素数组合出来，如果可以，需要满足超级素数的个数最少，要求输出一个方案。</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p>

<p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;
mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:Calibri">题解：先将满足条件的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> </span><span style="font-family:
宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:Calibri">超级素数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> </span><span style="font-family:
宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:Calibri">筛选出来，</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">3 5 11 17</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
Calibri">等等，</span><span style="font-family: 宋体;">然后对于输入的</span><span lang="EN-US" style="font-family: 'Times New Roman', serif;">N</span><span style="font-family: 宋体;">进行一次记忆化搜索（</span><span lang="EN-US" style="font-family: 'Times New Roman', serif;">DP</span><span style="font-family: 宋体;">）</span></p>

<p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;
mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:Calibri">例如</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> N = 15<o:p></o:p></span></p>

<p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:Calibri">那么</span><span lang="EN-US" style="font-family:
&quot;Times New Roman&quot;,&quot;serif&quot;">N</span><span style="font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:Calibri">的最优值一定是来自</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> 15-3=12</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
Calibri">，</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">
15-5=10</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:Calibri">，</span><span lang="EN-US" style="font-family:
&quot;Times New Roman&quot;,&quot;serif&quot;"> 15-11=4 </span><span style="font-family:宋体;
mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:Calibri">这三个数，</span><span style="font-family: 宋体;">以此类推，递归出口是</span><span lang="EN-US" style="font-family: 'Times New Roman', serif;">N = 0</span><span style="font-family: 宋体;">，每次计算完</span><span lang="EN-US" style="font-family: 'Times New Roman', serif;">N</span><span style="font-family: 宋体;">就将它保存下来，下次就不用重复计算了。</span></p>

<p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:Calibri">所以状态转移方程为：</span><span lang="EN-US" style="font-family: 'Times New Roman', serif;">DP[i] =&nbsp;
min{ DP [ i - p ] ,&nbsp; p </span><span style="font-family: 宋体;">为超级素数</span><span style="font-family: 'Times New Roman', serif;"> <span lang="EN-US">} + 1</span></span></p>

<p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;
mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:Calibri">因为需要输出组合的序列，所以每次搜索，需要保存当前最优值的前驱结点，最后一次性输出即可。</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p>

<p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;</span></p><strong>117&nbsp;Counting</strong><br /><p class="MsoNormal">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">二分求余</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p>

<p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;
mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">题意：给定</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt; 10001)</span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">个数</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A<sub>i</sub></span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">，求其中</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A<sub>i</sub><sup>M
</sup></span><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">是</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K</span><span style="font-family:
宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">的倍数的数的个数。</span><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p>

<p class="MsoNormal"><span lang="EN-US" style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;
mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">题解：</span><span style="font-family: 宋体;">对于</span><span lang="EN-US" style="font-family: 'Times New Roman', serif;">a<sup>b</sup> mod c</span><span style="font-family: 宋体;">二分求解。</span><span style="font-family: 宋体;">当</span><span lang="EN-US" style="font-family: 'Times New Roman', serif;">
b == 0 则&nbsp;</span><span style="font-family: 'Times New Roman', serif;">a</span><sup style="font-family: 'Times New Roman', serif;">b</sup><span style="font-family: 'Times New Roman', serif;"> mod c = 1 mod c;&nbsp;</span><span style="font-family: 宋体;">否则&nbsp;</span><span style="font-family: 'Times New Roman', serif;">a</span><sup style="font-family: 'Times New Roman', serif;">b</sup><span style="font-family: 'Times New Roman', serif;"> mod c = (A</span><sup style="font-family: 'Times New Roman', serif;">2</sup><span style="font-family: 'Times New Roman', serif;">)</span><sup style="font-family: 'Times New Roman', serif;">(B/2)</sup><span style="font-family: 'Times New Roman', serif;">
* ( (B%2) ? A : 1 ) mod c;</span></p><strong><br />118&nbsp;Digital Root</strong><br /><p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">数学归纳法</span><span style="font-family:宋体;Times New Roman&quot;;"><br /><br /></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;;">题意：</span><span style="font-family: 宋体;">定义</span><span style="font-family: 'Times New Roman', serif;">f(n)</span>&nbsp;<span style="font-family: 宋体;">为</span>&nbsp;<span style="font-family: 'Times New Roman', serif;">n</span><span style="font-family: 宋体;">的所有数字的和</span><span style="font-family: 'Times New Roman', serif;">. </span><span style="font-family: 宋体;">如果</span>&nbsp;<span style="font-family: 'Times New Roman', serif;">f(n)</span>&nbsp;<span style="font-family: 宋体;">是</span><span style="font-family: 'Times New Roman', serif;">1</span><span style="font-family: 宋体;">位数字，那么它是</span><span style="font-family: 'Times New Roman', serif;">n</span><span style="font-family: 宋体;">的</span><span style="font-family: 'Times New Roman', serif;"> "digital root"</span><span style="font-family: 宋体;">，否则</span><span style="font-family: 'Times New Roman', serif;">n</span><span style="font-family: 宋体;">的</span><span style="font-family: 'Times New Roman', serif;">"digital root" </span><span style="font-family: 宋体;">为</span><span style="font-family: 'Times New Roman', serif;"> f(n) </span><span style="font-family: 宋体;">的</span><span style="font-family: 'Times New Roman', serif;">"digital root"</span><span style="font-family: 宋体;">。<br /></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体;">给定数组</span><span style="font-family: 'Times New Roman', serif;">A<sub>i</sub>&#173;</span><span style="font-family: 宋体;">，求</span>&nbsp;<span style="font-family: 'Times New Roman', serif;">A<sub>1</sub>*A<sub>2</sub>* &#8230; *A<sub>N </sub>&nbsp;+ &nbsp;A<sub>1</sub>*A<sub>2</sub>*&#8230;*A<sub>N-1</sub>&nbsp;+ &#8230; + &nbsp;A<sub>1</sub>*A<sub>2 &nbsp;</sub>+ A<sub>1</sub></span> <span style="font-family: 宋体;">的</span><span style="font-family: 'Times New Roman', serif;">"digital root"(N &lt;= 1000)</span><span style="font-family: 宋体;">。</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;;">题解：定义</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">d(n)</span><span style="font-family:宋体;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;;">的</span><span style="font-family: 'Times New Roman', serif;">"digital root"</span><span style="font-family: 宋体;">，</span><span style="font-family:宋体;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;;">从</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">N=1</span><span style="font-family:宋体;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;;">：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp; &nbsp; &nbsp;&nbsp;</span>&nbsp; &nbsp; &nbsp; &nbsp;<span style="font-family: 'Times New Roman', serif;">1) d(</span>&nbsp;<span style="font-family: 'Times New Roman', serif;">A<sub>1</sub>*A<sub>2</sub>* &#8230; *A<sub>N </sub></span><span style="font-family: 'Times New Roman', serif;">) = d( </span><span style="font-family: 'Times New Roman', serif;">A<sub>N</sub></span><span style="font-family: 'Times New Roman', serif;"> * d(</span>&nbsp;<span style="font-family: 'Times New Roman', serif;">A<sub>1</sub>*A<sub>2</sub>* &#8230; *A<sub>N-1 </sub></span><span style="font-family: 'Times New Roman', serif;">) )</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp; &nbsp; &nbsp; &nbsp;</span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 'Times New Roman', serif;">2) d(</span><span style="font-family: 'Times New Roman', serif;">A<sub>1</sub> + A<sub>2</sub> </span><span style="font-family: 'Times New Roman', serif;">) = d( d(</span><span style="font-family: 'Times New Roman', serif;">A<sub>1</sub></span><span style="font-family: 'Times New Roman', serif;">) +d(</span><span style="font-family: 'Times New Roman', serif;">A<sub>2</sub></span><span style="font-family: 'Times New Roman', serif;">) )</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;;">利用这两点，可以直接扫描</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">A</span><span style="font-family:宋体;Times New Roman&quot;;">数组就可以计算出给定表达式的</span><span style="font-family: 'Times New Roman', serif;">"digital root"</span><span style="font-family: 宋体;">了。</span></p>  <p>&nbsp;</p><strong>119 Magic Pairs</strong><br /><p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; color: #ff6600;">枚举 + 扩展欧几里得</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;;">题意：对于所有的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(X,Y)</span><span style="font-family:宋体;Times New Roman&quot;;">在满足</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> (A0 * X + B0 * Y) % N = 0 (1) </span><span style="font-family:宋体;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;;">使得</span><span style="font-family: 'Times New Roman', serif;">(A * X + B * Y) % N = 0 (2) </span><span style="font-family: 宋体;">也成立</span><span style="font-family: 'Times New Roman', serif;">, </span><span style="font-family: 宋体;">求这样的</span><span style="font-family: 'Times New Roman', serif;"> (A, B)</span><span style="font-family: 宋体;">。</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;;">题解：首先求出</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A0</span><span style="font-family:宋体;Times New Roman&quot;;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B0</span><span style="font-family:宋体;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;;">三者的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">GCD</span><span style="font-family:宋体;Times New Roman&quot;;">，最后算出来的答案需要乘上这个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">GCD</span><span style="font-family:宋体;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; (A0 * X + B0 * Y) = K * N&nbsp; (3)&nbsp; (K</span><span style="font-family:宋体;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; (A * X + B * Y) = K' * N&nbsp;&nbsp; (4) (K'</span><span style="font-family:宋体;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; X = (K*N - B0*Y) / A0</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;;">代入</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(4)</span><span style="font-family:宋体;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;;">可得</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A*(K*N - B0*Y) + B*A0*Y = K'* N * A0 (5)</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;;">化简得</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> (6)</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (B*A0 - A*B0) * Y = (K'*A0 - K*A) * N (6)</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;;">两边同时</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">mod N</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;;">得</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; (B*A0 - A*B0) * Y % N = 0 (7)</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;;">由于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Y</span><span style="font-family:宋体;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;;">即</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Y</span><span style="font-family:宋体;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;;">互素</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">), </span><span style="font-family:宋体;Times New Roman&quot;;">所以必须满足</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; (B*A0 - A*B0) % N = 0&nbsp; (8)</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;;">可以化简为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp; (B*A0 - A*B0) = K'' * N&nbsp; (9)&nbsp; (K''</span><span style="font-family:宋体;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; A0 * B + N * (-K'') = A*B0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (10)</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;;">枚举</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A</span><span style="font-family:宋体;Times New Roman&quot;;">的值，就可以把方程转化成了</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> ax + by = c</span><span style="font-family:宋体;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; a = A0, b = N, c = A*B0 </span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = B, y = -K'' </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;;">利用扩展欧几里得即可求得最小的满足条件的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">x(</span><span style="font-family:宋体;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;;">的值了。</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;;">最后的答案需要乘上</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> A0</span><span style="font-family:宋体;Times New Roman&quot;;">、</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">B0</span><span style="font-family:宋体;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;;">三者的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">GCD</span><span style="font-family:宋体;Times New Roman&quot;;">。</span></p>  <p>&nbsp;</p></div><img src ="http://www.cppblog.com/menjitianya/aggbug/207263.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-12 12:49 <a href="http://www.cppblog.com/menjitianya/archive/2014/06/12/207263.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SGU 100 - 109 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/06/10/207242.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Tue, 10 Jun 2014 05:43:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/06/10/207242.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207242.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/06/10/207242.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207242.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207242.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 100 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;测试题101 Domino &nbsp; &nbs...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2014/06/10/207242.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/207242.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-10 13:43 <a href="http://www.cppblog.com/menjitianya/archive/2014/06/10/207242.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>