﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-英雄哪里出来</title><link>http://www.cppblog.com/menjitianya/</link><description /><language>zh-cn</language><lastBuildDate>Wed, 22 Apr 2026 22:04:19 GMT</lastBuildDate><pubDate>Wed, 22 Apr 2026 22:04:19 GMT</pubDate><ttl>60</ttl><item><title>博客迁移</title><link>http://www.cppblog.com/menjitianya/archive/2017/12/26/215445.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Tue, 26 Dec 2017 05:24:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2017/12/26/215445.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/215445.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2017/12/26/215445.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/215445.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/215445.html</trackback:ping><description><![CDATA[<span style="font-size: 18pt"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/公众号.png" border="0" alt="" /><br />由于个人原因，该博客停止更新。</span><br /><span style="font-size: 18pt">后续相关文章更新传送门：<a href="http://blog.csdn.net/whereisherofrom">http://blog.csdn.net/whereisherofrom</a></span><img src ="http://www.cppblog.com/menjitianya/aggbug/215445.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2017-12-26 13:24 <a href="http://www.cppblog.com/menjitianya/archive/2017/12/26/215445.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>网络编程路漫漫（一）启程</title><link>http://www.cppblog.com/menjitianya/archive/2017/12/20/215435.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Wed, 20 Dec 2017 12:36:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2017/12/20/215435.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/215435.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2017/12/20/215435.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/215435.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/215435.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 一、套接字&nbsp; &nbsp; &nbsp; 1、什么是套接字（socket）&nbsp; &nbsp; &nbsp;&nbsp;2、创建套接字&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;1) 协议族（Protocol Family）&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; ...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2017/12/20/215435.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/215435.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2017-12-20 20:36 <a href="http://www.cppblog.com/menjitianya/archive/2017/12/20/215435.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>夜深人静写算法（七）[2016 贺岁版] - 线段树</title><link>http://www.cppblog.com/menjitianya/archive/2016/02/25/212891.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Thu, 25 Feb 2016 15:49:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2016/02/25/212891.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/212891.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2016/02/25/212891.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/212891.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/212891.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 目录 &nbsp;零、前言一、引例&nbsp; &nbsp; &nbsp;&nbsp;1、区间最值&nbsp; &nbsp; &nbsp;&nbsp;2、区间求和二、线段树的基本概念&nbsp; &nbsp; &nbsp;1、二叉搜索树&nbsp; &nbsp; &nbsp;2、数据域&nbsp; &nbsp; &nbsp;3、指针表示&nbsp; &nbsp; &nbsp;4、数组表示三、线段树...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2016/02/25/212891.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/212891.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2016-02-25 23:49 <a href="http://www.cppblog.com/menjitianya/archive/2016/02/25/212891.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>夜深人静写算法（六） - 最近公共祖先</title><link>http://www.cppblog.com/menjitianya/archive/2015/12/10/212447.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Wed, 09 Dec 2015 16:14:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2015/12/10/212447.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/212447.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2015/12/10/212447.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/212447.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/212447.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 目录 &nbsp;一、引例&nbsp; &nbsp; &nbsp;&nbsp;1、树-结点间最短距离二、LCA（最近公共祖先）&nbsp; &nbsp; &nbsp; 1、朴素算法&nbsp; &nbsp; &nbsp; 2、步进法&nbsp; &nbsp; &nbsp;&nbsp;3、记忆化步进法&nbsp; &nbsp; &nbsp;&nbsp;4、tarjan算法&nbsp; &nbsp; ...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2015/12/10/212447.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/212447.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2015-12-10 00:14 <a href="http://www.cppblog.com/menjitianya/archive/2015/12/10/212447.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>夜深人静写算法（五） - 初等数论</title><link>http://www.cppblog.com/menjitianya/archive/2015/12/02/212395.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Wed, 02 Dec 2015 14:05:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2015/12/02/212395.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/212395.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2015/12/02/212395.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/212395.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/212395.html</trackback:ping><description><![CDATA[<div><a href="https://mp.weixin.qq.com/s?__biz=Mzg2NjU1MzIxNg==&amp;mid=2247483938&amp;idx=1&amp;sn=7d8580aed32a0b536d2d45c998d11383&amp;chksm=ce485ecdf93fd7dba6da2ab91fd3f80e6563225b31f91972ae1c87bd301d347cf3eec995eeb3&amp;token=1626063786&amp;lang=zh_CN#rd">夜深人静写算法（三） - 初等数论<br /><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/公众号.png" border="0" alt="" /></a></div><img src ="http://www.cppblog.com/menjitianya/aggbug/212395.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2015-12-02 22:05 <a href="http://www.cppblog.com/menjitianya/archive/2015/12/02/212395.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>夜深人静写算法（二十三） - 最短路</title><link>http://www.cppblog.com/menjitianya/archive/2015/11/19/212292.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Thu, 19 Nov 2015 15:44:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2015/11/19/212292.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/212292.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2015/11/19/212292.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/212292.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/212292.html</trackback:ping><description><![CDATA[<p><span tabindex="-1" contenteditable="false" data-cke-widget-wrapper="1" data-cke-filter="off" class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" data-cke-display-name="图像" data-cke-widget-id="0" role="region" aria-label=" 图像 小部件"><img alt="" data-cke-saved-src="https://img-blog.csdnimg.cn/20210105190605774.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1doZXJlSXNIZXJvRnJvbQ==,size_16,color_FFFFFF,t_70" src="https://img-blog.csdnimg.cn/20210105190605774.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1doZXJlSXNIZXJvRnJvbQ==,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&amp;quot;hasCaption&amp;quot;:false,&amp;quot;src&amp;quot;:&amp;quot;https://img-blog.csdnimg.cn/20210105190605774.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1doZXJlSXNIZXJvRnJvbQ==,size_16,color_FFFFFF,t_70&amp;quot;,&amp;quot;alt&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;width&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;height&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;lock&amp;quot;:true,&amp;quot;align&amp;quot;:&amp;quot;none&amp;quot;,&amp;quot;classes&amp;quot;:[]}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" class="cke_widget_element" /><span class="cke_reset cke_widget_drag_handler_container" style="background: url(&quot;https://csdnimg.cn/release/blog_editor_html/release1.6.19/ckeditor/plugins/widget/images/handle.png&quot;) rgba(220, 220, 220, 0.5); top: -15px; left: 0px; display: block;"><img class="cke_reset cke_widget_drag_handler" data-cke-widget-drag-handler="1" src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==" width="15" title="点击并拖拽以移动" height="15" role="presentation" draggable="true" alt="" /></span><span class="cke_image_resizer" title="点击并拖拽以改变尺寸">&#8203;</span></span></p><p><strong><a data-cke-saved-href="https://mp.weixin.qq.com/s?__biz=Mzg2NjU1MzIxNg==&amp;mid=2247485426&amp;idx=1&amp;sn=114743202d4fa0feadac7d7eed7a0dd0&amp;chksm=ce485b1df93fd20b50e20214d95a417ec0c859c7eeb134fe92a58aaf993bec7477d76aee3200&amp;token=327533227&amp;lang=zh_CN#rd" href="https://mp.weixin.qq.com/s?__biz=Mzg2NjU1MzIxNg==&amp;mid=2247485426&amp;idx=1&amp;sn=114743202d4fa0feadac7d7eed7a0dd0&amp;chksm=ce485b1df93fd20b50e20214d95a417ec0c859c7eeb134fe92a58aaf993bec7477d76aee3200&amp;token=327533227&amp;lang=zh_CN#rd"></a></strong></p><p><strong>新地址：<a data-cke-saved-href="https://mp.weixin.qq.com/s?__biz=Mzg2NjU1MzIxNg==&amp;mid=2247485426&amp;idx=1&amp;sn=114743202d4fa0feadac7d7eed7a0dd0&amp;chksm=ce485b1df93fd20b50e20214d95a417ec0c859c7eeb134fe92a58aaf993bec7477d76aee3200&amp;token=327533227&amp;lang=zh_CN#rd" href="https://mp.weixin.qq.com/s?__biz=Mzg2NjU1MzIxNg==&amp;mid=2247485426&amp;idx=1&amp;sn=114743202d4fa0feadac7d7eed7a0dd0&amp;chksm=ce485b1df93fd20b50e20214d95a417ec0c859c7eeb134fe92a58aaf993bec7477d76aee3200&amp;token=327533227&amp;lang=zh_CN#rd">夜深人静写算法（二十三）- 最短路</a></strong></p><img src ="http://www.cppblog.com/menjitianya/aggbug/212292.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2015-11-19 23:44 <a href="http://www.cppblog.com/menjitianya/archive/2015/11/19/212292.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>夜深人静写算法（十三） - 树状数组</title><link>http://www.cppblog.com/menjitianya/archive/2015/11/02/212171.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Mon, 02 Nov 2015 14:53:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2015/11/02/212171.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/212171.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2015/11/02/212171.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/212171.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/212171.html</trackback:ping><description><![CDATA[<a href="https://mp.weixin.qq.com/s?__biz=Mzg2NjU1MzIxNg==&amp;mid=2247484830&amp;idx=1&amp;sn=c4a237dadda7616a7341fd49ea38be9e&amp;chksm=ce485971f93fd0672d0d379a016c6c52360d16ba60f19c5c1fa06471a4557aa6937ba6747fed&amp;scene=178&amp;cur_album_id=1658866261407137801#rd">夜深人静写算法（十三）- 树状数组<br /><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/公众号.png" border="0" alt="" /></a><img src ="http://www.cppblog.com/menjitianya/aggbug/212171.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2015-11-02 22:53 <a href="http://www.cppblog.com/menjitianya/archive/2015/11/02/212171.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>夜深人静写算法（二） - 动态规划</title><link>http://www.cppblog.com/menjitianya/archive/2015/10/23/212084.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Fri, 23 Oct 2015 15:24:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2015/10/23/212084.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/212084.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2015/10/23/212084.html#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/212084.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/212084.html</trackback:ping><description><![CDATA[<a href="https://mp.weixin.qq.com/s?__biz=Mzg2NjU1MzIxNg==&amp;mid=2247483846&amp;idx=1&amp;sn=7691121f35968b55b2474681d16ebb24&amp;chksm=ce485d29f93fd43fe8b8645c5b6a77e2fbab86be395e16d87ba6e1470c3afa065df7712e7e3e&amp;token=1626063786&amp;lang=zh_CN#rd" title="夜深人静写算法（二） - 动态规划">夜深人静写算法（二） - 动态规划<br /><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/公众号.png" border="0" alt="" /></a><img src ="http://www.cppblog.com/menjitianya/aggbug/212084.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2015-10-23 23:24 <a href="http://www.cppblog.com/menjitianya/archive/2015/10/23/212084.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>夜深人静写算法（一） - 搜索入门</title><link>http://www.cppblog.com/menjitianya/archive/2015/10/09/211980.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Fri, 09 Oct 2015 14:28:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2015/10/09/211980.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/211980.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2015/10/09/211980.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/211980.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/211980.html</trackback:ping><description><![CDATA[<div style="font-family: 微软雅黑;"><a href="https://mp.weixin.qq.com/s?__biz=Mzg2NjU1MzIxNg==&amp;mid=2247483845&amp;idx=1&amp;sn=5a3b9b5bc3247a66568105ee6a028189&amp;chksm=ce485d2af93fd43c9b85aa2a5d91542b4b8f081ad3074feecf9a4945b886a719e2c6821fec36&amp;token=1626063786&amp;lang=zh_CN#rd" title="夜深人静写算法（一）- 搜索入门">夜深人静写算法（一）- 搜索入门</a><br /><a href="https://mp.weixin.qq.com/s?__biz=Mzg2NjU1MzIxNg==&amp;mid=2247483845&amp;idx=1&amp;sn=5a3b9b5bc3247a66568105ee6a028189&amp;chksm=ce485d2af93fd43c9b85aa2a5d91542b4b8f081ad3074feecf9a4945b886a719e2c6821fec36&amp;token=1626063786&amp;lang=zh_CN#rd" title="夜深人静写算法（一）- 搜索入门"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/公众号.png" border="0" alt="" /><br /></a></div><img src ="http://www.cppblog.com/menjitianya/aggbug/211980.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2015-10-09 22:28 <a href="http://www.cppblog.com/menjitianya/archive/2015/10/09/211980.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>二维线段树</title><link>http://www.cppblog.com/menjitianya/archive/2015/10/06/211956.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Tue, 06 Oct 2015 10:56:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2015/10/06/211956.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/211956.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2015/10/06/211956.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/211956.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/211956.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp; &nbsp; &nbsp; 二维线段树最主要用于平面统计问题。类似一维线段树，最经典的就是求区间最值（或区间和），推广到二维，求得就是矩形区域最值（或矩形区域和），对于矩形区域和，二维树状数组更加高效，而矩形区域最值，更加高效的方法是二维RMQ，但是二维RMQ不支持动态更新，所以二维线段树还是有用武之地的。&nbsp; &nbsp; &nbsp; 如果对一维线段树已经驾轻就熟，那么直...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2015/10/06/211956.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/211956.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2015-10-06 18:56 <a href="http://www.cppblog.com/menjitianya/archive/2015/10/06/211956.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><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>Southeastern Europe 2004 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/08/06/207926.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Wed, 06 Aug 2014 13:23:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/08/06/207926.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207926.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/08/06/207926.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207926.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207926.html</trackback:ping><description><![CDATA[<p><div style="text-align: center;"><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/souer2004.png" width="907" height="206" alt="" /></span></strong></div><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A. Period</span></strong></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">PKU 1961 <a href="http://poj.org/problem?id=1961">http://poj.org/problem?id=1961</a></span></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一个长度为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 10<sup>6</sup>)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的字符串</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，求它的所有前缀中能够表示成</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">A<sup>K</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的前缀，并且要求求出每个前缀对应的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">KMP</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">利用</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">KMP</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">求出该串的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Next</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数组，然后枚举每个前缀，根据</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">Next</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数组的定义，对于某个前缀</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S[1...i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，有</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S[1...Next[i]] = S[i-Next[i]+1...i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，假设前缀</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S[1...i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">能够表示长</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A<sup>K</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的形式，则</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A = S[Next[i]+1...i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，所以必须满足</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">能够被</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i - Next[i] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">整除，满足条件后</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K = i/( i - Next[i])</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p><strong>&nbsp;</strong></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B. Corporative Network</span></strong></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">PKU 1962 <a href="http://poj.org/problem?id=1962">http://poj.org/problem?id=1962</a></span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 20000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">M(M &lt;= 200000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">次操作，每次操作有两种类型：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I a b&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">将</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">a</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的父结点设为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">b</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且合并距离为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> |a-b| mod 1000</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E a&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">询问</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">a</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">到根结点的合并距离。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：并查集</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">利用路径压缩的思想，用</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">dist[p]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的父结点的合并距离，每次查询的时候累加</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">到根结点的合并距离，并且将</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">到</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">所在树的根结点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的路径上的所有点的父结点都设为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">R</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，然后更新各自的合并距离。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">合并操作</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">O(1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，查询操作总复杂度</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">O(N)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C. Cave Exploration</span></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">PKU 1963 <a href="http://poj.org/problem?id=1963">http://poj.org/problem?id=1963</a></span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给出</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 1000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">条水平或者垂直的走廊，再给定走廊上任意一个坐标点作为起点以及方向，按照以下策略走：能够左转就左转，不能则笔直走，不能笔直走就右转，都不能就掉头。这样走最后绕一圈又会回到起点，问哪些走廊是没有经过的，只要有一个点走过就算经过。<br /></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="text-indent: 0px; font-family: 宋体;">题解：模拟</span><span style="text-indent: 0px; font-family: 'Times New Roman', serif;"> + </span><span style="text-indent: 0px; font-family: 宋体;">哈希。</span></p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">将水平线段和竖直线段分开存，分两种情况讨论：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、水平线段</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于任意一根水平线段，枚举所有的竖直线段，计算出交点和水平线段的端点，保存下来并且按</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">x</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">坐标递增排序，去掉重复点，利用双向链表将两个相邻点连接起来，由于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">x</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">y</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">坐标范围为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">-32767~32767</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，而交点数不会超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N<sup>2</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，所以可以采用哈希将二维的点映射到一位数组中。每个点记录水平走廊的编号。</span></p>  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、竖直线段</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">同上操作，不同的是每个点记录竖直走廊的编号。</span></p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">经过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">两步操作后，走廊上的关键点已经被离散化了，并且所有点都通过四向链表串接起来，然后只需要从起点开始模拟行走即可，走到一个关键点，将关键点所在的两个走廊编号标记掉，最后统计没有标记的走廊编号就是答案了。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">D. City Game</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1964 <a href="http://poj.org/problem?id=1964">http://poj.org/problem?id=1964</a></span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">M*N(M &lt;= 1000</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N &lt;= 1000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">01</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">矩阵，求它的一个子矩阵，满足矩阵元素全为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且面积最大。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：枚举行，对于第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">行，以第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">行为起点，扫描每一列</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">j</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，找到第一个不是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的数所在的位置</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">P[j]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，令</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K[j] = P[j] - i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，于是问题转化成了一个一维的问题。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L[i] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> K [ L[i]+1 ... i] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中的元素都大于等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，但是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">小于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R[i] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> K [i ... R[i]-1] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中的元素都大于等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K[i],</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">但是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">小于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">K[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Max{&nbsp; (R[i] - L[i] - 1) * K[i],&nbsp; 1 &lt;= i &lt;= N }</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">就是以当前枚举行为起点的最大矩阵，枚举</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">M</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">次取最大值就是全局的最大子矩阵了。</span></p>  <p style="text-indent:21.0pt">&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">E. Cube Root</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1965 <a href="http://poj.org/problem?id=1965">http://poj.org/problem?id=1965</a></span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一个不超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">150</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数字的正整数，求它的三次方根，精确到小数点后</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">10</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">位。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：大数模拟</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">将输入的数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">X</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">用字符串存储，乘上</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">10<sup>30</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，利用二分求出最大的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Y</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，使得</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Y<sup>3 </sup>&lt;= X</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。然后在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Y</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的后十位前插入一个小数点，输出即可。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">F. Cable TV Network</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1966 <a href="http://poj.org/problem?id=1966">http://poj.org/problem?id=1966</a></span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：求图的点连通度。给定一个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 50)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点的图，求去掉至少多少个点能够将它变成一个非连通图。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：搜索</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> + </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">剪枝</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> (</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">或者</span> <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">最大流</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">枚举每个点去掉或不去掉，总共</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2<sup>50</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">种状态，每次去掉点后判断当前图的连通性，一旦破坏了连通，去掉的点数即为答案；如果发现某个点去掉后，剩下点组成的图变成了一个完全图，那么不用继续搜索了，因为当前状态下不可能将剩下的图变成非连通图了；如果去掉的点数超过目前的最优解也直接剪枝。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">好吧</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">...</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一定是数据弱了-_-||，正解是最大流拆点。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">G. Alibaba</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1967 <a href="http://poj.org/problem?id=1967">http://poj.org/problem?id=1967</a></span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 10<sup>4</sup>)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个整数对</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(P<sub>i</sub>, D<sub>i</sub>)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">P<sub>i</sub></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位置有一个宝物，并且需要在</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">D<sub>i</sub> </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时间之前取走</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">给出顺序为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">P<sub>i</sub></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">递增的顺序</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。起始可以任意选择一个位置，往左或者往右取宝物，问是否能够保证每个物品都在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">D<sub>i</sub></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时间之前取走</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时间和距离关系为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1:1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果可以，给出取完所有宝物的最少时间。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：搜索</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> + </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">剪枝</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">首先可以想到的是，起始位置一定是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个宝物所在位置中的其中一个，所以首先可以枚举每个宝物的起始点，比如当前位置为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么在第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">秒内，访问过的区间为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">[pos, pos]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，可以选择往左走，也可以选择往右走，那么是不是只要选择某个方向走完，然后再反方向走到底如果能够满足所有点都在截止时间内完成一定是对的呢？答案是否定的，来看一组数据，如图</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，起始点只能选择</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">3</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">号位置，并且只能选择往右走，走到</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">4</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">后再折回走到</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，然后再折回走到</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">5</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，以此类推，并且只有这一种路径才能满足所有宝物都在截至时间内取完。</span></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/se2004_g1.png" width="373" height="107" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-size:9.0pt;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span><span style="font-size:9.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1</span></p>  <p align="left"><span style="font-size:9.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">按照这个思路，进行状态的划分，假设当前已经访问的区间为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">[L, R]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且现在的位置处于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位置</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">要么等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，要么等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，所以可以用三维来表示状态</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[s][l][r](l</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">r</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示访问过的区间的左右端点，如果当前位置在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">l</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">则</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">s = 0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果当前位置在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">r</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">s=1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，总共状态数目</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N<sup>2</sup></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，状态转移的时候由大状态推小状态，即</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[s][l][r]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一定是由</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[0][l-1][r]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[0][l][r+1]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[1][l-1][r]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">DP[1][l][r+1]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这四个状态得出。</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">考虑到</span><span style=" font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">比较大，所以把所有状态存储到数组中再利用动态规划进行递推，如果数据量不多的话，可以卡过，但是状态存储需要用滚动数组，否则内存吃不消，也可以采用搜索</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> + </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">剪枝，思路是沿用了动态规划的思想，假设当前已经访问的区间为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">[L, R]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，现在的位置处于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位置</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">要么等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，要么等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且已经使用了</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时间，无论当前的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">pos</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是在左区间端点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">上还是在右区间端点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">上，他都可以选择走到</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L-1(L &gt; 1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，或者</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R+1(R &lt; N)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，于是就可以递归求解了，递归出口为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L=1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">R=N</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时候。</span></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/se2004_g2.png" width="362" height="106" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-size:9.0pt;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span><span style="font-size:9.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如图，已经访问的宝物为红色标记的点，灰色标记的为未曾访问过的，并且现在的位置在已经访问区间的左端点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">L</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">上，已经使用了</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时间，我们需要判断这个状态是否合法，则需要满足以下的几个不等式。</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、保证右边未访问的都能在截止时间内访问到：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T + (P[R] - P[L]) +&nbsp; (P[R+1] - P[R])&nbsp; &lt; D[R+1]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T + (P[R] - P[L]) +&nbsp; (P[R+2] - P[R])&nbsp; &lt; D[R+2]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T + (P[R] - P[L]) +&nbsp; (P[N] - P[R])&nbsp; &lt; D[N]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">将这些等式化简，可得：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T - P[L]&nbsp; &lt;&nbsp; D[R+1] - P[R+1]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T - P[L]&nbsp; &lt;&nbsp; D[R+2] - P[R+2]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T - P[L]&nbsp; &lt;&nbsp; D[N] - P[N]</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">再进行进一步化简，得：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T - P[L]&nbsp; &lt;&nbsp; Min{ D[k] - P[k],&nbsp; R &lt; k &lt;= N }</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、保证左边未访问的都能在截止时间内访问到：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">同理，可以得出：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T + P[R]&nbsp; &lt;&nbsp; Min{ D[k] + P[k],&nbsp; 1 &lt;= k &lt; R }</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">那么，令</span><span style=" font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> POSTM[i] = Min{ D[k] - P[k],&nbsp; i &lt; k &lt;= N }</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;PREM[i] = Min{ D[k] + P[k],&nbsp; 1 &lt;= k &lt; i }</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这两个数组可以分别通过一次逆序和顺序的线性扫描求出来，用于搜索的时候判断可行性。例如，当</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T - P[L] &gt;= POSTM[R] </span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">表示在右边未访问的宝物中有至少一个宝物不能在截止时间前被访问到，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T + P[R] &gt;= PREM [R]</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">表示在左边未访问的宝物中有至少一个宝物不能在截止时间前被访问到，直接剪枝。</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">还需要一个剪枝，就是在当前时间</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">加上<strong><span style="color:red">当前状态下预计访问完所有宝物的最小时间</span></strong>已经比之前求出的最小时间大，直接剪枝。</span></p>  <p align="left">&nbsp;</p>  <p align="left"><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">H . Booklets</span></strong></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1968 <a href="http://poj.org/problem?id=1968">http://poj.org/problem?id=1968</a></span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：</span><span style=" font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 3000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">本小册子需要分配给</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个学校，每个学校得到的是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N/S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的上整本册子或者</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N/S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的下整本册子，每本册子有一个页数，并且规定分配册子的时候按照页数递增来分配，先把上整本册子分完再分下整的，对于每个学校的分书规则，按照输入的顺序进行分配。求问第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个学校分到的第一本册子的页数。</span></p>  <p align="left">&nbsp;</p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：需要求出几个量：</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">上整册子的数目</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">UIP = (N+S-1) / S;</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">下整册子的数目</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">LIP = N/S;</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分到上整册子数目的学校个数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">UIPC = N % S;</span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分到下整册子数目的学校个数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">LIPC = N - N % S;</span></p>  <p align="left">&nbsp;</p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">首先对所有的册子按页数递增来排序</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果页数相同按照下标递增排序</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，然后减去前</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T-1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个学校的册子总数，容易得出第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个学校分到的册子数目</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，从接下来的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个册子中找到之前下标最小的册子，它对应的页数就是答案。</span></p>  <p align="left">&nbsp;</p>  <p align="left"><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">I. Count on Canton</span></strong></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1969 <a href="http://poj.org/problem?id=1969">http://poj.org/problem?id=1969</a></span></p>  <p align="left"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定下图所示的无限分数序列，并且按照蛇形方式编号，即第一个为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1/1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，第二个为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">1/2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，第三个为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">2/1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，第四个为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">3/1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，以此类推，问第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个分数是什么。</span></p>  <pre><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1/1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1/2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1/3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1/4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  1/5 ...</span></pre><pre><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2/1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2/2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2/3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2/4</span></pre><pre><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3/1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3/2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3/3</span></pre><pre><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4/1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4/2</span></pre><pre><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5/1</span></pre><pre><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp; </span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">题解：数学题。</span></pre><pre><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">&nbsp;&nbsp;&nbsp; </span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">首先二分求出在第几条斜线上，即</span><span style="font-size: 10.5pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">(K-1)K/2 &lt; N</span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">的最大的</span><span style="font-size:10.5pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">K</span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">，然后求根据</span><span style="font-size:10.5pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">K</span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">的奇偶性求出蛇形在第</span><span style="font-size:10.5pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">K</span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">条斜线的行走方向，第</span><span style="font-size:10.5pt; font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">N - (K-1)K/2 </span><span style="font-size:10.5pt;Times New Roman&quot;;Times New Roman&quot;">个数就是答案。</span></pre><pre>&nbsp;</pre><img src ="http://www.cppblog.com/menjitianya/aggbug/207926.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-08-06 21:23 <a href="http://www.cppblog.com/menjitianya/archive/2014/08/06/207926.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>South Central USA 2002 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/07/31/207869.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Thu, 31 Jul 2014 03:31:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/07/31/207869.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207869.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/07/31/207869.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207869.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207869.html</trackback:ping><description><![CDATA[<p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><div align="center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/soutcenusa2002.png" width="950" height="160" alt="" /></div><br />A . The Hardest Problem Ever</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1298 <a href="http://poj.org/problem?id=1298">http://poj.org/problem?id=1298</a></span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;">题意：解码题，按照如下对应关系解码：</span></p>  <p><span style="font-size: 11.5pt; font-family: 'Times New Roman', serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 11.5pt; font-family: 宋体;">密文</span><span style="font-size: 11.5pt; font-family: 'Times New Roman', serif;"> A B C D E F G H I J K L M N O P Q R S T U V W X Y Z&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 11.5pt; font-family: 宋体;">原文</span><span style="font-size: 11.5pt; font-family: 'Times New Roman', serif;"> V W X Y Z A B C D E F G H I J K L M N O P Q R S T U&nbsp;</span><a href="http://poj.org/problem?id=1299"></a></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：简单题。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">B. Polar Explorer</span></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">PKU 1299 </span><a href="http://poj.org/problem?id=1299"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">http://poj.org/problem?id=1299</span></a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定圆的半径</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;;">X</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，求圆周上两个点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">A</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">B</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的距离，其中圆心角</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">AOB</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的角度为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">Z(0 &lt;= Z &lt;= 360)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：核心是</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;;">Z</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">如果大于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">180</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，则</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">Z = 360 - Z</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，即走劣弧。而且题目求的是来回一次，所以计算的时候弧长要乘</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">。</span></p>  <p><strong>&nbsp;</strong></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">C. Door Man</span></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">PKU 1300 </span><a href="http://poj.org/problem?id=1300"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">http://poj.org/problem?id=1300</span></a><strong></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定一些边和起点</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;;">s</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，求能否找到一条从</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">s</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">到</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的通路，并且要求访问所有的边。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：欧拉回路可行解判定。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">首先利用</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">flood fill</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">从</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">s</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">遍历全图，如果</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">点没有被访问到则必定不存在；然后判断度数不为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的点是否有未被访问到的，如果有，说明图不连通，也必定不存在解；最后统计度数为奇数的点的个数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">P</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，以及具体的点：</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">1)&nbsp; P = 0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，则必定有解；</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">2)&nbsp; P &gt; 2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，则无解；</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">3)&nbsp; P =2, </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">那么有解的前提是两个奇度数点中一个是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">s</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，另一个是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">；否则无解。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">D . The Umbrella Problem 2054</span></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">PKU 1301 </span><a href="http://poj.org/problem?id=1301"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">http://poj.org/problem?id=1301</span></a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定一个</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;;">10X10</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的地图，玩家从第一行的某一个点出发，每一步行编号</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">+1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，列编号增量有三种选择</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">(-1, 0, 1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，图中标记为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">S(laser gun)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的点不能走，并且</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的点会发出镭射光，第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">秒朝上发射，第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">秒朝右，第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">秒朝下，第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">3</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">秒朝左，循环往复，发射长度一直到地图边缘。问能否走到最后一行标记为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">G(grass)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的地方。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：广搜。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;">hash[4][R][C]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">表示状态，每走一步，利用步数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;"> mod 4</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">计算出镭射光的方向，然后将所有的镭射光可达区域全部标记出来，未标记的点为可达点，枚举三个方向进行搜索。<br /><br /></span></p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">E. Blue Gene, Jr.</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1302 </span><a href="http://poj.org/problem?id=1302"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">http://poj.org/problem?id=1302</span></a></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：一个长度为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 20)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的病毒基因串</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A[1...N]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">进行变异，变异过程从左往右，分情况讨论：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个字符是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> A-Z</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则它将变异成数字</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">n mod 10</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">n</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A[i+1...N]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中变异基因的数目；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个字符是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> 1-9</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则它变异成</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">A[i] - 1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且如果第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p (p = i + A[i])</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个基因存在的话，从第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">p</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个基因开始变异；否则从第</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i+1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个基因开始变异；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：题意理解后就是个水题了，递归求解。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">F . Byte Me!</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1303 </span><a href="http://poj.org/problem?id=1303"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">http://poj.org/problem?id=1303</span></a></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：二进制二十一点</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">二进制黑杰克</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是由两种牌组成的游戏，一种称为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">bytes(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">8</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">比特的序列表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">0-255</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">之间的数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，一种称为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">nibbles((</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一个</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">4</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">比特的序列表示</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">0-15</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">之间的数</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，游戏玩法如下：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">游戏的目标是获得尽量接近</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分，并且不能超过它；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每个玩家有两张牌，一张面朝上，一张面朝下</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">庄家不知道是什么牌</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每个玩家有四次叫牌机会，可以叫</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">bytes</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，也可以叫</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">nibbles</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，但是如果分数超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">则不能再叫牌；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">所有的叫牌都是面朝上的；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果玩家分数超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，立即判为输；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">庄家最后一个叫牌；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">平局的情况庄家胜</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果所有人都超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分，庄家还是赢的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:red">庄家的规则</span></strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如下：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">当看到自己和其他人面朝上的牌，判断已经必胜时不要再叫牌了；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果总分小于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">382</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">需要叫一次</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">byte</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">牌；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果总分小于等于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">500</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"> </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">需要叫一次</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">nibble</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">牌；</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">还有两个隐藏规则：</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">你是庄家；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每个非庄家的玩家面朝下的牌是</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">11111111</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（但是庄家不知道），面朝上的牌给定；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">非庄家不会叫牌</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">因为他们比较笨</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">给定庄家的牌和其他玩家面朝上的牌，以及牌堆中的</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">bytes</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">牌和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">nibble</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">牌，求庄家的四次叫牌能否获胜；</span></p>  <p>&nbsp;</p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：题目说了一大堆，最后非庄家的玩家都不会叫牌，</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">o(</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#9583;&#9633;&#9584;</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">)o...</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">所以只要根据庄家的规则进行叫牌，然后判断是否能够胜出即可；</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">因为其他人都不叫牌，每个人都有两张牌，所以其他人的总分不可能超过</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分，所以，如果庄家叫牌超过</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分直接被判为负。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每次叫牌前先判断所有玩家的朝上的卡片分数加上</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">255</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和庄家当前得分进行比较，如果有一个玩家分数大于庄家分数，则庄家按照</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">382</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">和</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">500</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这两个区间进行叫牌。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">四次叫牌结束，如果所有玩家分数都小于等于庄家分数，则判断庄家分数是否大于</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">510</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果是，输出</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Bust!</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，否则输出</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">Win!</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；如果小于某个玩家的分数，那么输出</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">Lose!</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p>&nbsp;</p>  <p><strong><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">G . World's Worst Bus Schedule</span></strong></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 1304 </span><a href="http://poj.org/problem?id=1304"><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">http://poj.org/problem?id=1304</span></a></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：公交车站有</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">N(N &lt;= 20)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">辆车，每辆车的发车时间间隔为</span><span style="font-family: &quot;Times New Roman&quot;,&quot;serif&quot;">a1 a2 a3 a4... a1 a2 a3 a4... a1 a2 a3 a4...</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，循环发车，问某人在</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时刻赶到公交车站，最少需要等待多少时间能够乘上公交车。</span></p>  <p><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：对于每辆公交车，设它的所有时间间隔之和为</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，令</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T' = T mod S</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，然后枚举所有的发车间隔，前</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">i</span><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个发车间隔</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">a[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">之和减去</span><span style="font-family:&quot;Times New Roman&quot;,&quot;serif&quot;">T'</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中的最小正值就是等这辆公交车需要的时间，取所有公交车的最小时间就是所求。</span></p>  <p>&nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207869.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-07-31 11:31 <a href="http://www.cppblog.com/menjitianya/archive/2014/07/31/207869.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ulm local 1998 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/07/19/207722.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sat, 19 Jul 2014 14:42:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/07/19/207722.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207722.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/07/19/207722.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207722.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207722.html</trackback:ping><description><![CDATA[<p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="text-align: center; margin-bottom: 0pt; margin-top: 0pt;">&nbsp;<img src="http://www.cppblog.com/images/cppblog_com/menjitianya/ulm1998.png" width="860" height="183" alt="" /></p><p style="margin-bottom:0pt; margin-top:0pt; "><br /></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">A</span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">.&nbsp;</span><span style="font-weight: bold; font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">Artificial&nbsp;Intelligence?</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">2256</span>&nbsp;<a href="http://poj.org/problem?id=2256"><span style="color: #0000ff; font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2256</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：功率的计算公式为P&nbsp;=&nbsp;UI</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">，给定一句话，这句话中一定会包含三个变量中的两个，求另外一个，并且单位会有三种前缀m(毫)，k(千)，M(兆)。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：字符串扫描。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">gets读入字符串，进行一次遍历，查找是否包含子串</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8217;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">P=</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8217;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">,&nbsp;</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8216;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">U=</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8217;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">,&nbsp;</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8216;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">I=</span><span style="font-size: 10.5pt; font-family: 'Times New Roman'; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">&#8217;</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">,&nbsp;格式化它后面的数字，需要用double来存，然后检查单位前缀，m需要将原值除上10</span><span style="font-size: 10.5pt; font-family: 宋体; vertical-align: super; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">3</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">，k需要将原值乘上10</span><span style="font-size: 10.5pt; font-family: 宋体; vertical-align: super; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">3</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">，M需要将原值常上10</span><span style="font-size: 10.5pt; font-family: 宋体; vertical-align: super; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">6</span><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">。然后分三种情况计算未知的那个值即可。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">B.&nbsp;Balancing&nbsp;Bank&nbsp;Accounts</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2257&nbsp;</span><a href="http://poj.org/problem?id=2257"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2257</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：给定N(N&nbsp;&lt;=&nbsp;20)个人，以及M(M&nbsp;&lt;=&nbsp;1000)条关系，每条关系的描述为nameA&nbsp;nameB&nbsp;C，表示nameA这个人给了nameB这个人C块钱，为了让所有人都不亏，需要再给出至多N-1条关系，使得所有人都收支平衡。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：贪心。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">首先将所有人分成两堆，from_set表示收入大于支出的人的集合，to_set表示支出大于收入的人的集合，并且记录他们各自的&nbsp;|收入-支出|，然后对于所有的from_set的人按&nbsp;|收入-支出|&nbsp;进行递增排序，枚举每个from_set中的人f，去to_set中找到一个人t，满足f剩余的钱小于等于t亏损的钱，并且t是to_set中亏损最少的人，如果找不到这样的人，那么找到亏损最多的那个人，将f的钱给t，循环往复，直到f的钱给完为止。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">当from_set中的所有人将钱全部给了to_set中的人后，to_set中也就没有人亏损了，所有人达到收支平衡。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">C.&nbsp;The&nbsp;Settlers&nbsp;of&nbsp;Catan</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2258&nbsp;</span><a href="http://poj.org/problem?id=2258"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2258</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：给定一个N(N&nbsp;&lt;=&nbsp;25)个点，M(M&nbsp;&lt;=&nbsp;25)条边的图，求图的最长路，点允许重复，边不允许重复。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：前向星&nbsp;+&nbsp;dfs。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">利用前向星存双向边，以每个点为起点深搜遍历整个图，访问过的边哈希，搜索过程更新最长路即可。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">D.&nbsp;Team&nbsp;Queue</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2259&nbsp;</span><a href="http://poj.org/problem?id=2259"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2259</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：Team&nbsp;Queue是这样一种queue，每个元素都有一个Team。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">对于queue的push操作，被push的元素从queue中从头到尾扫描，如果扫到一个元素和它属于同一个Team，那么直接将它插入到这个元素后面；如果没有扫到，直接插到对列尾。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">对于queue的pop操作，等同于普通queue的pop操作。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">队伍数N小于等于1000。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：模拟，开1000个队列。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">对于插入操作，每个Team的元素插入到对应的队列中，并且记录当前Team的最早插入时间。O(1)</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">对于弹出操作，枚举所有Team的队列首元素，从中找时间最早的，然后对那个队列执行弹出操作。O(N)。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">E.&nbsp;Error&nbsp;Correction</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2260&nbsp;</span><a href="http://poj.org/problem?id=2260"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2260</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：给定N*N(N&nbsp;&lt;&nbsp;100)的01矩阵，问是否所有&nbsp;行和&nbsp;和&nbsp;列和&nbsp;都是偶数，如果是输出OK，如果不是，是否能够通过改变一个值保证&nbsp;都是偶数，&nbsp;都不行输出Corrupt。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：扫描。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">扫描所有&nbsp;行和&nbsp;和&nbsp;列和，如果正好有其中一行R是奇数，并且其中一列C是奇数，那么改变(R,&nbsp;C)的值就能保证全是偶数，否则要么是OK，要么是Corrupt。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">F.&nbsp;France&nbsp;'98</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2261&nbsp;</span><a href="http://poj.org/problem?id=2261"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2261</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：给定16个国家进行淘汰赛，以及一个16*16的矩阵A，其中A[i][j]表示i号国家打败j号国家的概率，问每个国家取得冠军的概率。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：动态规划。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">dp[0][i]&nbsp;&nbsp;&nbsp;表示&nbsp;1/2决赛&nbsp;第i个人获胜的概率</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">dp[1][i]&nbsp;&nbsp;&nbsp;表示&nbsp;1/4决赛&nbsp;第i个人获胜的概率</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">dp[2][i]&nbsp;&nbsp;&nbsp;表示&nbsp;1/8决赛&nbsp;第i个人获胜的概率</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">dp[3][i]&nbsp;&nbsp;&nbsp;表示&nbsp;&nbsp;总决赛&nbsp;第i个人获胜的概率&nbsp;</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">1)&nbsp;那么显然dp[0][i]&nbsp;=&nbsp;A[i][i^1]</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">2)&nbsp;dp[1][i]的概率取决于1/2决赛时第i个人获胜的概率乘上他打败1/4决赛中同组的那两个人的概率；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">3)&nbsp;dp[2][i]的概率取决于1/4决赛时第i个人获胜的概率乘上他打败1/8决赛中同组的那四个人的概率；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">4)&nbsp;dp[3][i]的概率取决于1/8决赛时第i个人获胜的概率乘上他打败&nbsp;总决赛中同组的那八个人的概率；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">直接递推求解，dp[3][i]就是所求。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">G.&nbsp;Goldbach's&nbsp;Conjecture</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2262&nbsp;</span><a href="http://poj.org/problem?id=2262"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2262</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：将一个数分解成两个奇素数的和。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：素数筛选，枚举。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">H.&nbsp;Heavy&nbsp;Cargo</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">PKU&nbsp;2263&nbsp;</span><a href="http://poj.org/problem?id=2263"><span style="color: #0000ff; font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">http://poj.org/problem?id=2263</span></a></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题意：给定一个有向图，边权W(u,&nbsp;v)表示从u到v的最大载重为W(u,&nbsp;v)，在给定s和t，求s到t&nbsp;的最大可能载重。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">题解：二分答案&nbsp;+&nbsp;判断连通性。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial;">二分枚举答案T，然后从起点到终点进行连通性判定，如果边权小于T的边不可达，二分的最大值就是答案。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207722.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-07-19 22:42 <a href="http://www.cppblog.com/menjitianya/archive/2014/07/19/207722.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AC自动机</title><link>http://www.cppblog.com/menjitianya/archive/2014/07/10/207604.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Thu, 10 Jul 2014 06:26:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/07/10/207604.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207604.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/07/10/207604.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207604.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207604.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: AC自动机  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 算法目的：  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AC自动机主要用于解决多模式串的匹配问题，是字典树(trie树)的变种，一种伪树形结构(主体是树形的，但是由于加入了失败指针，使得它变成了一个有向图)；trie图(我的理解^_^)是对AC自动机的一种改造，使得图中每个结点都...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2014/07/10/207604.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/207604.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-10 14:26 <a href="http://www.cppblog.com/menjitianya/archive/2014/07/10/207604.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>Asia Hefei Online 2008 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/06/28/207449.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sat, 28 Jun 2014 11:48:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/06/28/207449.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207449.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/06/28/207449.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207449.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207449.html</trackback:ping><description><![CDATA[<p><strong><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asia_online2008.PNG" width="913" height="183" alt="" /><br />A. Constellations</strong></p>  <p style="text-indent:21.0pt">PKU 3690 <a href="http://poj.org/problem?id=3690">http://poj.org/problem?id=3690</a><strong></strong></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>N*M(N&lt;=1000, M &lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的</span>01<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">矩阵</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，再给定</span>T(T &lt;= 100)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个</span>P*Q(P &lt;= 50, Q &lt;= 50)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的</span>01<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">矩阵，问</span>P*Q<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的矩阵中有多少个是</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的子矩阵。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：位压缩</span> + KMP</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">由于</span>P &lt;= 50<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，所以我们可以把所有</span>P*Q<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的矩阵进行二进制位压缩，将</span>P*Q<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的矩阵的每一列压缩成一个</span>64<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位整数，这样</span>P*Q<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的矩阵就变成了一个长度为</span>Q<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的整数序列，用同样的方式对</span>N*M<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的矩阵进行压缩，总共可以产生</span>(N-P+1)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个长度为</span>M<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的整数序列，剩下的就是进行最多</span>(N-P+1)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">次</span>KMP<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">匹配了。</span><strong></strong></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KMP</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">相关算法可以参阅：</span></strong></p>  <p style="text-indent:21.0pt"><a href="http://www.cppblog.com/menjitianya/archive/2014/06/20/207354.html">http://www.cppblog.com/menjitianya/archive/2014/06/20/207354.html</a></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_1.PNG" width="209" height="186" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">图</span>1 &#8216;*&#8217;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">代表二进制的</span>1, &#8217;0&#8217;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">代表二进制的</span>0</p>  <p align="center" style="text-align:center"><strong>&nbsp;</strong></p>  <p><strong>B. DNA repair</strong></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>PKU 3691<strong> </strong><a href="http://poj.org/problem?id=3691">http://poj.org/problem?id=3691</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定</span>N(N &lt;= 50)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个长度不超过</span>20<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的模式串，再给定一个长度为</span>M(M &lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的目标串</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，求在目标串</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">上最少改变多少字符，可以使得它不包含任何的模式串（所有串只有</span>ACGT<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">四种字符）。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：</span>AC<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">自动机</span> + <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">动态规划</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">利用模式串建立</span>trie<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">图，</span>trie<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">图的每个结点</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">即下文讲到的状态</span>j)<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">维护三个结构，</span></p>  <p style="text-indent:21.0pt">Node{</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Node *next[4];&nbsp;&nbsp; // <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">能够到达的四个状态</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的结点指针</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp; id;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">状态</span>ID<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">，用于到数组下标的映射</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp; val;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">当前状态是否是一个非法状态</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">（以某些模式串结尾）</span></p>  <p style="text-indent:21.0pt">}</p>  <p>&nbsp;</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">用</span>DP[i][j]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">表示长度为</span>i (i &lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，状态为</span>j(j &lt;= 50*20 + 1)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的字符串变成目标串</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">需要改变的最少字符，设初始状态</span>j = 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，那么</span>DP[0][0] = 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，其他均为无穷大。从长度</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">到</span>i+1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">进行状态转移，每次转移枚举共四个字符</span>(A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>C<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>G<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>T)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，如果枚举到的字符和</span>S<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">对应位置相同则改变值</span>T=1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，否则</span>T=0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">；那么有状态转移方程</span> DP[i][j] = Min{ DP[i-1][ fromstate ] + T, fromstate<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">为所有能够到达</span>j<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的状态</span> };<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">最后</span>DP[n][j]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">中的最小值就是答案。</span></p>  <p><strong>&nbsp;</strong></p>  <p><strong>C. Kindergarten</strong></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>PKU 3692 <a href="http://poj.org/problem?id=3692">http://poj.org/problem?id=3692</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定</span>G(G &lt;= 200)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个女孩和</span>B(B &lt;= 200)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个男孩，以及</span>M(0 &lt;= M &lt;= G*B)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">条记录</span>(x, y)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">表示</span>x<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">号女孩和</span>y<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">号男孩互相认识。并且所有的女孩互相认识，所有的男孩互相认识，求找到最大的一个集合使得所有人都认识。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：二分图最大匹配</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">一个点集中所有人都认识表示这个点集是个完全图，该问题就是求原图的一个最大团</span>(<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">最大完全子图</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，可以转化为求补图的最大独立集，而补图恰好是个二分图。二分图的最大独立集</span> = <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">总点数</span> - <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">二分图的最大匹配。于是问题就转化成了求补图的最大匹配了。</span></p>  <p style="text-indent:21.0pt">&nbsp;</p>  <p><strong>D. Maximum repetition substring</strong></p>  <p style="text-indent:21.0pt">PKU 3693 <a href="http://poj.org/problem?id=3693">http://poj.org/problem?id=3693</a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定长度为</span>N(N &lt;= 10<sup>5</sup>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的字符串</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，求它的一个最多重复子串</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">注意：最多重复子串不等于最长重复子串，即</span>ababab<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>aaaa<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">应该取后者</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：后缀数组</span> + RMQ</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">枚举重复子串的长度</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果对于某个</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，有</span>S[i*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>S[(i+1)*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最长公共前缀大于等于</span>L(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这一步可以利用后缀数组求解</span>height<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数组，然后通过</span>RMQ<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">查询区间最小值来完成</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么以</span>i*L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首，长度为</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的子串至少会重复两次。</span></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_2.PNG" width="386" height="200" alt="" /><br /></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>2</p>  <p align="left" style="text-indent: 21pt;"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如图，</span>L=3<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">，</span>i=3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的情况，</span>S[3...10]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>S[6...10]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最长公共前缀为</span>3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，即</span>S[3...5]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>S[6...8]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">完全匹配，所以</span>S[3...5]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">重复了两次。反之，如果最长公共前缀小于</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，必定不会重复（因为两个子串之间出现了断层）。</span></p>  <p align="left" style="text-indent: 21pt;"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">推广到更一般的情况，如果</span>S[i*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>S[(i+1)*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最长公共前缀为</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么以</span>S[i*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首的重复子串的重复次数为</span>T / L + 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，而且我们可以发现如果以</span>S[i*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首，长度为</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的子串的重复次数大于等于</span>2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么它一定不会比以</span>S[(i+1)*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首的子串的重复次数少，这个是显然的，比如</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为</span>2<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的时候，</span>ababab<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一定比</span>abab<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">多重复一次，基于这个性质，我们定义一个</span>new_flag<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">标记，表示是否需要计算接下来匹配到的串</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如</span>ababab<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>abab<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的情况，前者计算过了，就把</span>new_flag<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">置为</span>false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，就不会计算</span>abab<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的情况了</span>)<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">，得出完整算法：</span></p>  <p align="left" style="margin-left: 0cm; text-indent: 21pt;">1) <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">枚举重复子串的长度</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，初始化</span>new_flag<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">标记为</span>true<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p align="left" style="margin-left: 0cm; text-indent: 21pt;">2) <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">枚举</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，计算</span>S[i*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>S[(i+1)*L ... N]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最长公共前缀</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p align="left" style="margin-left: 21pt; text-indent: 21pt;">a) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果</span>T &lt; L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span>new_flag<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">标记为</span>true<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt">b) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果</span>T &gt;= L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，判断</span>new_flag<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是不是为</span>false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果为</span>false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，说明以</span>S[i*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首的串和</span>S[(i-1)*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为首的串的最长公共前缀大于等于</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，跳转到</span>2)<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">；否则转</span>3)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="text-indent:21.0pt">3) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">因为</span>S[i*L, (i+1)*L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">有重复子串，但是字典序不一定最小，所以还需要枚举区间</span> [i-L+1, i+L]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，看是否存在字典序更小的子串，比较字典序这一步可以直接使用后缀数组计算出来的</span>rank<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">值进行比较。</span></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RMQ</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">相关算法可以参阅：</span></strong></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><a href="http://www.cppblog.com/menjitianya/archive/2014/06/26/207420.html">http://www.cppblog.com/menjitianya/archive/2014/06/26/207420.html</a></p>  <p>&nbsp;</p>  <p><strong>E. Network</strong></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PKU 3694 <a href="http://poj.org/problem?id=3694">http://poj.org/problem?id=3694</a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定</span>N(N &lt;= 10<sup>5</sup>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个点和</span>M(N-1 &lt;= M &lt;= 2*10<sup>5</sup>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">条边的无向连通图，进行</span>Q(Q &lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">次加边，每次加入一条边要求输出当前图中有多少条割边。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：无向图割边、最近公共祖先</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">利用</span>tarjan<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">求出原图的割边，由于这题数据量比较大，所以用递归可能会爆栈，需要栈模拟实现递归过程，</span>tarjan<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">计算的时候用</span>parent[u]<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">保存</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的父结点，每个结点进出栈各一次，出栈时表示以它为根结点的子树访问完毕，然后判断</span>(u, parent[u])<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">是否为割边。每次询问</span>u, v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">加入后会有多少割边，其实就是求</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">和</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的到它们的最近公共祖先</span>lca(u, v)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的路径上有多少割边，由于在进行</span>tarjan<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">计算的时候保存了每个结点的最早访问时间</span>dfn[u]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，那么有这么一个性质：</span>dfn[ parent[u] ] &lt; dfn[u]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，这是显然的</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">父结点的访问先于子结点</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">。于是当</span>dfn[u] &lt; dfn[v]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，将</span>parent[v]<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">赋值给</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，反之，将</span>parent[u]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">赋值给</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，因为是一棵树，所以进过反复迭代，一定可以出现</span>u == v <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的情况，这时候的</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">就是原先</span>u<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">和</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的最近公共祖先，在迭代的时候判断路径上是否存在割边，路径上的割边经过</span>(u, v)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">这条边的加入都将成为非割边，用一个变量保存割边数目，输出即可。</span></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_3.PNG" width="301" height="410" alt="" /><br /></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">图</span>3</p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">如图</span>3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，图中实线表示树边，虚线表示原图中的边，但是进行</span>tarjan<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">计算的时候</span>7<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">这个结点被</span>(6, 7)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">这条边&#8220;捷足先登&#8221;了，于是</span>(4, 7)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">成为了一条冗余边，计算完后这个图的割边为</span>(1, 2)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>(1,3)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>(3, 4)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>(3, 5)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，分别标记</span>bridge[2]<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>bridge[3]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>bridge[4]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>bridge[5]<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">为</span>true<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">当插入一条边</span>(7, 5)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，那么沿着</span>7<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">的祖先路径和</span>5<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的祖先路径最后找到的最近公共祖先为</span>3(<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">路径为</span>7 -&gt; 6 -&gt; 4 -&gt; 3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">和</span> 5 -&gt; 3)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，</span>(3, 4)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>(3, 5)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">这两条割边因为加入了</span>(7, 5)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">这条边而变成了普通边，将标记</span>bridge[4]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">、</span>bridge[5]<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">置为</span>false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">。</span></p>  <p><strong>&nbsp;</strong></p>  <p><strong>F. Rectangles</strong></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>PKU 3695 <a href="http://poj.org/problem?id=3695">http://poj.org/problem?id=3695</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题意：给定</span>N(N &lt;= 20)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个矩形，以及</span>M(M &lt;= 10<sup>5</sup>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">次询问，询问</span>R(R &lt;= N)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">个矩形的并。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">题解：离散化</span> + <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">暴力</span>( <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">或</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">容斥原理</span> )</p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">离散化：由于矩形很少，所以可以将它们的</span>XY<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">坐标分别离散到整点，两个维度分别离散，点的总数不会超过</span>2N<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，对于本次询问，利用前一次询问的结果进行面积的增减，对每个矩形进行判断，一共有两种情况：</span></p>  <p style="text-indent:21.0pt">1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">）这个矩形前一次询问出现，本次询问不出现，对它的所有离散块进行自减操作，如果某个离散块计数减为</span>0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">，则总面积减去这个离散块的面积；</span></p>  <p style="text-indent:21.0pt">2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">）这个矩形前一次询问没出现，本次询问出现，对它的所有离散块进行自增操作，如果某个离散块计数累加后为</span>1<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">，则总面积加上这个离散块的面积；</span></p>  <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">容斥原理：对于每个询问，利用</span>dfs<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">枚举每个矩形取或不取，取出来的所有矩形作相交操作，所有</span>[<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">奇数个矩形交</span>]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的面积和</span> &#8211; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">所有</span>[<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">偶数个矩形交</span>]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">的面积和</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">就是答案，因为是</span>dfs<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">枚举，所以在枚举到某次相交矩形面积为</span>0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;;">的时候就不需要再枚举下去了，算是一个比较强的剪枝。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">如图</span>4<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">，红色区域为被覆盖了一次的区域，橙色区域为被覆盖了两次的区域，黄色区域为被覆盖了三次的区域，那么先将所有的三个矩形加起来，然后需要减掉重叠的部分，重叠的减掉后发现，重叠的部分多减了，即图中黄色的部分被多减了一次，需要加回来。所以容斥原理可以概括为：奇数加，偶数减。</span></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_4.PNG" width="301" height="410" alt="" /><br /></p>  <p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;">图</span>4</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>  <p><strong></strong></p><p><strong>G. The Luckiest number</strong></p>  <p style="text-indent:21.0pt">PKU 3696 <a href="http://poj.org/problem?id=3696">http://poj.org/problem?id=3696</a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>L(L &lt;= 2*10<sup>9</sup>)<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，求一个最小的数</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，满足</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">仅由数字</span>&#8217;8&#8217;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">组成，并且</span>T<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的倍数。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：欧拉定理</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">首先，长度为</span><span style="color:#333333;background:white">N</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">的仅由</span><span style="color:#333333;background:white">8</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">组成的数字可以表示为</span><span style="color:#333333;background:white">8*(10<sup>N</sup>-1)/9</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">如果它能被</span><span style="color:#333333;background:white">L</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">整除，则可以列出等式</span><span style="color:#333333;background:white">(1)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">：</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="color:#333333;background:white">8*(10<sup>N</sup>-1)/9 = KL&nbsp;&nbsp;&nbsp;&nbsp; (</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">其中</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">为任意正整数</span><span style="color:#333333;background:white">)&nbsp; (1) </span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">将等式稍作变形得到等式</span><span style="color:#333333;background:white">(2)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">：</span> </p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="color:#333333;background:white">(10<sup>N</sup>-1) = 9KL/8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (2)</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">由于存在分母，所以我们需要先对分数部分进行约分，得到等式</span><span style="color:#333333;background:white">(3)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">：</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">令</span><span style="color:#333333;background:white">A = L/GCD(8, L),&nbsp; B = 8/GCD(8, L)</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="color:#333333;background:white">(10<sup>N</sup>-1) = 9K*A / B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (3)</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">因为</span><span style="color:#333333;background:white">A</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">和</span><span style="color:#333333;background:white">B</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">已经互质，所以如果</span><span style="color:#333333;background:white">B</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">不为</span><span style="color:#333333;background:white">1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，为了保证等式右边仍为整数，</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">必须能被</span><span style="color:#333333;background:white">B</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">整除，而</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">为任意整数，所以一定能够找到一个</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">正好是</span><span style="color:#333333;background:white">B</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">的倍数，所以可以在等式两边同时模</span><span style="color:#333333;background:white">9A</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，得到</span><span style="color:#333333;background:white">(10<sup>N</sup>-1) mod (9A) = 0</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">，稍作变形，得到等式</span><span style="color:#333333;background:white">(4):</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="color:#333333;background:white"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_6.PNG" width="122" height="33" alt="" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(4)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">于是需要引入一个定理，即欧拉定理。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">欧拉定理的描述为：若</span><span style="color:#333333;background:white">n, a</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">为正整数，且</span><span style="color:#333333;background:white">n, a</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">互质，则：</span></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asiahefei_5.PNG" width="116" height="22" alt="" /><br /></p>  <p align="center" style="text-align:center;text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>5</p>  <p align="center" style="text-align:center;text-indent:21.0pt">(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#968;</span>(n)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span>n<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的欧拉函数，即小于等于</span>n<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">并且和</span>n<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">互素的数的个数</span>)</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这样一来，我们发现只要</span>10<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>9A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">互质，</span><span style="font-size: 10.5pt; font-family: 宋体;">只需要求</span><span style="font-size: 10.5pt; font-family: 'Times New Roman';">9A</span><span style="font-size: 10.5pt; font-family: 宋体;">的欧拉函数，但是求出来的欧拉函数是不是一定使得</span><span style="font-size: 10.5pt; font-family: 'Times New Roman';">N</span><span style="font-size: 10.5pt; font-family: 宋体;">最小呢，并不是，所以还需要枚举欧拉函数的因子，如果它的某个因子</span><span style="font-size: 10.5pt; font-family: 'Times New Roman';">T也</span><span style="font-size: 10.5pt; font-family: 宋体;">满足(4)的等式，那么T肯定不会比</span><span style="text-align: center; font-family: 宋体;">&#968;</span><span style="text-align: center;">(9A)大，所以T一定更优。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里</span>9A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">有可能超过</span>32<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位整数，所以计算过程中遇到的乘法操作不能直接相乘</span>(<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">两个超过</span>32<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位整数的数相乘会超过</span>64<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位整数</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，需要用到二分乘法，即利用二进制加法模拟乘法，思想很简单，就直接给出一段代码吧。</span></p><p>&nbsp;</p>  <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">&nbsp;1</span>&nbsp;<span style="color: #0000FF; ">#define</span>&nbsp;LL&nbsp;__int64<br /><span style="color: #008080; ">&nbsp;2</span>&nbsp;&nbsp;<br /><span style="color: #008080; ">&nbsp;3</span>&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">计算&nbsp;a*b&nbsp;%&nbsp;mod</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">&nbsp;4</span>&nbsp;<span style="color: #008000; "></span>LL&nbsp;Produc_Mod(LL&nbsp;a,&nbsp;LL&nbsp;b,&nbsp;LL&nbsp;mod)&nbsp;{<br /><span style="color: #008080; ">&nbsp;5</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LL&nbsp;sum&nbsp;=&nbsp;0;<br /><span style="color: #008080; ">&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>(b)&nbsp;{<br /><span style="color: #008080; ">&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(b&nbsp;&amp;&nbsp;1)&nbsp;sum&nbsp;=&nbsp;(sum&nbsp;+&nbsp;a)&nbsp;%&nbsp;mod;<br /><span style="color: #008080; ">&nbsp;8</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;=&nbsp;(a&nbsp;+&nbsp;a)&nbsp;%&nbsp;mod;<br /><span style="color: #008080; ">&nbsp;9</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b&nbsp;&gt;&gt;=&nbsp;1;<br /><span style="color: #008080; ">10</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">11</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;sum;<br /><span style="color: #008080; ">12</span>&nbsp;}<br /><span style="color: #008080; ">13</span>&nbsp;&nbsp;<br /><span style="color: #008080; ">14</span>&nbsp;&nbsp;<br /><span style="color: #008080; ">15</span>&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">计算a^b&nbsp;%&nbsp;mod</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">16</span>&nbsp;<span style="color: #008000; "></span>LL&nbsp;Power(LL&nbsp;a,&nbsp;LL&nbsp;b,&nbsp;LL&nbsp;mod)&nbsp;{<br /><span style="color: #008080; ">17</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LL&nbsp;sum&nbsp;=&nbsp;1;<br /><span style="color: #008080; ">18</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>(b)&nbsp;{<br /><span style="color: #008080; ">19</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(b&nbsp;&amp;&nbsp;1)&nbsp;sum&nbsp;=&nbsp;Produc_Mod(sum,&nbsp;a,&nbsp;mod);<br /><span style="color: #008080; ">20</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;=&nbsp;Produc_Mod(a,&nbsp;a,&nbsp;mod);<br /><span style="color: #008080; ">21</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b&nbsp;&gt;&gt;=&nbsp;1;<br /><span style="color: #008080; ">22</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">23</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;sum;<br /><span style="color: #008080; ">24</span>&nbsp;}</div>  <p>&nbsp;</p>  <p><strong>H. USTC campus network</strong></p>  <p style="text-indent:21.0pt">PKU 3697 <a href="http://poj.org/problem?id=3697">http://poj.org/problem?id=3697</a></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>N, M(N &lt;= 10<sup>4</sup>, M &lt;= 10<sup>6</sup>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，求</span>N<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个点的完全图删掉</span>M<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">条边后，和</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这个结点相邻的点的数目。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span>BFS</p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">利用前向星存边</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里边的含义是反的，</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>j<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">有边表示</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>j<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">不直接连通</span>)<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">。然后从</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">开始广搜，将和</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">有边的点</span>hash<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">掉，然后枚举</span>hash<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数组中没有</span>hash<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">掉的点</span>(<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">这些点是和</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">连通的</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果点没有被访问过，标记已访问，入队；然后不断弹出队列首元素进行相同的处理。</span></p>  <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里可以加入一个小优化，将所有点分组，编号</span>0-9<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的分为一组，</span>10-19<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的分为一组，</span>20-29<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的分为一组，然后用一个计数器来记录每个组中的点是否被访问，每次访问到一个点的时候计数器自增，当某个组的计数器为</span>10<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时候表示这个组内所有点都被访问过了，不需要再进行枚举了，这样可以把最坏复杂度控制在</span> O( N*N/10 ) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">以下。</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207449.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-06-28 19:48 <a href="http://www.cppblog.com/menjitianya/archive/2014/06/28/207449.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RMQ</title><link>http://www.cppblog.com/menjitianya/archive/2014/06/26/207420.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Thu, 26 Jun 2014 08:35:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/06/26/207420.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207420.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/06/26/207420.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207420.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207420.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: RMQ  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 定义：&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A[0...n-1] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2014/06/26/207420.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/207420.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-26 16:35 <a href="http://www.cppblog.com/menjitianya/archive/2014/06/26/207420.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>KMP</title><link>http://www.cppblog.com/menjitianya/archive/2014/06/20/207354.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Fri, 20 Jun 2014 13:37:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/06/20/207354.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207354.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/06/20/207354.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207354.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207354.html</trackback:ping><description><![CDATA[<p style="margin-bottom:0pt; margin-top:0pt; text-align:center; "><span style="font-size: 14pt; font-family: 宋体;">K</span><span style="mso-spacerun:'yes'; font-size:14.0000pt; font-family:'宋体'; ">MP</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp; &nbsp; &nbsp; &nbsp; KMP</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">算法</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">可以说</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">所有数据结构书上都有，上大学的时候也陆陆续续学过三次，每次学完看似理解了，</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">可是</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">过了</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">不到</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">半年又</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">忘记了，或许是因为代码太短，能写出来就以为自己会了，没有深入去理解，导致下次再来看的时候感觉很陌生，一定是这样的。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">&nbsp; &nbsp; 今天看了matrix67对KMP的解释，很赞，附上地址：</span><a href="http://www.matrix67.com/blog/archives/115"><span style="color: #0000ff; font-family: 'Times New Roman';">http://www.matrix67.com/blog/archives/115</span></a></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">&nbsp; &nbsp; 为了让老年的自己不用在迟暮的时候再学一遍KMP，还是决定把一些关键性的东西记录下来，如果那时候的自己看到自己当年写的这篇笔记能有恍然大悟的感觉，那么现在就不是在浪费时间了。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">定义：</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S[1...&nbsp;n]&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;T[1...m]&nbsp;&nbsp;&nbsp;模式串</span><br /></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">算法目的：</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 从目标串S中找到一个子串和模式串T完全匹配。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">算法核心思想：</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">1)&nbsp;枚举i从1到n，在S[i-j...i-1]和T[1...j]完全匹配的前提下，判断S[i]是否和T[j+1]相等：</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">a)&nbsp;如果相等，说明S[i-j...i]和T[1...j+1]完全匹配，那么i和j都自增1；</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">b)&nbsp;如果不相等，则需要找到一个最大的j'&nbsp;&lt;&nbsp;j，满足S[i-j'...i-1]和T[1...j']完全匹配；</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">2)&nbsp;当i=n或j=m的时候说明匹配结束，否则重复1)；<br /><br /></span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">	</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">对于j'可以这样理解，由于前提是S[i-j...i-1]和T[1...j]完全匹配，如果要找到一个j'满足S[i-j'...i-1]和T[1...j']也完全匹配，那么T[1...j']必定为T[1...j]的后缀，</span><span style="font-family: 宋体; font-size: 10.5pt;">证明如下：首先将以下的子串进行编号：&nbsp;</span><span style="font-family: 宋体; font-size: 10.5pt;">A&nbsp;=&nbsp;S[i-j...i-1]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B&nbsp;=&nbsp;T[1...j]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C&nbsp;=&nbsp;S[i-j'...i-1]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D&nbsp;=&nbsp;T[1...j']</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">因为A和B完全匹配，C和D完全匹配，由于C为A的后缀，所以D为B的后缀。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">当S[i]和T[j+1]不相等的时候需要调整j的值，调整完后的j&nbsp;=&nbsp;Next[j](这个Next[j]就是之前所说的j')，需要满足 T[1&nbsp;...&nbsp;Next[j]&nbsp;]&nbsp;=&nbsp;=&nbsp;T[&nbsp;j&nbsp;-&nbsp;Next[j]&nbsp;+&nbsp;1...&nbsp;j&nbsp;]， 并且Next[j]的值最大，比较书面的说法就是Next[j]表示</span><span style="mso-spacerun:'yes'; color:#ff0000; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">在模式串T中以第j个元素为结尾的最长后缀中满足它是T的前缀的后缀的长度</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">举个例子，T&nbsp;=&nbsp;"ababaaba"的Next数组为&nbsp;[0,&nbsp;0,&nbsp;1,&nbsp;2,&nbsp;3,&nbsp;1,&nbsp;2,&nbsp;3]。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">由于Next数组表示的含义只和自身的性质有关，所以在没有目标串的情况下同样可以求出Next数组，KMP的精妙之处就在于求这个Next数组了。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "></span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">在上文中提到的S和T的匹配中，每次S[i-j...i-1]都是尽量找到最大的j使得它和T[1...j]完全匹配，当然有可能找不到这样的j，此时令j&nbsp;=&nbsp;0，即&nbsp;S[i,i-1]和T[1,0]匹配(这是两个空串，空串和空串也可以匹配，hohoho~~所以j是一定存在的)。如果现在把S换成T，那么问题就转化成了T[i-j...i-1]和T[1...j]的匹配问题了，如果T[i-j...i-1]和T[1...j]完全匹配，并且T[1...j]是和T[i-j...i-1]匹配的最长的串，那么&nbsp;Next[i-1]&nbsp;就是&nbsp;j（思考一下红色字的定义就明白了），于是问题就转化成了T的自我匹配的过程了。<br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>算法复杂度：</strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;O(n+m)</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">&nbsp;&nbsp;&nbsp;&nbsp;Next函数的求解非常简洁：</span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">&nbsp;1</span>&nbsp;<span style="color: #0000FF; ">#define</span>&nbsp;MAXN&nbsp;1000010<br /><span style="color: #008080; ">&nbsp;2</span>&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;next[MAXN];<br /><span style="color: #008080; ">&nbsp;3</span>&nbsp;&nbsp;<br /><span style="color: #008080; ">&nbsp;4</span>&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;传入的字符串下标需要以1开头</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">&nbsp;5</span>&nbsp;<span style="color: #008000; "></span><span style="color: #0000FF; ">void</span>&nbsp;getNext(<span style="color: #0000FF; ">int</span>&nbsp;m,&nbsp;<span style="color: #0000FF; ">char</span>&nbsp;*str)&nbsp;{<br /><span style="color: #008080; ">&nbsp;6</span>&nbsp;next[1]&nbsp;=&nbsp;0;<br /><span style="color: #008080; ">&nbsp;7</span>&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;枚举模式串的每个位置，判断以当前字符结尾能够匹配到的最大前缀</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">&nbsp;8</span>&nbsp;<span style="color: #008000; "></span><span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;j&nbsp;=&nbsp;0,&nbsp;i&nbsp;=&nbsp;2;&nbsp;i&nbsp;&lt;=&nbsp;m;&nbsp;i++)&nbsp;{<br /><span style="color: #008080; ">&nbsp;9</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;在str[i-j<img src="http://www.cppblog.com/Images/dot.gif" alt="" />&nbsp;i-1]和str[1<img src="http://www.cppblog.com/Images/dot.gif" alt="" />j]&nbsp;完全匹配的前提下判断str[i]和str[j+1]是否相等<br /></span><span style="color: #008080; ">10</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;如果不相等，则减小j的值，直到匹配到完全相等位置</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">11</span>&nbsp;<span style="color: #008000; "></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>(&nbsp;j&nbsp;&gt;&nbsp;0&nbsp;&amp;&amp;&nbsp;str[i]&nbsp;!=&nbsp;str[j+1]&nbsp;)&nbsp;j&nbsp;=&nbsp;next[j];<br /><span style="color: #008080; ">12</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;如果能够找到以i结尾的后缀和以j+1结尾的前缀完全匹配，j自增1。</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">13</span>&nbsp;<span style="color: #008000; "></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(str[i]&nbsp;==&nbsp;str[j+1])&nbsp;j&nbsp;++;<br /><span style="color: #008080; ">14</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;这里j有两种情况：<br /></span><span style="color: #008080; ">15</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;j&nbsp;=&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;以i结尾的后缀找不到一个前缀和它完全匹配<br /></span><span style="color: #008080; ">16</span>&nbsp;<span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;j&nbsp;&gt;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;以i结尾的后缀和以j结尾的前缀完全匹配，更新Next函数的值</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">17</span>&nbsp;<span style="color: #008000; "></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next[i]&nbsp;=&nbsp;j;<br /><span style="color: #008080; ">18</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br /><span style="color: #008080; ">19</span>&nbsp;}</div><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">PKU</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">&nbsp;3461&nbsp;Oulipo</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：求一个匹配串</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">T在目标串S中的出现次数。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">求出</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">T的</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">N</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">ext数组</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">，然后和S进行KMP匹配，匹配时当j&nbsp;=&nbsp;=m的时候表示找到一个可行解，计数器+1，然后将Next[j]赋值给j，使得它的最长前缀能够继续和目标串进行匹配。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">KMP匹配过程和Next数组的求解是一样的。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">&nbsp;1</span>&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;S[1<img src="http://www.cppblog.com/Images/dot.gif" alt="" />n]&nbsp;目标串<br /></span><span style="color: #008080; ">&nbsp;2</span>&nbsp;<span style="color: #008000; "></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;T[1<img src="http://www.cppblog.com/Images/dot.gif" alt="" />m]&nbsp;匹配串&nbsp;</span><span style="color: #008000; "><br /></span><span style="color: #008080; ">&nbsp;3</span>&nbsp;<span style="color: #008000; "></span><span style="color: #0000FF; ">int</span>&nbsp;KMP(<span style="color: #0000FF; ">int</span>&nbsp;n,&nbsp;<span style="color: #0000FF; ">char</span>&nbsp;*S,&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;m,&nbsp;<span style="color: #0000FF; ">char</span>&nbsp;*T)&nbsp;{<br /><span style="color: #008080; ">&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;cnt&nbsp;=&nbsp;0;<br /><span style="color: #008080; ">&nbsp;5</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span>&nbsp;j&nbsp;=&nbsp;0,&nbsp;i&nbsp;=&nbsp;1;&nbsp;i&nbsp;&lt;=&nbsp;n;&nbsp;i++)&nbsp;{<br /><span style="color: #008080; ">&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">while</span>(&nbsp;j&gt;0&nbsp;&amp;&amp;&nbsp;S[i]&nbsp;!=&nbsp;T[j+1])&nbsp;j&nbsp;=&nbsp;next[j];<br /><span style="color: #008080; ">&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(S[i]&nbsp;==&nbsp;T[j+1])&nbsp;j++;<br /><span style="color: #008080; ">&nbsp;8</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(j&nbsp;==&nbsp;m)&nbsp;{<br /><span style="color: #008080; ">&nbsp;9</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cnt&nbsp;++;<br /><span style="color: #008080; ">10</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j&nbsp;=&nbsp;next[j];<br /><span style="color: #008080; ">11</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">12</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><span style="color: #008080; ">13</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;cnt;<br /><span style="color: #008080; ">14</span>&nbsp;}</div><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">HDU</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">&nbsp;4763&nbsp;Theme&nbsp;Section</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定一个长度为</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">N(1&nbsp;&lt;=&nbsp;N&nbsp;&lt;=&nbsp;10</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:super; ">6</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)的字符串S，问能否和模式串EAEBE进行匹配其中A和B表示任意随机字符，如果能匹配，输出E的最大可能长度，不能匹配输出0。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：首先利用KMP求出S的Next数组，那么S[1...Next[N]]、S[1...Next[Next[N]]]、S[1...Next[...[N]]&nbsp;]必定能和S的后缀进行完全匹配，将这些Next[i]利用一次迭代求出来，最终的答案一定在这些值中，然后从大到小枚举这些值，判断可行性。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">假设当前枚举长度为i，那么在S[i+1&nbsp;...&nbsp;N-i]&nbsp;中如果能够找到一个长度为i的子串满足和S[1...i]完全匹配，那么i就是一个可行解，又因为枚举是从大到小进行的，所以i就是E可能的最大长度。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">于是问题就转变成了判断S[i+1&nbsp;...&nbsp;N-i]中是否存在一个和S[1...i]完全匹配的子串。如果存在，那么必定存在一个k(&nbsp;2*i&nbsp;&lt;=&nbsp;k&nbsp;&lt;=&nbsp;N-i&nbsp;)，使得S[k-i+1&nbsp;...&nbsp;k]&nbsp;=&nbsp;=&nbsp;S[1&nbsp;...&nbsp;i&nbsp;]，所以必定有Next[Next[...[k]]]&nbsp;=&nbsp;=&nbsp;i，所以我们可以预先将S[i+1&nbsp;...&nbsp;N-i]区间内所有的Next值退化后进行Hash，然后在枚举某个长度i的时候去Hash数组中找i是否被标记，如果被标记说明存在某个k满足S[k-i+1&nbsp;...&nbsp;k]&nbsp;=&nbsp;=&nbsp;S[1&nbsp;...&nbsp;i&nbsp;]，i就是最大可能长度。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">HDU</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">&nbsp;2594&nbsp;Simpsons&#8217;&nbsp;Hidden&nbsp;Talents</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定两个长度不大于</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">50000的</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">串，求两个串的一个最长公共子串满足子串为第一个串的前缀，并且为第二个串的后缀。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：将两个串用一个从未出现过的字符连接，拼成一个长度为</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">N的串，</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">然后进行一次自我匹配，求出</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">next数组，根据Next数组的定义，Next[N]就是所求的最大长度。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">HDU&nbsp;3746&nbsp;Cyclic&nbsp;Nacklace</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定一个长度为N(N&nbsp;&lt;=&nbsp;10</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:super; ">5</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)的字符串S，求在它的末尾添加几个字符使得他变成一个至少重复两次的连续重复串，要求添加的字符数最少。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：首先利用KMP进行一次自我匹配求出Next数组，然后枚举重复串的长度i，令x&nbsp;=&nbsp;i&nbsp;*&nbsp;(N/i)，如果x&nbsp;-&nbsp;Next[x]&nbsp;==&nbsp;i，说明S[x]是S的一个连续重复子串（或者叫连续重复前缀更加贴切），理由很简单，将字符串S[x]以长度i为单位分组，</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">S[1...i]&nbsp;&nbsp;&nbsp;S[i+1...2i]&nbsp;&nbsp;S[2i+1...3i]&nbsp;&nbsp;&nbsp;&#8230;&#8230;&nbsp;&nbsp;&nbsp;S[(N/i-1)i&nbsp;+&nbsp;1...(N/i)i]</span></p><p style="margin-left:42.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">&nbsp;&nbsp;&nbsp;S[1...i]&nbsp;&nbsp;&nbsp;S[i+1...2i]&nbsp;&nbsp;&nbsp;&#8230;&#8230;&nbsp;&nbsp;S[(N/i-2)i&nbsp;+&nbsp;1...(N/i-1)i]</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">由于x&nbsp;+&nbsp;i&nbsp;=&nbsp;=&nbsp;Next[x]，可以列出连等式，有如下等价关系：S[1...i]&nbsp;=&nbsp;=&nbsp;S[i+1...2i]&nbsp;=&nbsp;=&nbsp;...&nbsp;=&nbsp;=&nbsp;S[(N/i-1)i&nbsp;+&nbsp;1...(N/i)i]。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">那么剩下的就是要看S[x+1...N]是否为S的前缀，同样可以根据Next数组的定义进行判断，特殊的，当x&nbsp;==&nbsp;N时，S[x+1...N]&nbsp;==&nbsp;S[N+1,N]为空串，必定为S的前缀，也是满足条件的，枚举所有满足条件的长度L，取L&nbsp;-&nbsp;(N-x)的最小者就是答案了。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">PKU&nbsp;2406&nbsp;Power&nbsp;Strings</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定一个长度不超过N(N&nbsp;&lt;=&nbsp;10</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:super; ">6</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)的字符串，它一定是某个串重复K次得到，求这个K的最大值。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：假设子串T重复K次后得到串S，那么T的长度一定为L&nbsp;=&nbsp;N/K(要整除)，则T&nbsp;=&nbsp;S[1...L]，将S拆分成K份，每份长度为L，则有</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">S[1...L]&nbsp;=&nbsp;S[L+1...2L]&nbsp;=&nbsp;S[2L+1...3L]&nbsp;=&nbsp;...&nbsp;=&nbsp;S[(K-1)L+1...KL]</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">由于要保证K最大，势必L要取最小，所以根据Next函数的定义，有Next[KL]&nbsp;=&nbsp;(K-1)L;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">即Next[N]&nbsp;=&nbsp;N&nbsp;-&nbsp;L，所以L&nbsp;=&nbsp;N&nbsp;-&nbsp;Next[N];</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">但是得出的长度L还要保证能被N整除，所以如果不能整除说明L&nbsp;=&nbsp;N，即K&nbsp;=&nbsp;1；而如果能整除，那么K&nbsp;=&nbsp;N&nbsp;/&nbsp;(N&nbsp;-&nbsp;Next[N]);</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">PKU&nbsp;2752&nbsp;Seek&nbsp;the&nbsp;Name,&nbsp;Seek&nbsp;the&nbsp;Fame</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定一个长度为N(N&nbsp;&lt;=&nbsp;400000)的字符串，求它的前缀等于后缀的所有子串的长度。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：考察Next数组的定义。不断迭代求N的Next，Next[N]的Next......然后逆序输出即可。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><div style="display: inline-block;"></div><p>&nbsp;</p><p class="p0" style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">HDU&nbsp;3374&nbsp;String&nbsp;Problem</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定一个长度为N(N&nbsp;&lt;=&nbsp;10</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:super; ">6</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)的字符串S，然后将它进行左移，总共产生N个循环字符串，求其中字典序最小的串的编号以及这样的串的个数，和字典序最大的串的编号以及这样的串的个数。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：先求字典序最小的，字典序最大的只需要将每个字符用127减去本身再求一次字典序最小即可；定义两个指针i，j，i初始为0，j初始为1，再定义一个长度变量k&nbsp;=&nbsp;0：</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">1)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">比较S[i+k]&nbsp;和S[j+k]的大小关系：</span></p><p style="margin-left:21.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">a)&nbsp;如果相等，k自增1；当k==N则跳出循环，否则继续1)的比较；</span></p><p style="margin-left:21.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">b)&nbsp;如果S[i+k]&nbsp;&lt;&nbsp;S[j+k]，j +=&nbsp;k + 1,&nbsp;k&nbsp;=&nbsp;0;&nbsp;</span></p><p style="margin-left:21.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">c)&nbsp;如果S[i+k]&nbsp;&gt;&nbsp;S[j+k],&nbsp;i +=&nbsp;k&nbsp;+ 1,&nbsp;k&nbsp;=&nbsp;0;</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">2)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">如果i&nbsp;和j相等，j自增1；当j==N或i==N则跳出循环，否则继续1)的比较；</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">这样循环结束后如果，取i和j的小者就是答案。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">然后在利用求出来的下标，生成一个新的字符串作为匹配串和一个原串的两倍的串作为目标串进行KMP匹配，得到种数。<br /><br /></span></p><strong><span style="font-family: 宋体; text-indent: 28px;">PKU&nbsp;3690</span><span style="text-indent: 28px;">&nbsp;</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt;">Constellations</span></strong><p class="p0" style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">题意：给定<font face="Times New Roman">N*M(N&lt;=1000,&nbsp;M&nbsp;&lt;=&nbsp;1000)</font><font face="宋体">的</font><font face="Times New Roman">01</font><font face="宋体">矩阵</font><font face="Times New Roman">S</font><font face="宋体">，再给定</font><font face="Times New Roman">T(T&nbsp;&lt;=&nbsp;100)</font><font face="宋体">个</font><font face="Times New Roman">P*Q(P&nbsp;&lt;=&nbsp;50,&nbsp;Q&nbsp;&lt;=&nbsp;50)</font><font face="宋体">的</font><font face="Times New Roman">01</font><font face="宋体">矩阵，问</font><font face="Times New Roman">P*Q</font><font face="宋体">的矩阵中有多少个是</font><font face="Times New Roman">S</font><font face="宋体">的子矩阵。</font></span><span style="font-size: 10.5pt; font-family: 宋体;"><o:p></o:p></span></p><p class="p0" style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">题解：由于<font face="Times New Roman">P&nbsp;&lt;=&nbsp;50</font><font face="宋体">，所以我们可以把所有</font><font face="Times New Roman">P*Q</font><font face="宋体">的矩阵进行二进制位压缩，将</font><font face="Times New Roman">P*Q</font><font face="宋体">的矩阵的每一列压缩成一个</font><font face="Times New Roman">64</font><font face="宋体">位整数，这样</font><font face="Times New Roman">P*Q</font><font face="宋体">的矩阵就变成了一个长度为</font><font face="Times New Roman">Q</font><font face="宋体">的整数序列</font><font face="Times New Roman">T</font><font face="宋体">，用同样的方式对</font><font face="Times New Roman">N*M</font><font face="宋体">的矩阵进行压缩，总共可以产生</font><font face="Times New Roman">(N-P+1)</font><font face="宋体">个长度为</font><font face="Times New Roman">M</font><font face="宋体">的整数序列，剩下的就是进行最多</font><font face="Times New Roman">(N-P+1)</font><font face="宋体">次</font><font face="Times New Roman">KMP</font><font face="宋体">匹配了。</font></span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'Times New Roman'; "><o:p></o:p></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;"><br /><br /></span></p><img src ="http://www.cppblog.com/menjitianya/aggbug/207354.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-20 21:37 <a href="http://www.cppblog.com/menjitianya/archive/2014/06/20/207354.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>3</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><item><title>Southeastern Europe 2007 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/06/01/207161.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sat, 31 May 2014 16:03:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/06/01/207161.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207161.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/06/01/207161.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207161.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207161.html</trackback:ping><description><![CDATA[<div align="center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/souer2007.png" width="821" height="205" alt="" /></div><br /><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">A&nbsp;.&nbsp;John</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3480&nbsp;<a href="http://poj.org/problem?id=3480">http://poj.org/problem?id=3480</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：N堆石子，两人轮流从其中一堆中取任意石子，最后一个取完石子的人输。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：博弈。</span></p><p style="margin-left:42.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">1)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">当所有石子的SG值异或和不等于0时：</span></p><p style="margin-left:42.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">a)&nbsp;个数大于1的堆数=0，必定是奇数个1，所以先手必输；</span></p><p style="margin-left:63.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">b)&nbsp;个数大于1的堆数=1，总能想办法将局面变成奇数个1，所以先手必胜；</span></p><p style="margin-left:42.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">c)&nbsp;个数大于1的堆数&gt;1，总能取掉某些石子，使得所有石子的SG值异或和为0，并且个数大于1的堆数至少还剩两堆；</span></p><p style="margin-left:42.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">2)&nbsp;当所有石子的SG值异或和等于0时：</span></p><p style="margin-left:42.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">a)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">个数大于1的堆数=0，必定是偶数个1，先手必胜；</span></p><p style="margin-left:42.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">b)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">个数大于1的堆数=1（不存在）；</span></p><p style="margin-left:42.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">c)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">个数大于1的堆数&gt;1，无论怎么取，SG值异或和都不可能为0。并且无论先手怎么移，后手可以要么进入偶数个1的状态，要么保持SG值和为0并且非全1的状态（</span><span style="mso-spacerun:'yes'; color:#ff0000; font-size:10.5000pt; font-family:'宋体'; ">该状态先手必输</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">），所以这种情况，先手必败。</span></p><p style="margin-left:21.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">由于1)&nbsp;的c)情况可以到达2的c)情况，所以1的c)情况为先手必胜点。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">B&nbsp;.&nbsp;Double&nbsp;Queue</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3481&nbsp;<a href="http://poj.org/problem?id=3481">http://poj.org/problem?id=3481</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定一些数据(K,P)和一些询问，K为数据值，P为优先级，每次询问输出当前优先级最高或者最低的数据的K的值，询问完删除这个数据。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：平衡树。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">可以用SLT的set(内部也是平衡树的实现)水过去。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">C&nbsp;.&nbsp;</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'Times New Roman'; ">&#8216;</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">JBC</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'Times New Roman'; ">&#8217;</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3482&nbsp;<a href="http://poj.org/problem?id=3482">http://poj.org/problem?id=3482</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：进制转换，数字位可以是任何的可见ASCII码，求所有可能进制下的串转换成十进制后的和。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：模拟进制转换，模拟大数运算。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">D&nbsp;.&nbsp;</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">Loan&nbsp;Scheduling</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3483&nbsp;<a href="http://poj.org/problem?id=3483">http://poj.org/problem?id=3483</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定N(N&nbsp;&lt;=&nbsp;10000)个任务，每个任务是一个二元组(Pi,</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">&nbsp;Di</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)，表示如果在[0,&nbsp;Di]的某个时刻内完成则可以得到Pi的利润，每个时间点最多只能有L(L&nbsp;&lt;=&nbsp;100)个任务，求取一个任务子集来完成的的最大利润总和。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：贪心。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">初始化每个时间点的可用任务数为L，初始化任务利润和S。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">将所有任务按Pi从大到小排序，对于每个任务，从Di到0枚举它的完成时间t，如果t这个时间点还有可用任务，累加Pi到S，并且将t这个时间点的可用任务数减1，枚举完所有任务后S即为所求。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">E&nbsp;.&nbsp;Showstopper</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3484&nbsp;<a href="http://poj.org/problem?id=3484">http://poj.org/problem?id=3484</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定一些三元组(X,&nbsp;Y,&nbsp;Z)，一个三元组表示满足X&nbsp;+&nbsp;K*Z&nbsp;&lt;=&nbsp;Y&nbsp;(K&nbsp;=&nbsp;0,&nbsp;1,&nbsp;2,&nbsp;3&nbsp;...&nbsp;)&nbsp;的所有正整数&nbsp;X&nbsp;+&nbsp;K*Z出现了一次。对于多个三元组，保证所有数中至多只有一个数出现奇数次，求这个数以及它出现的次数。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：二分答案。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">对于出现奇数次的那个数T，那么如果小于T的所有数的和必定是偶数，大于等于T的所有数的和必定是奇数，利用这一点可以二分枚举这个T，然后利用所有小于等于T的数的个数的奇偶性进行二分判定。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">对于某个三元组(X,&nbsp;Y,&nbsp;Z)，小于等于T的个数分几种情况讨论：</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">1)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">当T&nbsp;&gt;=&nbsp;Y，个数为&nbsp;(Y-X)/Z&nbsp;+&nbsp;1;</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">2)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">当T&nbsp;&lt;&nbsp;X，个数为0;</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">3)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">当&nbsp;X&nbsp;&lt;=&nbsp;T&nbsp;&lt;&nbsp;Y，个数为&nbsp;(T-X)/Z&nbsp;+&nbsp;1;</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">每次枚举T，将所有区间的数相加判断奇偶性即可。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">F&nbsp;.&nbsp;Highway</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3485&nbsp;<a href="http://poj.org/problem?id=3485">http://poj.org/problem?id=3485</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：给定一条高速公路的长度L(范围为0到L)和N个村庄，要求在高速公路上建一些出口，使得每个村庄到高速公路至少有一个出口的距离不大于D，并且出口总数最少。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：贪心。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">计算出每个村庄到高速公路距离D范围内的左右区间[L</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">i</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">,&nbsp;R</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">i</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">]，对这些区间进行排序，排序规则为如果左端点一致则按照右端点递增排序，否则按照左端点递增排序。然后按左端点递增枚举每个区间（每个区间对应一个村庄），对于尚未有高速公路可达的村庄，在其右端点建立一个出口（贪心所在，因为是从左往右扫描，所以在右端点建出口肯定比左端点建更优），然后将它之后的左端点坐标小于这个出口的区间全部hash掉（因为那些村庄可以用这个出口，无须建立新的出口），直到所有区间枚举完毕，出口数也就得出了。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">G&nbsp;.&nbsp;Computers</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3486&nbsp;<a href="http://poj.org/problem?id=3486">http://poj.org/problem?id=3486</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：故事背景是每年都要更换电脑或者进行一次维修，如果换电脑需要c的花费，如果不换电脑，那么第y年到第z年(&nbsp;1&nbsp;&lt;=&nbsp;y&nbsp;&lt;=&nbsp;z&nbsp;&lt;=&nbsp;n)的总维修费用为m[y][z]，求经过n年的最小花费。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：动态规划。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">DP[i]表示经过i年的总开销，假设从第j年开始买了一台新的电脑，一直用到了第i年，那么前j年的总开销为DP[j]，从第j+1年到第i年的维修开销加上购买花费c，即DP[j]&nbsp;+&nbsp;m[j+1][i]&nbsp;+&nbsp;c，DP[i]就是这些开销中的最小值，即。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">DP[i]&nbsp;=&nbsp;min{&nbsp;DP[j]&nbsp;+&nbsp;m[j+1][i]&nbsp;+&nbsp;c,&nbsp;0&nbsp;&lt;=&nbsp;j&nbsp;&lt;&nbsp;i&nbsp;};</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">H&nbsp;.&nbsp;The&nbsp;Stable&nbsp;Marriage&nbsp;Problem</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3487&nbsp;<a href="http://poj.org/problem?id=3487">http://poj.org/problem?id=3487</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：n(n&nbsp;&lt;&nbsp;27)对男女，每个男人有对所有女人的好感度，每个女人也有对所有男人的好感度，A对B的好感度记为G(A,&nbsp;B),&nbsp;求找出一种稳定的婚配关系，使得对于任意一对夫妇X(M,&nbsp;W)，不存在&nbsp;G(X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">M</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">,&nbsp;Y</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">W</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)&nbsp;&gt;&nbsp;G(X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">M</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">,&nbsp;X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">W</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)&nbsp;并且&nbsp;G(X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">W</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">,&nbsp;Z</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">M</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)&nbsp;&gt;&nbsp;G(X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">W</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">,&nbsp;X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">M</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">)，并且要求男士优先考虑（即男方如果能找到好的一定不会更差的）。通俗的讲，就是X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">M</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">更加喜欢别人的老婆，X</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; vertical-align:sub; ">w</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">更加喜欢别人的老公，这样的婚姻是不稳定的，双方都有可能出现外遇。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：稳定婚姻经典算法。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">由于是男士最优，所以需要模拟男士求爱的方式。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">用L[i][j]表示i号男子喜欢的第j个女子的编号；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">用R[i][j]表示i号女子对j号男子的评分（越大评分越高，且对于确定的i肯定互不相同）；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">算法如下：</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">1)&nbsp;将所有的男子以及他们向多少个女人求过婚的信息入队，每次弹出一个男子M，找到他下一个要求婚的对象（求婚顺序按照对女生的好感度顺序进行）。</span></p><p style="margin-left:21.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">a)&nbsp;如果当前求婚对象W没有配偶，直接配对，记Match[&nbsp;W&nbsp;]&nbsp;=&nbsp;M;</span></p><p style="margin-left:21.0000pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">b)&nbsp;如果当前求婚对象有老公，即Match[&nbsp;W&nbsp;]，那么检查M&nbsp;和&nbsp;Match[&nbsp;W&nbsp;]在W的评分，如果M的评分大于W的老公，则迫使其改嫁，前夫入队，Match[&nbsp;W&nbsp;]&nbsp;=&nbsp;M；否则，该男子M继续入队；</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size:10.5000pt; font-family:'宋体'; ">2)&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">反复进行1)直到所有人都找到的对象。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">I&nbsp;.&nbsp;Arne&nbsp;Saknussemm</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 宋体;">PKU&nbsp;3488&nbsp;<a href="http://poj.org/problem?id=3488">http://poj.org/problem?id=3488</a></span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题意：简单字符串模拟。</span></p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">题解：根据题意做就行了。</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207161.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-06-01 00:03 <a href="http://www.cppblog.com/menjitianya/archive/2014/06/01/207161.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Greater New York Regional 2009 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/05/28/207124.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Wed, 28 May 2014 00:25:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/05/28/207124.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207124.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/05/28/207124.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207124.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207124.html</trackback:ping><description><![CDATA[<div style="text-align: center;"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/gnyork2009.png" width="796" height="184" alt="" /></div> <p><span style="color: #333333; background-color: white;"><strong>A.Nth Largest Value</strong><br /><strong>&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3781<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3781">http://poj.org/problem?id=3781</a></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">水题，求</span><span style="color:#333333;background:white">10</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">个数中第</span><span style="color:#333333;background:white">3</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">大的数。</span></p>  <p><strong>&nbsp;</strong></p>  <p><strong><span style="color:#333333;background:white">B.Equal Sum Partitions<br />&nbsp; &nbsp; &nbsp; &nbsp;</span></strong><span style="color: #333333; background-color: white;">PKU 3782<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3782">http://poj.org/problem?id=3782</a></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题意：给定一个</span><span style="color:#333333;background:white">M(M &lt;= 10000)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">个元素的序列，将它切割成</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">块，每块的和相等，求最大的</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">。</span></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题解：枚举。</span></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">首先，切成</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">块，每块和相等，那么这个和必定是</span><span style="color:#333333;background:white">M</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">个元素总和的一个因子，那么可以枚举第一个块的长度（</span><span style="color:#333333;background:white">M</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">种），判断当前块的和是否能被所有数的总和整除，如果可以，顺序判断可行性，看似复杂度是</span><span style="color:#333333;background:white">O(M^2)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，但是能否整除这个剪枝可以筛选掉绝大部分情况。</span></p>  <p>&nbsp;</p>  <p><strong><span style=" color:#333333;background:white">C.Balls<br />&nbsp; &nbsp; &nbsp; &nbsp;</span></strong><span style="color: #333333; background-color: white;">PKU 3783<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3783">http://poj.org/problem?id=3783</a></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题意：给定</span><span style="color:#333333;background:white">B (B &lt;= 50) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333; background:white">个一样的球，从</span><span style="color:#333333;background:white"> M (M &lt;= 1000) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">层楼上一个一个往下扔，存在某个楼层</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，使得低于它的楼层往下扔球，球不会碎，在第</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">层扔下去会碎。求最坏情况下，需要扔几次才能确定这个</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题解：动态规划。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">令</span><span style="color:#333333;background:white">DP[i][j]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">表示总楼层为</span><span style="color:#333333;background:white">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，持有</span><span style="color:#333333;background:white">j</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">个球时，最坏情况需要的次数；</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">那么如果从</span><span style="color:#333333;background:white">k ( 1 &lt;= k &lt;= i) </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">层进行扔球，有两种情况：</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">1) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">如果球不碎，则还需要进行</span><span style="color:#333333;background:white">DP[i-k][j]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">次测试（向更高的楼层进发）；</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">如果球碎，那么还可以进行的次数为</span><span style="color:#333333;background:white">DP[k-1][j-1] </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333; background:white">（损失了一个球）；</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">由于要考虑最坏情况，所以每次测试必须取</span><span style="color:#333333;background:white">(1) (2)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333; background:white">中的大者</span><span style=" color:#333333;background:white">+1</span><span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，每次选定一个楼层，使得这个楼层往下扔球的结果的最大值最小，也即状态转移方程为：</span></p>  <p style="text-indent:25.0pt"><span style="color:#333333;background:white">DP[i][j] = Min( DP[i][j],&nbsp; Max(DP[i-k][j], DP[k-1][j-1]) + 1 );</span></p>  <p style="text-indent:25.0pt"><span style="color:#333333;background:white">Pku</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">上有道和这题想法类似的题：</span><span style="color:#333333;background:white"><a href="http://poj.org/problem?id=1243">http://poj.org/problem?id=1243</a></span></p>  <p>&nbsp;</p>  <p><strong><span style="color:#333333;background:white">D.Running Median<br />&nbsp; &nbsp; &nbsp; &nbsp;</span></strong><span style="color: #333333; background-color: white;">PKU 3784<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3784">http://poj.org/problem?id=3784</a></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题意：一个长度为</span><span style="color:#333333;background:white">M(M &lt;= 9999)</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">的序列，每次奇数位的数读入的时候计算前面整个序列的中位数。</span></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题解：二分</span><span style="color:#333333;background:white"> + </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">树状数组。</span></p>  <p><span style=" color:#333333;background:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">由于数字是</span><span style="color:#333333;background:white">int32</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">范围，所以首先需要将所有数离散到下标，枚举每一个数字读入，将对应位的数字下标插入到树状数组中，每当读到奇数个的时候，利用树状数组的成端求和的性质，如果要找第</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">大的数，那么就二分一个答案，然后查询树状数组，如果求和大于等于</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，表示是一个候选解（因为要保证大于等于</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">的数最小，才是第</span><span style="color:#333333;background:white">K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">大的数），反复二分，直到找到最小的值</span><span style="color:#333333;background:white">V</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">满足</span><span style="color:#333333;background:white">sum(V) &gt;= K</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333; background:white">，时间复杂度</span><span style=" color:#333333;background:white">O(2 *M * log(M) )</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">。</span></p>  <p>&nbsp;</p>  <p><strong><span style=" color:#333333;background:white">E.The Next Permutation<br />&nbsp; &nbsp; &nbsp;&nbsp;</span></strong><span style="color: #333333; background-color: white;">PKU 3785<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3785">http://poj.org/problem?id=3785</a></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题意：给定一个可重复元素的排列</span><span style="color:#333333;background:white">A[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，求下一个排列。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题解：从后往前扫描，对于第</span><span style="color:#333333;background:white">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">个元素</span><span style="color:#333333;background:white">A[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，如果能够找到一个</span><span style="color:#333333;background:white">j</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，使得</span><span style="color:#333333;background:white">A[j] &gt; A[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">，并且满足</span><span style="color:#333333;background:white">A[j]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">是继第</span><span style="color:#333333;background:white">i</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">位之后最小的数，那么将</span><span style="color:#333333;background:white">A[i]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">和</span><span style="color:#333333;background:white">A[j]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">进行交换，然后将</span><span style="color:#333333;background:white">A[i+1]</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">到末尾的元素进行一次不降序排序，最后得到的串就是解。</span></p>  <p style="text-indent:25.0pt">&nbsp;</p>  <p><strong>F.Adjacent Bit Counts<br />&nbsp; &nbsp; &nbsp;&nbsp;</strong><span style="color: #333333; background-color: white;">PKU 3786<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3786">http://poj.org/problem?id=3786</a></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：求长度为</span>n<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的二进制整数中，相邻两个</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数有</span>k<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对（可重复使用）的整数个数。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：动态规划。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">令长度为</span>n<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，相邻</span>1<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数为</span>k<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的数的个数为</span>DP[n][k]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，其中以</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">结尾的为</span>DP[n][k][0]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，以</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">结尾的为</span>DP[n][k][1]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么</span> DP[n][k] = DP[n][k][0] + DP[n][k][1]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">并且有如下状态转移方程：</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">1) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">长度为</span>n-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的二进制数在末尾加上一个</span>0<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，相邻</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数不变，所以有：</span></p>  <p style="text-indent:25.0pt">DP[n][k][0] = DP[n-1][k][0] + DP[n-1][k][1];</p>  <p style="margin-left:0cm;text-indent:25.0pt;">2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">长度为</span>n-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的二进制数在末尾加上一个</span>1<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，相邻</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数取决于，第</span>n-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位是</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">还是</span>1<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，当第</span>n-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位是</span>1<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，相邻</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数</span>+1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；当第</span>n-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">位是</span>0<span style=" font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，相邻</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的对数不变，所以有：</span></p>  <p style="text-indent:25.0pt">DP[n][k][1] = DP[n-1][k][0] + DP[n-1][k-1][1];</p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">并且初始状态下</span>DP[0][0][0] = 1,&nbsp; DP[0][0][1] = 0</p>  <p style="text-indent:25.0pt">&nbsp;</p>  <p><strong>G.Convex Hull of Lattice Points</strong></p>  <p style="text-indent:25.0pt"><span style="text-indent: 0px; color: #333333; background-color: white;">PKU 3787<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3787" style="text-indent: 0px;">http://poj.org/problem?id=3787</a><br /><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&nbsp; &nbsp; &nbsp;题意：凸包。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span><span style=" color:#333333;background:white">Graham</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">扫描法求解即可。</span></p>  <p><strong>&nbsp;</strong></p>  <p>&nbsp;</p>  <p><strong><span style=" color:#333333;background:white">H.Interior Points of Lattice Polygons</span></strong></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white"><span style="font-family: verdana, 'courier new'; text-indent: 0px;">PKU 3788<strong>&nbsp;</strong></span><a href="http://poj.org/problem?id=3788" style="font-family: verdana, 'courier new'; text-indent: 0px;">http://poj.org/problem?id=3788</a><br />&nbsp; &nbsp; &nbsp;题意：给定一个凸多边形，求它内部所有的水平线段。</span></p>  <p style="text-indent:25.0pt"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">题解：从多边形第一个点的</span><span style="color:#333333;background:white">y</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">坐标开始，递减枚举水平线段的</span><span style="color:#333333;background:white">y</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">坐标，分别和多边形的</span><span style="color:#333333;background:white">n</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">条边进行求交点；</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">1) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">如果水平线段和多边形某条边共线，说明正好到了多边形的边缘，无须往下枚举，跳出循环。</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">如果水平线段和多边形小于一个交点，那么当</span><span style="color:#333333;background:white">y</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">轴再次减小的时候，必然没有交点，也无须继续枚举。</span></p>  <p style="margin-left:0cm;text-indent:25.0pt;">3) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">否则，将左端点坐标取上整</span><span style="color:#333333;background:white">x1</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，右端点取下整</span><span style="color:#333333;background:white">x2</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:#333333;background:white">，如果</span><span style="color:#333333;background:white">x1 &lt;= x2 </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;; color:#333333;background:white">将它插入到解集中。</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207124.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-05-28 08:25 <a href="http://www.cppblog.com/menjitianya/archive/2014/05/28/207124.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mid-Central USA 2009 解题报告 </title><link>http://www.cppblog.com/menjitianya/archive/2014/05/25/207098.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sun, 25 May 2014 12:33:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/05/25/207098.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207098.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/05/25/207098.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207098.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207098.html</trackback:ping><description><![CDATA[<p>&nbsp;</p><div style="text-align: center;"><strong><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/midc2009.png" width="814" height="204" alt="" /></strong></div><strong>A. Up and Down<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3912<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3912">http://poj.org/problem?id=3912</a><p>&nbsp;</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一个一维的棋盘，范围为</span>[0, W] (W &lt;= 1000,000,000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，某两个点之间有梯子或虫洞，梯子的下端点到上端点以及虫洞的上端点到下端点花费的步数为</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，其它任意点之间的距离通过跳跃来计算，最多每次跳跃不超过</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">格（</span>S&lt;= 6<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">），跳跃的过程中如果跳到梯子的下端点或者虫洞的上端点就会被直接传送到另一端，并且每次跳跃只能从小的点跳到大的点（虫洞是个例外），求从</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">到</span>W<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最短距离。</span></p>  <p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/1.png" border="0" alt="" width="373" height="323" /></p>  <p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>A-1</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">离散化</span> + SPFA<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">将所有梯子和虫洞的两端点、</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>W<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">以及他们往前往后</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">步以内的数全部记录下来，梯子和虫洞有</span>P<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>P &lt;= 40<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）个，加上起点终点，总共</span>82<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点，算上前后各六步，总共</span>82 * 13 = 1066<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点，然后将这些点排序后离散化，最后就是要构建一个网络图，通过网络求</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">到</span>W<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的最短路，最短路可以用</span>SPFA<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">求解。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">谈谈建图的过程，对于任意两个点，他们之间必定可以连一条边，然后有一个步数表示边的权值（这里的步数也可能是正无穷，也即永远都无法到达）。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于任意两个点</span>(u, v)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，他们的步数</span>w(u, v)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（边权）我们做如下讨论（这里的</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>v<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">是离散化后的点）：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果</span>u<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">是梯子的下端点，</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是梯子的上端点</span> <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">或者</span> u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是虫洞的上端点，</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是虫洞的下端点，那么</span>w(u, v) = 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，否则进入</span>2)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的判断</span>;</p>  <p style="text-indent:21.0pt">2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果</span>u<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的编号大于</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span>w(u, v) = inf<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，表示永远不可达，因为某次跳跃只能从小的点跳到大的点，否则进入</span>3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）的判断</span>;</p>  <p style="text-indent:21.0pt">3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果</span>u<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的实际位置和</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的实际位置差值小于等于</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则</span>w(u, v) = 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p style="text-indent:21.0pt">4<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）检查</span>u<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">之间是否有虫洞的上端点或者梯子的下端点，之后将这两种点称为</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点</span></p>  <p style="margin-left:21.0pt;text-indent:21.0pt">a<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果有，判断他们是否连续，</span></p>  <p style="margin-left:42.0pt;text-indent:21.0pt">i) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如果不连续</span>w(u, v) = inf<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（这一步这么做是为了简单化，试想一下，如果</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点不是全部连续，说明</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">可以先跳到他们中间的某个非</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的点，然后再跳到</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点，这一步是通过</span>SPFA<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">来实现迭代的，建边的时候可以不考虑）。</span></p>  <p style="margin-left:42.0pt;text-indent:21.0pt">ii<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果连续，判断他们连续的格子的数目，如果大于等于</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">说明这个连续的块必定跳不过去，所以</span>w(u, v) = inf<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，否则可以先跳到最先的一个</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点的前面一个点，然后经过一步</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">跳跃将这个连续块跳过去，再跳到</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果没有</span>X<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">点，那么直接从</span>u<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点跳到</span>v<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这里我们需要计算从</span>a<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">点跳到</span>b<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">点不考虑虫洞和梯子的最短距离，可以贪心的跳，每次往大的跳，直到剩余格子不足</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">格，即</span>(b-a + S-1) / S <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>b-a<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对</span>S<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">求商的上整）。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">边建立完成就可以利用广搜求解</span>0-W<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最短路了。</span></p>  <p>&nbsp;</p>  <p><strong>B. Gnome Sequencing<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3913<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3913">http://poj.org/problem?id=3913</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">水题，判断三个数是全递增还是全递减还是无序。</span></p>  <p>&nbsp;</p>  <p><strong>C. DuLL<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3914<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3914">http://poj.org/problem?id=3914</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一些</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件和它占用的内存空间，以及一些可执行程序占用的内存空间和它依赖的</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件，程序以进程为单位，两个相同的程序可能有不同的进程，进行一些下列的操作：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）某个程序运行的时候需要它依赖的</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件也加载到内存中，多个程序可以共用一个</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）某个程序退出的时候，如果它所依赖的</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件没有其它程序使用，需要释放这段内存空间；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">给定一系列的运行进程，求某个时刻的最大内存占用。</span></p>  <p>&nbsp;</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span>HASH<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的简单应用。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">初始化内存占用</span>V = 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于给定的输入进程：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果是新运行的进程，将</span>V<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">加上这个进程的内存占用，并将它所有依赖的</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件检查一遍，如果引用计数为</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则将对应</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件的内存累加到</span>V<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">上，引用计数</span>+1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果是退出进程，将</span>V<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">减去这个进程的内存占用，并将它所有依赖的</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件检查一遍，如果引用计数为</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，则用</span>V<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">减去对应</span>dll<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件的占用量，引用计数</span>-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每次操作记录最大的</span>V<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">就是最后的答案。</span></p>  <p><strong>D. Black Vienna<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3915<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3915">http://poj.org/problem?id=3915</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：三个人，每个人五张牌，互相不知道对方的牌，还有额外的三张牌放在一边（所有牌编号为</span>A - R<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）。每一轮，由</span> (i-1)%3+1 (1 &lt;= i &lt;= 15) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">号玩家进行发问，问</span>Ai &nbsp;(1 &lt;= Ai &lt;= 3) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">号玩家</span>XYZ<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">（代表任意三个牌号）三张牌中有多少张在他手上，然后他回答</span>Bi (0 &lt;= Bi &lt;= 3)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，问经过多少轮之后有某位玩家知道</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">额外</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的那三张牌是什么。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span>dfs<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">枚举</span> + <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">剪枝。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">首先枚举到某个询问</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时候玩家</span>j<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">能够猜出的那三张牌的情况，如果枚举完所有情况最后确定只有一个解满足条件的时候，那个询问的编号</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">就是答案了。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">类似</span>IDA*<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">的思路，先枚举询问最大深度，如果到达那个询问不能确定额外的那三张牌或者有很多种情况，那么说明还需要更多的询问，迭代深度继续枚举。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于某个询问</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，找到询问的那三张牌中已经是</span>Ai<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">号选手的数量</span>ansCnt<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，以及尚未确定牌的归属的牌的数量</span>xCnt<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果已经确定位置的牌数量</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">大于</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">实际他回答的数量（</span>ansCnt &nbsp;&gt; &nbsp;Bi<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）或者</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">尚未确定位置的牌数量</span> + <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">已经确定为他的牌数量</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">小于</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">实际他回答的数量（</span>ansCnt + xCnt &lt; Bi<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）都是不合理的情况，剪枝，不用继续往下搜索；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">否则，将</span>(Bi - ansCnt)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">张牌分配给</span>Ai<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span>(xCnt - (Bi - ansCnt))<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">张牌分配给其它两位玩家以及额外的那一堆，这里需要用到嵌套</span>dfs<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">枚举，枚举完后进入下一个询问的枚举，每次询问的时候可以有几个剪枝：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）如果某个阶段某个人的牌数超过</span>5<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">张；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）枚举的解的数量超过</span>2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于一次完全枚举，枚举完所有询问后还是有无法确定三张额外的牌的情况；</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>  <p><strong>E. Duplicate Removal<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3916<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3916">http://poj.org/problem?id=3916</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">水题，对输入的元素进行连续判重输出。</span></p>  <p>&nbsp;</p>  <p><strong>F. Rock, Paper, Scissors<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3917<strong></strong><a href="http://poj.org/problem?id=3917"><strong>&nbsp;</strong>http://poj.org/problem?id=3917</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">水题，剪刀石头布！</span>O_o<br /></p>  <p>&nbsp;</p>  <p><strong><span style="color:#C00000">G. A to Z Numerals<br />&nbsp; &nbsp; &nbsp; &nbsp;</span></strong>PKU 3918<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3918">http://poj.org/problem?id=3918</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：复杂模拟。（没做出来，</span>#-_-# <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">样例的</span>98<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">是怎么出来的呀！！！）</span></p>  <p>&nbsp;</p>  <p><strong>H. Cell Towers&nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3919<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3919">http://poj.org/problem?id=3919</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给出一条曲折的连续线段，曲线从起点开始每经过一个长度为</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的单位会放置一个守卫</span>K<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，在曲线以外的某些地方会有</span>T(T &lt;= 10)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个信号发射器，用</span>A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>B<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>C...<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">来表示，每个信号发射器有它的信号强度</span>Pi<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，每个信号发射器到守卫</span>K<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的距离如果是</span>D<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，那么它能接收到的信号值为</span>Pi / D<sup>2</sup><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最近整数，并且对于守卫</span>K<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，它只会接收最大的信号值，如果有多个发射器对于</span>K<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的信号值相同，那么选择字典序最小的发射器。需要求是一些守卫集合，这些守卫分别和它的前一个守卫所接收的信号发射器不一样。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：计算几何、向量的简单应用。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于每条射线，终点减去起点，再单位化后就可以得到这条射线的单位向量，利用这一点可以很简单的将所有守卫的坐标求出来，然后对于每个守卫判断接收的是哪个发射器，判断和之前那个守卫是否相同即可。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">需要注意的是最后一个守卫，当和上一个守卫距离小于</span>0.5<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的时候不会建立新的守卫。</span></p>  <p>&nbsp;</p>  <p><strong>I. RIPOFF<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 3920<strong>&nbsp;</strong><a href="http://poj.org/problem?id=3920">http://poj.org/problem?id=3920</a></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>N(N &lt;= 200)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数的一维数组</span>A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，取不大于</span>T+2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数，每相邻两个数之间的下标不大于</span>S<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，问最大的取值总和</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">第</span>0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个和第</span>N+1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数必取，且权值为</span>0)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：动态规划。</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DP[i][j] <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示第</span>j<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数取</span> A[i]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的最大值，那么状态转移方程可以表示为：</span></p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DP[i][j] = max{ DP[k][j-1] + A[i], &nbsp;i &gt; k &gt; i-1-S &amp;&amp; k &gt;= 0};</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">特殊的，</span>DP[0][0] = 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，其他的</span>DP[i][j] <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">都初始化为</span>INF;</p>  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">最后计算出的</span>DP[N+1][i]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中的最大值就是答案了。</span></p>  <p>&nbsp; &nbsp; &nbsp; &nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/207098.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-05-25 20:33 <a href="http://www.cppblog.com/menjitianya/archive/2014/05/25/207098.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>South America 2002 解题报告</title><link>http://www.cppblog.com/menjitianya/archive/2014/05/18/207005.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sun, 18 May 2014 09:10:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2014/05/18/207005.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/207005.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2014/05/18/207005.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/207005.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/207005.html</trackback:ping><description><![CDATA[<p>&nbsp;</p><div style="text-align: center;"><strong><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/soutame2009.png" width="761" height="185" alt="" /></strong></div><strong>A</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>Grandpa's Rubik Cube<br /></strong>&nbsp; &nbsp; &nbsp; &nbsp;PKU 1290<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1290">http://poj.org/problem?id=1290</a><br /><p>&nbsp;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一个</span>3X3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的六面魔方（每个面有</span>3X3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个块），求经过某些旋转之后能否使得所有面的颜色都相同，旋转包括对某个面进行顺时针和逆时针旋转（共</span>12<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">种情况）。</span></p><p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/wght.png" border="0" alt="" width="633" height="215" /></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>A-1</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如图</span>1<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">，输入数据为左图的形式，右图给对应的面编号，箭头方向为顺时针旋转方向。</span></p><p>+A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示对</span>A<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这个面进行一次顺时针旋转，</span>-B<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示对</span>B<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">这个面进行一次逆时针旋转。问经过一定的</span>+A/-B<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">操作之后能否使得所有面的</span>3X3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个字母都相同。</span></p><p>&nbsp;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：模拟题</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">做法很多，这里介绍一种比较容易理解的状态记录方式，考虑某次旋转，一定是旋转某个面，然后对邻接的四个面的某条边进行顺次平移。如图</span>A-2, 2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">号面的旋转带动的是</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>5<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、</span>6<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">四个面。</span></p><p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/acad.png" border="0" alt="" width="260" height="209" /></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>A-2</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">我用一个数组</span>rotate_n<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">来记录某个面旋转的时候带动的面的编号集合（编号为</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的数据为占位符），那么有：</span></p><p>int rotate_n [7][4] = {</p><p>&nbsp;&nbsp;&nbsp; {0, 0, 0, 0}, {4, 5, 2, 6}, {1, 5, 3, 6}, {2, 5, 4, 6}, {3, 5, 1, 6}, {1, 4, 3, 2}, {1, 2, 3, 4}</p><p>};</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">光记录带动的面是哪些还不够，还需要知道带动面的对应边，对于一个魔方的一个面，我们编号如下：</span></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>0,0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>0,1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>0,2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>1,0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>1,1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>1,2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>2,0<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>2,1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）（</span>2,2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分别用</span>1<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">到</span>4<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">来代表一个面的四条边（注意，有方向）：</span></p><p align="center" style="text-align:center">1 (0,2) - (0,0)</p><p align="center" style="text-align:center">2 (2,2) - (0,2)</p><p align="center" style="text-align:center">3 (2,0) - (2,2)</p><p align="center" style="text-align:center">4 (0,0) - (2,0)</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">那么同样用</span>rotate_p<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">来记录某个面旋转的时候带动的面对应的边，则有：</span></p><p>int rotate_p[7][4] = {</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {0, 0, 0, 0}, {2, 4, 4, 4}, {2, 3, 4, 1}, {2, 2, 4, 2}, {2, 1, 4, 3}, {1, 1, 1, 1}, {3, 3, 3, 3},</p><p>};</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这样一来，我们只需要考虑一个面的旋转，然后套用对应的数据即可，还有一个比较巧妙的是，逆时针旋转不需要特殊处理，直接将顺时针旋转执行三次即可。</span></p><p><strong>B</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>This Sentence is False<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1291<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1291">http://poj.org/problem?id=1291</a></p><p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定一些句子形如&#8220;</span>Sentence X is true/false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#8221;的句子，</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示第几个句子，问所有的情况是否合法，如果合法，输出最大的可能为真的句子。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：</span>2-sat<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每个句子抽象成两个结点，为真的时候为</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，为假的时候为</span>X '<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于第</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个句子，如果是</span> Sentence Y is true<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">则这个句子为真的时候，</span> X -&gt;Y<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">连边；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">当这个句子为假的时候，</span>X ' -&gt; Y '<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">连边；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对于第</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个句子，如果是</span> Sentence Y is false<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">则这个句子为真的时候，</span> X -&gt;Y '<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">连边；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">当这个句子为假的时候，</span>X ' -&gt; Y<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">连边；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">然后求一次强连通，如果最后有某个点</span>X<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>X ' <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">在同一个连通图中，说明逻辑错误，说明必然存在不合法的情况，否则对于每个连通分量，求出为真的点的个数和为假的点的个数，然后将他们之中的大者累加，最后答案除</span>2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">就是最大的可能为真的句子（除</span>2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的原因是因为真假是对称的）。</span></p><p><strong>C</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>Will Indiana Jones Get There?<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1292<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1292">http://poj.org/problem?id=1292</a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：营救公主，营救路线要么绕着墙走，要么走两面墙的最短距离（这种情况下需要在两面墙之间搭一块木板，并且可以反复使用）。问营救过程中木板的最短长度。</span></p><p align="center" style="text-align:center"><strong><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/adasd.png" border="0" alt="" width="378" height="215" /></strong></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>C-1</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：线段距离</span> + <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">二分答案</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">因为木板可以反复使用，所以我们可以假设如果木板越长，能够营救公主的概率就越大，反之则越小，所以问题就是求满足两点可达的最小木板长度，可以二分枚举这个长度</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，如果两面墙的最短距离大于这个</span>T<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，表明两面墙不可达，将墙抽象成点，两面墙之间的最短距离可以通过线段和线段的最短距离预处理出来，然后每次二分答案后通过一次搜索就可以找出起点和终点是否可达，复杂度为</span>O<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>n^2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）即计算两线段距离时候的复杂度。</span></p><p><strong>&nbsp;</strong></p><p><strong>D.</strong> <strong>Duty Free Shop<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1293<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1293">http://poj.org/problem?id=1293</a></p><p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>M(M &lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个白巧克力和</span>L(L&lt;= 1000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个黑巧克力，然后给定</span>N(N &lt;= M + L)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个容量为</span>Ci<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的盒子，问能否找到一种方案，使得某些盒子放满白巧克力，剩下的盒子放满黑巧克力。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：背包问题。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">由于需要将每个盒子都放满，于是可以利用一维背包的求法将</span>Ci<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的所有小于等于</span>M<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的可行组合求出来，找到最大的</span>M ' &lt;= M<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，并且</span>M ' <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">能够通过某种方式被组合出来，那么所有盒子的容量</span>Sum <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">减去</span> M ' <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的差小于等于</span>L<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的话，必定能将剩下的盒子填满黑巧克力，否则无解。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这题需要记录前驱，并且注意</span>M = 0 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">以及</span> L = 0 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的情况（主要是在输入的时候判断退出条件，</span>M+L==0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">退出而并非</span> (M&amp;&amp;L) == 0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）。</span></p><p>&nbsp;</p><p><strong>E</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>Not Too Convex Hull<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1294<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1294">http://poj.org/problem?id=1294</a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定</span>N(N&lt;=101)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点（没有三点共线的情况），要求用</span>B(B&lt;=50)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">根皮条将这</span>N<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个点圈成</span>B<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个部分，每个部分为一个凸多边形，并且所有凸多边形公用一个点（这个点会给出），求众多方案中满足所有多边形面积和最小的方案。图</span>E-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示用两根皮条圈住</span>19<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点的情况（原点共用了两次）。</span></p><p align="center" style="text-align:center"><img src="http://www.cppblog.com/images/cppblog_com/menjitianya/asdasdsd.png" border="0" alt="" width="323" height="230" /></p><p align="center" style="text-align:center"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">图</span>E-1</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：环形动态规划。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">首先将所有点按照给定的原点进行极坐标排序，那么第</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点到第</span>N<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点必定是按照极坐标严格逆时针排布的（因为没有三点共线），用</span>DP[i][b]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示第</span>i<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个点到第</span>N<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点经过</span>b<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">次分割后分割完的凸多边形的面积总和最小值，那么：</span></p><p>DP[i][b] =min{ area[i][k] +DP[k+1][b-1]&nbsp;&nbsp; (i &lt; k &lt; N) }; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">特殊的，</span>DP[0][0] = 0;</p><p>&nbsp;&nbsp;&nbsp;&nbsp; area[i][j] <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示极坐标在第</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点和第</span>j<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个点之间的所有点</span>(<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">包含这两个点</span>)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">加上原点组成的凸包的面积，可以通过初始化预处理出来；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">由于点是极坐标排列的，也就是第一个点不一定是凸包边上的点（有可能是第</span>N-1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个点到第</span>2<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个点组成的凸包达到整体最优），所以需要做</span>N<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">次</span>DP<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，可以将所有点复制一份，枚举起点</span>i ( 1 &lt;= i &lt;= N)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，终点即</span>i+N, <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">然后分别做一次</span>DP<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">取最小值。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时间复杂度</span>O(N^2 * B)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p><p><strong>&nbsp;</strong></p><p><strong>F</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>I hate SPAM, but some people love it<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1295<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1295">http://poj.org/problem?id=1295</a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：</span>N(N&lt;=20)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个人互发邮件，某个人收到邮件后一定会回复给他所有的好友，回复的数量决定他的称号，按顺序给定首先发起邮件的人，要求按顺序输出所有人得到的称号。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：深搜枚举。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数据量很小，对于给定的初始者作为起点进行遍历，每个人只访问一次，访问到的时候根据他的朋友数量计算他的称号即可。</span></p><p><strong>&nbsp;</strong></p><p><strong>G</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>Noise Effect<br />&nbsp; &nbsp; &nbsp; &nbsp;</strong>PKU 1296<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1296">http://poj.org/problem?id=1296</a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：给定两个正方形矩阵，求他们的最大相似度，相似度的定义为矩阵元素对应位差值小于等于</span>100<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的个数占所有矩阵元素的百分比（可以进行旋转和翻转）。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：模拟题。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每个矩阵可以进行四次旋转，每次旋转可以有水平翻转、竖直翻转、水平竖直翻转、保持原样四种状态，一共十六种情况（实际小于</span>16<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">种，因为有些状态经过翻转和旋转之后是一样的），对每种情况模拟计算相似度取最大值即可。</span></p><p>&nbsp;</p><p><strong>H</strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">．</span>Supermarket<br />&nbsp; &nbsp; &nbsp;&nbsp;</strong><strong>&nbsp;</strong>PKU 1297<strong>&nbsp;</strong><a href="http://poj.org/problem?id=1297">http://poj.org/problem?id=1297</a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题意：约翰需要买</span>M(M&lt;=100)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">件物品，超级市场上的物品都排成一排，一共</span>N(N&lt;=100000)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">件物品，他从左向右开始选物品，但是为了不麻烦，不想走回头路，而且第</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个物品买的条件是，前</span>i<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">－</span>1<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个物品必须已经买了，但是每个物品在超级市场中的价格不一样，即使同一个物品也有不同的价格，为了花费最少，他想要一个方案使得：</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">按顺序购买</span>M<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个物品；</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">总价值最少，并输出这个最小值，如果方案不存在，输出</span>Impossible<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p><p>&nbsp;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">题解：动态规划。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DP[i][j]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示第</span>i<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个购买列表中的物品和第</span>j<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个市场中的物品匹配时的最小消费（</span>1&lt;=i&lt;=M,1&lt;=j&lt;=N<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span>;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Min[i][j]<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表示</span>min{ DP [i][x]&nbsp; x&lt;=j };</p><p>&nbsp;&nbsp;&nbsp; a)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">当第</span>i<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">个物品和第</span>j<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个市场物品编号相同时，</span>DP[i][j] = Min[i-1][j-1] +cost[j];</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">否则</span>DP[i][j] = inf; <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">计算</span>DP<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">数组同时更新</span>Min<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数组，由于每次的状态最多和上一行有关，所以在进行状态转移的时候可以采用滚动数组。时间复杂度</span>O(NM)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p><p>                                                                                                                                                                        </p><p><strong>&nbsp;</strong></p><img src ="http://www.cppblog.com/menjitianya/aggbug/207005.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2014-05-18 17:10 <a href="http://www.cppblog.com/menjitianya/archive/2014/05/18/207005.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pygame 游戏 英雄梦II【资料片】1  利剑无痕[v1.00]</title><link>http://www.cppblog.com/menjitianya/archive/2011/06/24/149391.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Fri, 24 Jun 2011 08:18:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/06/24/149391.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/149391.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/06/24/149391.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/149391.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/149391.html</trackback:ping><description><![CDATA[<p>【开发信息】<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;本游戏是采用Python的Pygame包开发而成，游戏的模式是射击类型，同时添加了RPG游戏特有的情节模式。<br /><br />【版本信息】<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v1.00<br /><br />【游戏简介】</p>
<p>&nbsp;&nbsp;&nbsp; 游戏的主要操作是键盘，但是在确认的时候也可以采用鼠标，鼠标还可以进行人物菜单栏<br />的Tip的查看，主角主要有生命、魔法、灵魂、攻击力、防御力、速度等几项属性。<br />&nbsp;&nbsp;&nbsp; 生命值&nbsp;&nbsp;&nbsp; 传说中的血，中国古代角色扮演游戏里大多将它称为&#8220;精&#8221;。<br />&nbsp;&nbsp;&nbsp; 查克拉&nbsp;&nbsp;&nbsp; 中国古代游戏中所谓的内力，小时候智力卡游戏中的MP，决定你进行攻击时候同时释放的武器数目。<br />&nbsp;&nbsp;&nbsp; 灵魂&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 每次生命值达到负值的时候可以通过释放一个灵魂来将血补满。&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; 攻击力&nbsp;&nbsp;&nbsp; 主角自身攻击力和当前武器攻击力的总和，影响对敌人的伤害值。<br />&nbsp;&nbsp;&nbsp; 防御力&nbsp;&nbsp;&nbsp; 主角的自身防御，影响主角受到攻击时的伤害值。<br />&nbsp;&nbsp;&nbsp; 速度&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 决定主角的移动速度和闪避率。<br />&nbsp;&nbsp;&nbsp; 必杀技&nbsp;&nbsp;&nbsp; 可以作用于整个游戏世界的无敌必杀技，可以理解为&#8220;大招&#8221;。<br />&nbsp;&nbsp;&nbsp; 得分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 每打到敌人一次可记一分，打死敌人记三分。当得分积满2000的时候可以换赎一个灵魂。<br /><br />【游戏操作】<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;方向键&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;控制人物行走<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;左Ctrl键&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 发射子弹 + 确认操作<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 空格键&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;释放大招（必杀技）<br /><br />【几点说明】<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;本游戏部分资源取自网络，部分由作者原创，所以请勿将其用于商业用途，否则后果自负。<br /><br />【试玩链接】<br /><a href="http://code.google.com/p/sguzty/downloads/list">http://code.google.com/p/sguzty/downloads/list</a><br /><br /><span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"><span style="line-height: 21px; font-family: Tahoma, Verdana, STHeiTi, simsun, sans-serif; color: rgb(51,51,51); font-size: 14px" class="Apple-style-span"> </p>
<p style="padding-bottom: 0px; margin: 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; padding-top: 0px">【联系作者】</p>
<p style="padding-bottom: 0px; margin: 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; padding-top: 0px">博客:www.cppblog.com/menjitianya</p>
<p style="padding-bottom: 0px; margin: 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; padding-top: 0px">&nbsp;邮箱:menjitianya2007@163.com</p>
<p style="padding-bottom: 0px; margin: 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; padding-top: 0px">&nbsp;QQ:277055227 &nbsp;周天涯 （英雄哪里出来）</p>
<p></span></span><br />【部分截图】<br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/menjitianya/0.png" width="640" longdesc="" height="480" /><br /><br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/menjitianya/1.png" width="640" longdesc="" height="480" /><br /><br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/menjitianya/3.png" width="640" longdesc="" height="480" /><br /><br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/menjitianya/6.png" width="640" longdesc="" height="480" /><br /><br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/menjitianya/7.png" width="640" longdesc="" height="480" /><br /><br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/menjitianya/5.png" width="640" longdesc="" height="480" /><br /><br /><br /><br /></p><img src ="http://www.cppblog.com/menjitianya/aggbug/149391.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-06-24 16:18 <a href="http://www.cppblog.com/menjitianya/archive/2011/06/24/149391.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C语言 控制台下 俄罗斯方块（续）- v1.01</title><link>http://www.cppblog.com/menjitianya/archive/2011/05/27/147358.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Fri, 27 May 2011 05:37:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/05/27/147358.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/147358.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/05/27/147358.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/147358.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/147358.html</trackback:ping><description><![CDATA[<p>Tetrix v1.01 版本下载地址：<br /><a href="http://code.google.com/p/sguzty/downloads/detail?name=Tetrix%20v1.01%20Release.rar&amp;can=2&amp;q">http://code.google.com/p/sguzty/downloads/detail?name=Tetrix%20v1.01%20Release.rar&amp;can=2&amp;q</a>=<br /><br /></p>
<p>Bug 修正<br />1.最大的bug是方块掉落的时候会将镂空的格子填满，修改之。<br />2."方块"旋转的时候不应该有任何效果，先前的版本会改变位置。<br />3.先前版本长条的旋转比较难看，这次略微好看一点。<br />4.修改了之前Life和Speed的显示问题。<br /><br /></p>
<p>功能 新增<br />1.添加了背景音乐和音效。<br />2.征询网友意见添加了随机种子，每次打开后都会有不同的开局。<br /><br /></p>
<p>背景音乐是 智冠电子 的 单机游戏 &lt;天龙八部&gt; 中 某个场景的背景音乐。<br />以此怀念我们儿时的单机游戏时代。</p>
<p><br />并且多谢众多网友们提的意见,你们的支持是我们最大的动力。</p>
<p><br />以下是其中一种在游戏中添加背景音乐的方法，拿出来分享以下，如果直接采用sndPlaySound是不能达到混音效果的，采用以下方法可以播放背景音乐，然后用sndPlaySound在播放音效，就可以达到混音效果。<br /></p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img id="Codehighlighter1_18_43_Open_Image" onclick="this.style.display='none'; Codehighlighter1_18_43_Open_Text.style.display='none'; Codehighlighter1_18_43_Closed_Image.style.display='inline'; Codehighlighter1_18_43_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_18_43_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_18_43_Closed_Text.style.display='none'; Codehighlighter1_18_43_Open_Image.style.display='inline'; Codehighlighter1_18_43_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;BeginMusic()&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_18_43_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_18_43_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;CoInitialize(&nbsp;NULL&nbsp;);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img id="Codehighlighter1_62_195_Open_Image" onclick="this.style.display='none'; Codehighlighter1_62_195_Open_Text.style.display='none'; Codehighlighter1_62_195_Closed_Image.style.display='inline'; Codehighlighter1_62_195_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_62_195_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_62_195_Closed_Text.style.display='none'; Codehighlighter1_62_195_Open_Image.style.display='inline'; Codehighlighter1_62_195_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;mp3Player&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_62_195_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_62_195_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;IGraphBuilder</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pGBuilder;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;IMediaControl</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pMControl;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;IMediaPosition</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pMPos;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;load(</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">filename);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;play();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img id="Codehighlighter1_236_774_Open_Image" onclick="this.style.display='none'; Codehighlighter1_236_774_Open_Text.style.display='none'; Codehighlighter1_236_774_Closed_Image.style.display='inline'; Codehighlighter1_236_774_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_236_774_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_236_774_Closed_Text.style.display='none'; Codehighlighter1_236_774_Open_Image.style.display='inline'; Codehighlighter1_236_774_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;mp3Player::load(</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">filename)&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_236_774_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_236_774_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;CoCreateInstance(CLSID_FilterGraph,&nbsp;NULL,CLSCTX_INPROC,&nbsp;IID_IGraphBuilder,&nbsp;(</span><span style="color: #0000ff">void</span><span style="color: #000000">**</span><span style="color: #000000">)</span><span style="color: #000000">&amp;</span><span style="color: #000000">pGBuilder);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pGBuilder</span><span style="color: #000000">-&gt;</span><span style="color: #000000">QueryInterface(IID_IMediaControl,&nbsp;(</span><span style="color: #0000ff">void</span><span style="color: #000000">**</span><span style="color: #000000">)</span><span style="color: #000000">&amp;</span><span style="color: #000000">pMControl);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pGBuilder</span><span style="color: #000000">-&gt;</span><span style="color: #000000">QueryInterface(IID_IMediaPosition,&nbsp;(</span><span style="color: #0000ff">void</span><span style="color: #000000">**</span><span style="color: #000000">)</span><span style="color: #000000">&amp;</span><span style="color: #000000">pMPos);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;strSoundPath[&nbsp;MAX_PATH&nbsp;];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;WCHAR&nbsp;wstrSoundPath[&nbsp;MAX_PATH&nbsp;];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;GetCurrentDirectory(MAX_PATH,&nbsp;strSoundPath);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;strcat(&nbsp;strSoundPath,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">\\</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;strcat(&nbsp;strSoundPath,&nbsp;filename&nbsp;);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;MultiByteToWideChar(CP_ACP,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;strSoundPath,&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;wstrSoundPath,&nbsp;MAX_PATH&nbsp;);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pGBuilder</span><span style="color: #000000">-&gt;</span><span style="color: #000000">RenderFile(wstrSoundPath,&nbsp;NULL);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span></div>
<p>&nbsp;</p><img src ="http://www.cppblog.com/menjitianya/aggbug/147358.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-05-27 13:37 <a href="http://www.cppblog.com/menjitianya/archive/2011/05/27/147358.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C语言 控制台下 俄罗斯方块（附源码）</title><link>http://www.cppblog.com/menjitianya/archive/2011/05/26/147205.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Thu, 26 May 2011 05:40:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/05/26/147205.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/147205.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/05/26/147205.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/147205.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/147205.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;&nbsp;&nbsp; 昨天看到百度之星的趣味赛的帖子，很多代码挺有意思的，于是想在控制台下写个简洁点的小游戏，想想还是写个最经典的游戏------俄罗斯方块 吧。睡觉的时候构思了下大致的情况，今天早起开始写，遇到最大的困难是键盘按键的问题，本来想开一个线程，然后让系统读getch()，但是getch和ReadConsoleInput函数一样，是同步的，没有输入的状态下会...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2011/05/26/147205.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/147205.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-05-26 13:40 <a href="http://www.cppblog.com/menjitianya/archive/2011/05/26/147205.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pygame游戏开发 之五</title><link>http://www.cppblog.com/menjitianya/archive/2011/05/01/145462.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sun, 01 May 2011 08:40:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/05/01/145462.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/145462.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/05/01/145462.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/145462.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/145462.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Pygame游戏开发之五小试牛刀大部分游戏都会对图像文件进行加密，这样你就很难看到它的图片信息，游戏就更加添加了神秘感。有加密自然有解密，所谓山外青山楼外楼，再高的加密手段都可以被破解，加密只是提高技术门槛，让一部分人看不到你的图片资源。在进行加密之前，让我们首先把文件的结构组织一下，用文件夹来管理各类文件。root/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2011/05/01/145462.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/145462.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-05-01 16:40 <a href="http://www.cppblog.com/menjitianya/archive/2011/05/01/145462.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pygame游戏开发 之四</title><link>http://www.cppblog.com/menjitianya/archive/2011/04/28/145179.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Wed, 27 Apr 2011 18:19:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/04/28/145179.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/145179.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/04/28/145179.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/145179.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/145179.html</trackback:ping><description><![CDATA[<p style="TEXT-ALIGN: center; LINE-HEIGHT: 150%; MARGIN: 0cm 0cm 0pt" class=MsoNormal align=center><strong style="mso-bidi-font-weight: normal"><span style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; FONT-SIZE: 16pt; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体" lang=EN-US>Pygame</span></strong><strong style="mso-bidi-font-weight: normal"><span style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; FONT-SIZE: 16pt; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">游戏开发之四</span></strong><span style="LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-ALIGN: center; MARGIN: 0cm 0cm 0pt" class=MsoNormal align=center><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 16pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">初学乍练</span></strong><strong style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 16pt" lang=EN-US><o:p></o:p></span></strong></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Pygame</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中除了</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Group</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Sprite</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的容器类，还有一些继承自</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Group</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的容器类，它们分别是</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>RenderUpdates</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>OrderedUpdates</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>LayeredUpdates</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>LayeredDirty</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.sprite.RenderUpdates</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">继承自</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.sprite.Group</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，它相对于</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Group</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的不同点就是重写了</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Group</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>draw</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函数，原型是：</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>RenderUpdates.draw(surface) : return Rect_list</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">它将所有它包含的</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Sprites</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">绘制到</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>surface</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上，和</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Group.draw</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一样。但是这个函数返回了一系列的屏幕上发生改变的矩形列表，这个矩形列表应该被传递到</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.display.update</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中去。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.sprite.OrderedUpdates</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">继承自</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.sprite.RenderUpdates</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，它绘制</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Sprite</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的时候是以</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Sprite</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">被添加时的顺序来绘制的。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.sprite. LayeredUpdates</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">绘制的方式和</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.sprite.OrderedUpdates</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类似，只是它引入了图层的概念。你可以通过</span><span lang=EN-US>'default_layer'</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置默认图层，或者一个整数来表示图层。如果添加的</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Sprite</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">自己有一个</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>layer</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的图层属性那么就是用这个，否则在添加</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Sprite</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的时候，在</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.sprite. LayeredUpdates(*sprites, **kwarges)</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>**kwarges</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">参数中对</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>layer</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">属性进行设置，如果两者都没有设置，那么系统将采用默认图层。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.sprite. LayeredDirty</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">继承自</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.sprite.LayeredUpdates</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，它是</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>DirtySprites</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的专用容器类，继承了</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Group</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的所有操作。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">因为我们需要用到</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>DirtySprite</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，所以之前我们用到的所有</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Group</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类都替换成</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>LayeredDirty</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，而且为了便于扩展，我们将</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>LayeredDirty</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">再封装一层，以便添加新的成员函数。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>class gameManager(pygame.sprite.LayeredDirty) :<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>def __init__(self, selfdata) :<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pygame.sprite.LayeredDirty.__init__(self)<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>def keyevent(self, keypressed) :<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>for son in self.sprites() :<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>son.keyevent(keypressed)<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义一个</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>gameManager</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类，它继承了</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.sprite.LayeredDirty</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，并且添加一个</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>keyevent</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的成员函数，用于对键盘事件进行处理，它的操作很简单，调用它容器里的元素的</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>keyevent</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函数，它容器里的元素有可能是另一个</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>gameManager</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、或者是一个单纯的</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>RenderObject</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。如果是</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>gameManager</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的话就会进行递归调用，直到是</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>RenderObject</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，所以我们还要给</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>RenderObject</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义一个</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>keyevent</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函数，像这样：</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>class RenderObject(pygame.sprite.DirtySprite) :<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8230; &#8230;<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>def keyevent(self, keypressed) :<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pass<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们把</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>keyevent</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义在基类</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>RenderObject</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中，并且用</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pass</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示它什么都不做，然后等着子类去实现它。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>class Player(RenderObject) :<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&#8230; &#8230;<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>def keyevent(self, keypressed) :<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>left_or_right = keypressed[K_RIGHT] - keypressed[K_LEFT]<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>up_or_down<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>= keypressed[K_DOWN] - keypressed[K_UP]<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>self.move(left_or_right, up_or_down)<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Player</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>RenderObject</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的一个子类，我们可以用以上的语句实现</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Player</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的行走，</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>keypressed</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其实是</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>pygame.key.get_pressed()</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，用于获取当前键盘的某个键是否按下的映射表。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接下来我们用之前的模块来写一个游戏的背景，利用图</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>4-1</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的资源拼接出图</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>4-2</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的图像，并且让它在屏幕</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Y</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">轴方向进行滚屏操作。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-ALIGN: center; MARGIN: 0cm 0cm 0pt" class=MsoNormal align=center><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/menjitianya/smallwater.png" width=256 height=256><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-ALIGN: center; MARGIN: 0cm 0cm 0pt" class=MsoNormal align=center><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US> 4-1<o:p></o:p></span></p>
<p style="TEXT-ALIGN: center; MARGIN: 0cm 0cm 0pt" class=MsoNormal align=center><img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/menjitianya/water.jpg" width=358 height=480><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-ALIGN: center; MARGIN: 0cm 0cm 0pt" class=MsoNormal align=center><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US> 4-2<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">首先要明确的一点就是图片的四个方向必须是可拼接的，也就是说用</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>9</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">张相同的图片拼成一个九宫格，用肉眼是分辨不出它们是九张图片的，看到的是一个完整的图像。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们定义一个</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>RenderBack</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类：</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>class RenderBack(RenderObject) :<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>def __init__(self, selfdata) :<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>RenderObject.__init__(self, selfdata)<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>do_init()<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21.75pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>def update(self) :<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21.75pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>RenderObject.update(self)<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>do_update()<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">首先确定做这么一个背景需要用到的数据，背景的宽高是肯定要的，而且要求它在</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Y</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方向做滚屏操作，所以这个背景的实际的高肯定要比屏幕上显示高还要长（我们假设他是图</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>4-1</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图片高的整数倍），那么我们用一个四元组</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>(x, y, z, w)</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来表示需要知道的数据：</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>x : </span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">背景图资源在</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>images[]</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的索引号</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>y : </span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">生成图的宽</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>z : </span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">生成图的高</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>w: </span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">生成图在竖直方向的原图图块的数量</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个四元组是作为</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>selfdata</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">被传到</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>__init__</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函数中进行初始化的，并且可以在配置文件中修改它的值。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">因为最后的图像要进行</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Y</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方向的滚屏操作，所以我们还需要定义一个</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Y</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方向的偏移量，以便每次绘制的时候进行偏移操作。这样初始化就可以这么写：</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.image<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>= pygame.Surface( (int(selfdata[1]), int(selfdata[2])) )<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.rect<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun: yes">&nbsp;</span>= self.image.get_rect()<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.source_rect <span style="mso-spacerun: yes">&nbsp;&nbsp;</span>= self.image.get_rect()<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.backlen<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun: yes">&nbsp;</span>= int(selfdata[3]) <o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.backimage<span style="mso-spacerun: yes">&nbsp; </span><span style="mso-spacerun: yes">&nbsp;</span><span style="mso-spacerun: yes">&nbsp;</span>= RenderObject( [ selfdata[0] ] )<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.top_offset<span style="mso-spacerun: yes">&nbsp; </span><span style="mso-spacerun: yes">&nbsp;&nbsp;</span>= self.backimage.image.get_height() * self.backlen - self.rect.height<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里需要注意的是，</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>LayeredDirty</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在对</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>DirtySprite</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">进行绘制的时候总是对</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>sprite.image</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的内容进行绘制的，所以在</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>RenderBack</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里我们需要额外定义一个</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>backimage</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来对原图进行缓存，然后通过循环将它</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>blit</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">到</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>image</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上。这样</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>RenderBack</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的拥有者才能找到</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>image</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将它绘制出来。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对于</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>update</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函数，每一帧我们需要更新</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.top_offset</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Y</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方向的偏移量，并且根据它更新</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>image</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图像。具体实现如下：</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>def update(self) :<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>RenderObject.update(self)<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>xstep = self.backimage.image.get_width()<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>ystep = self.backimage.image.get_height()<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.top_offset -= 3<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p>&nbsp;</o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>y_offset = self.top_offset % ystep<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>for x in range(0, self.rect.width + xstep, xstep) :<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt 21pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.image.blit( self.backimage.image, (x, 0), ((0, y_offset), (xstep, ystep - y_offset) ) )<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p>&nbsp;</o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>for y in range(ystep - y_offset, self.rect.height + ystep, ystep) :<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt 21pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>for x in range(0, self.rect.width + xstep, xstep) :<o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt 42pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.image.blit( self.backimage.image, (x, y), ((0,0), (xstep, ystep) ) )<o:p></o:p></span></p>
<p style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p>&nbsp;</o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>(xstep, ystep)</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是原图的尺寸，每一帧我们对</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.top_offset</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">进行自减操作（效果就是让最后的图像有一种向上延伸的感觉，也就是滚屏的效果）。</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">然后我们分</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>x</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方向和</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>y</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方向进行讨论，因为</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>x</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方向没有滚屏操作，所以只要用现有的图片填充整个宽度即可，比如原图是</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>W=100</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个像素，需要填充的背景是</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>D=250</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个像素，那么水平方向至少需要用到</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>[ (D + W &#8211; 1) / W ] = 3</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">张原图（</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>[x]</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示比</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>x</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">小的最大整数，即取下整）。对于竖直方向，因为有滚屏操作，所以有两部分组成：第一排（从原图的</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>y</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方向某个位置粘贴过来的）以及非第一排（总是粘贴原图）。将</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>self.top_offset </span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US> ystep </span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">取模，得到的是需要绘制图像的最上方在原图的偏移量，通过它可以绘制第一排，然后再调用两层</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>for</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">循环绘制后面几排。这样随着时间的推移，一个</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US>Y</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方向的滚屏效果就出来了。（未完待续）</span><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
<p style="TEXT-INDENT: 21pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><span style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt" lang=EN-US><o:p>&nbsp;</o:p></span></p>
<img src ="http://www.cppblog.com/menjitianya/aggbug/145179.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-04-28 02:19 <a href="http://www.cppblog.com/menjitianya/archive/2011/04/28/145179.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pygame游戏开发 之三</title><link>http://www.cppblog.com/menjitianya/archive/2011/04/26/145013.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Mon, 25 Apr 2011 17:07:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/04/26/145013.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/145013.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/04/26/145013.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/145013.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/145013.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Pygame游戏开发之三初出茅庐&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pygame中除了Sprite，还有一个DirtySprite，它是由Sprite派生出来的绘制效率更高的精灵，较之Sprite多了以下几个属性：dirty =&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果设为1，则进行...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2011/04/26/145013.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/145013.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-04-26 01:07 <a href="http://www.cppblog.com/menjitianya/archive/2011/04/26/145013.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pygame游戏开发 之二</title><link>http://www.cppblog.com/menjitianya/archive/2011/04/24/144913.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sun, 24 Apr 2011 11:55:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/04/24/144913.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/144913.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/04/24/144913.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/144913.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/144913.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Pygame游戏开发之二初窥门径游戏中需要用到很多对象，比如人物、野怪、建筑物、UI控件等等，他们的行为不尽相同，但是总有那么些共同点，如果将所有的东西都封装成各自的类难免会写上很多重复的代码，因为两个对象如果具有相同的行为（比如人物和野怪都可以行走）如果写两个move()函数，以后改起来就要修改两个地方，不容易维护而且扩展很麻烦，但是人物和野怪又有其它不相同的行为，比如技能之类的不同...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2011/04/24/144913.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/144913.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-04-24 19:55 <a href="http://www.cppblog.com/menjitianya/archive/2011/04/24/144913.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pygame游戏开发 之一</title><link>http://www.cppblog.com/menjitianya/archive/2011/04/23/144866.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Sat, 23 Apr 2011 12:39:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/04/23/144866.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/144866.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/04/23/144866.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/144866.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/144866.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Pygame游戏开发之一初涉红尘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 本人是个游戏爱好者，同样是个游戏开发爱好者，最近开始学习Pygame，Pygame是 跨平台的 Python模块（包括Win32、Unix、Mac、Android等等），主要包含图像和声音，专为电子游戏设计。所有需要的游戏功能和理念都完全简化为游戏逻辑本身，这样就大大提高了开发效率。...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2011/04/23/144866.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/144866.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-04-23 20:39 <a href="http://www.cppblog.com/menjitianya/archive/2011/04/23/144866.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZJU 3108 Last Digit</title><link>http://www.cppblog.com/menjitianya/archive/2011/04/15/144304.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Fri, 15 Apr 2011 06:19:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/04/15/144304.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/144304.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/04/15/144304.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/144304.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/144304.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 题目链接：http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=2984/**//*题意：&nbsp;&nbsp;&nbsp;&nbsp;给出一个长度为N(N&nbsp;&lt;=&nbsp;1000000)的串，要求求出所有串的不重复排列的方案。输出方案数的最后一个非零位。题解：&nbsp;&nbsp;&nbsp;&nbsp;组...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2011/04/15/144304.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/144304.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-04-15 14:19 <a href="http://www.cppblog.com/menjitianya/archive/2011/04/15/144304.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PKU 3489 Knapsack I</title><link>http://www.cppblog.com/menjitianya/archive/2011/04/15/144291.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Fri, 15 Apr 2011 04:03:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/04/15/144291.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/144291.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/04/15/144291.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/144291.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/144291.html</trackback:ping><description><![CDATA[题目链接：<a href="http://poj.org/problem?id=3489">http://poj.org/problem?id=3489</a><br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img id=Codehighlighter1_0_1249_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_1249_Open_Text.style.display='none'; Codehighlighter1_0_1249_Closed_Image.style.display='inline'; Codehighlighter1_0_1249_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_0_1249_Closed_Image onclick="this.style.display='none'; Codehighlighter1_0_1249_Closed_Text.style.display='none'; Codehighlighter1_0_1249_Open_Image.style.display='inline'; Codehighlighter1_0_1249_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_0_1249_Closed_Text>/**/</span><span id=Codehighlighter1_0_1249_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">题意：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;给定n(&nbsp;n&nbsp;&lt;=&nbsp;1000&nbsp;)个大小为Vi的物品，每个物品都可以拆分成k次，拆分好的<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">物品可以继续拆分，Vi是整数，但是拆分好的物品的大小可以是任意实数，例如本来<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">Vi为7的物品拆分成5份，那么每份大小就是1.4，问最后能不能通过拆分和组合组出<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">大小为x的物品（每个物品的供应量是无穷多的）。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">题解：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;数学推导<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">思路：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;问题求得就是以下方程有没有整数解：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;x1*V1/(k^y1)&nbsp;+&nbsp;x2*V2/(k^y2)&nbsp;+&nbsp;<img src="http://www.cppblog.com/Images/dot.gif">&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;xn*Vn/(k^yn)&nbsp;=&nbsp;x<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">其中x1，y1是未知量。首先要明确的一点是，一个物品可以拆分的无限小，也就是<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">k^yi可以很大很大，因为当k^yi取得越大时，我们总可以找到k^yi个这类物品把它<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">还原成原来的大小，所以不影响解题；相反，如果取得比较小的话可能找不到可行<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">解，因为还没有达到要拆分的次数，然后我们这样考虑，令G&nbsp;=&nbsp;gcd(V1,&nbsp;V2&nbsp;<img src="http://www.cppblog.com/Images/dot.gif">)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">，并且Ti&nbsp;=&nbsp;Vi&nbsp;/&nbsp;G。那么原方程就可以表示成如下形式：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;G&nbsp;*&nbsp;(&nbsp;x1*T1/(k^y1)&nbsp;+&nbsp;x2*T2/(k^y2)&nbsp;+&nbsp;<img src="http://www.cppblog.com/Images/dot.gif">&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;xn*Tn/(k^yn)&nbsp;)&nbsp;=&nbsp;x<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;然后令M&nbsp;=&nbsp;k^j，你可以假设这个M足够大。再将上面的方程变形：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;S&nbsp;=&nbsp;x1*T1*(k^(j-y1))&nbsp;+&nbsp;x2*T2*(k^(j-y2))&nbsp;+&nbsp;<img src="http://www.cppblog.com/Images/dot.gif">&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;xn*Tn/(k^(j-yn));<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;G&nbsp;/&nbsp;M&nbsp;*&nbsp;S&nbsp;=&nbsp;x<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;接下啦，如果在G中的素因子同时存在于k中，那么我们把这些素因子全部剔除<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">，这一步其实就是求G和M的最大公约数，这就是为什么M要取足够大的原因。方程<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">转变成：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;G'&nbsp;=&nbsp;G&nbsp;/&nbsp;gcd(G,&nbsp;M);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;M'&nbsp;=&nbsp;M&nbsp;/&nbsp;gcd(G,&nbsp;M);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;G'&nbsp;/&nbsp;M'&nbsp;*&nbsp;S&nbsp;=&nbsp;x;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;然后我们将等式两边都乘上M'，可以得到：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;G'*&nbsp;S&nbsp;=&nbsp;x&nbsp;*&nbsp;M';<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;这四个数都是整数，G'和M'互质，所以G'必然要整除x，否则方程无解。那么<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">接下来就是要看，如果整除的话是否一定有解。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;令x'&nbsp;=&nbsp;x&nbsp;/&nbsp;G';&nbsp;那么有S&nbsp;=&nbsp;x'&nbsp;*&nbsp;M';<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;首先考虑n&nbsp;=&nbsp;1的情况，如果n&nbsp;=&nbsp;1，那么x1*(k^(j-y1))&nbsp;=&nbsp;x'&nbsp;*&nbsp;M';我们只要<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">取x1&nbsp;=&nbsp;x'&nbsp;*&nbsp;M'，y1&nbsp;=&nbsp;j&nbsp;就可以了。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;然后是n&nbsp;&gt;&nbsp;1的情况，我们取任意两种物品，其他物品假设都不取，如果这样都<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">能组合出来，那么结论就显然了。来看下面的方程：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;=&nbsp;x1*T1*(k^(j-y1));<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;B&nbsp;=&nbsp;x2*T2*(k^(j-y2));<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;+&nbsp;B&nbsp;=&nbsp;x'&nbsp;*&nbsp;M';<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;于是问题就转变成了线性同余方程是否有整数解的问题了。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;不妨假设y1&nbsp;&lt;&nbsp;y2，那么GG&nbsp;=&nbsp;gcd(A,&nbsp;B)&nbsp;=&nbsp;k^(j-y2);因为y1和y2的各自取值不<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">影响最后结果（因为可用很多个x2来补充），我们可以大胆的将y2取值为j。于是GG<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">就等于1了。这样方程就必然有解了。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;结论得证。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"></span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;maxn&nbsp;65537</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;f[maxn];<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;prime[maxn],&nbsp;size;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_1410_1444_Open_Image onclick="this.style.display='none'; Codehighlighter1_1410_1444_Open_Text.style.display='none'; Codehighlighter1_1410_1444_Closed_Image.style.display='inline'; Codehighlighter1_1410_1444_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1410_1444_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1410_1444_Closed_Text.style.display='none'; Codehighlighter1_1410_1444_Open_Image.style.display='inline'; Codehighlighter1_1410_1444_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;gcd(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;b)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1410_1444_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1410_1444_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;b</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">&nbsp;a&nbsp;:&nbsp;gcd(b,&nbsp;a</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">b);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_1484_1714_Open_Image onclick="this.style.display='none'; Codehighlighter1_1484_1714_Open_Text.style.display='none'; Codehighlighter1_1484_1714_Closed_Image.style.display='inline'; Codehighlighter1_1484_1714_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1484_1714_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1484_1714_Closed_Text.style.display='none'; Codehighlighter1_1484_1714_Open_Image.style.display='inline'; Codehighlighter1_1484_1714_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Divide(vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;&amp;</span><span style="COLOR: #000000">&nbsp;ans,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;v)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1484_1714_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1484_1714_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;ans.clear();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(v&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i;<br><img id=Codehighlighter1_1558_1693_Open_Image onclick="this.style.display='none'; Codehighlighter1_1558_1693_Open_Text.style.display='none'; Codehighlighter1_1558_1693_Closed_Image.style.display='inline'; Codehighlighter1_1558_1693_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1558_1693_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1558_1693_Closed_Text.style.display='none'; Codehighlighter1_1558_1693_Open_Image.style.display='inline'; Codehighlighter1_1558_1693_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;size;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1558_1693_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1558_1693_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_1584_1690_Open_Image onclick="this.style.display='none'; Codehighlighter1_1584_1690_Open_Text.style.display='none'; Codehighlighter1_1584_1690_Closed_Image.style.display='inline'; Codehighlighter1_1584_1690_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1584_1690_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1584_1690_Closed_Text.style.display='none'; Codehighlighter1_1584_1690_Open_Image.style.display='inline'; Codehighlighter1_1584_1690_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(v&nbsp;</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">&nbsp;prime[i]&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1584_1690_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1584_1690_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(v&nbsp;</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">&nbsp;prime[i]&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v&nbsp;</span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000">&nbsp;prime[i];<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans.push_back(prime[i]);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(v&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;ans.push_back(v);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,&nbsp;x,&nbsp;k;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_1742_2545_Open_Image onclick="this.style.display='none'; Codehighlighter1_1742_2545_Open_Text.style.display='none'; Codehighlighter1_1742_2545_Closed_Image.style.display='inline'; Codehighlighter1_1742_2545_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1742_2545_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1742_2545_Closed_Text.style.display='none'; Codehighlighter1_1742_2545_Open_Image.style.display='inline'; Codehighlighter1_1742_2545_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1742_2545_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1742_2545_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;j;<br><img id=Codehighlighter1_1782_1880_Open_Image onclick="this.style.display='none'; Codehighlighter1_1782_1880_Open_Text.style.display='none'; Codehighlighter1_1782_1880_Closed_Image.style.display='inline'; Codehighlighter1_1782_1880_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1782_1880_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1782_1880_Closed_Text.style.display='none'; Codehighlighter1_1782_1880_Open_Image.style.display='inline'; Codehighlighter1_1782_1880_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;maxn;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1782_1880_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1782_1880_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_1796_1877_Open_Image onclick="this.style.display='none'; Codehighlighter1_1796_1877_Open_Text.style.display='none'; Codehighlighter1_1796_1877_Closed_Image.style.display='inline'; Codehighlighter1_1796_1877_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1796_1877_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1796_1877_Closed_Text.style.display='none'; Codehighlighter1_1796_1877_Open_Image.style.display='inline'; Codehighlighter1_1796_1877_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">f[i])&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1796_1877_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1796_1877_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prime[size</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;i;<br><img id=Codehighlighter1_1854_1873_Open_Image onclick="this.style.display='none'; Codehighlighter1_1854_1873_Open_Text.style.display='none'; Codehighlighter1_1854_1873_Closed_Image.style.display='inline'; Codehighlighter1_1854_1873_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1854_1873_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1854_1873_Closed_Text.style.display='none'; Codehighlighter1_1854_1873_Open_Image.style.display='inline'; Codehighlighter1_1854_1873_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i;&nbsp;j&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;maxn;&nbsp;j&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;i)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1854_1873_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1854_1873_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[j]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img id=Codehighlighter1_1928_2532_Open_Image onclick="this.style.display='none'; Codehighlighter1_1928_2532_Open_Text.style.display='none'; Codehighlighter1_1928_2532_Closed_Image.style.display='inline'; Codehighlighter1_1928_2532_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1928_2532_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1928_2532_Closed_Text.style.display='none'; Codehighlighter1_1928_2532_Open_Image.style.display='inline'; Codehighlighter1_1928_2532_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">x,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">k)&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;EOF)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1928_2532_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1928_2532_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;G&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_1968_2057_Open_Image onclick="this.style.display='none'; Codehighlighter1_1968_2057_Open_Text.style.display='none'; Codehighlighter1_1968_2057_Closed_Image.style.display='inline'; Codehighlighter1_1968_2057_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1968_2057_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1968_2057_Closed_Text.style.display='none'; Codehighlighter1_1968_2057_Open_Image.style.display='inline'; Codehighlighter1_1968_2057_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1968_2057_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1968_2057_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;val;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">val);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;gcd(G,&nbsp;val);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;val;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;vecG;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;vecK;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Divide(vecG,&nbsp;G);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Divide(vecK,&nbsp;k);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;flag&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_2194_2488_Open_Image onclick="this.style.display='none'; Codehighlighter1_2194_2488_Open_Text.style.display='none'; Codehighlighter1_2194_2488_Closed_Image.style.display='inline'; Codehighlighter1_2194_2488_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_2194_2488_Closed_Image onclick="this.style.display='none'; Codehighlighter1_2194_2488_Closed_Text.style.display='none'; Codehighlighter1_2194_2488_Open_Image.style.display='inline'; Codehighlighter1_2194_2488_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;vecG.size();&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_2194_2488_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_2194_2488_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_2232_2276_Open_Image onclick="this.style.display='none'; Codehighlighter1_2232_2276_Open_Text.style.display='none'; Codehighlighter1_2232_2276_Closed_Image.style.display='inline'; Codehighlighter1_2232_2276_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_2232_2276_Closed_Image onclick="this.style.display='none'; Codehighlighter1_2232_2276_Closed_Text.style.display='none'; Codehighlighter1_2232_2276_Open_Image.style.display='inline'; Codehighlighter1_2232_2276_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;j&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;vecK.size();&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_2232_2276_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_2232_2276_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(vecG[i]&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;vecK[j])<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_2302_2484_Open_Image onclick="this.style.display='none'; Codehighlighter1_2302_2484_Open_Text.style.display='none'; Codehighlighter1_2302_2484_Closed_Image.style.display='inline'; Codehighlighter1_2302_2484_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_2302_2484_Closed_Image onclick="this.style.display='none'; Codehighlighter1_2302_2484_Closed_Text.style.display='none'; Codehighlighter1_2302_2484_Open_Image.style.display='inline'; Codehighlighter1_2302_2484_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(j&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;vecK.size())&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_2302_2484_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_2302_2484_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_2332_2454_Open_Image onclick="this.style.display='none'; Codehighlighter1_2332_2454_Open_Text.style.display='none'; Codehighlighter1_2332_2454_Closed_Image.style.display='inline'; Codehighlighter1_2332_2454_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_2332_2454_Closed_Image onclick="this.style.display='none'; Codehighlighter1_2332_2454_Closed_Text.style.display='none'; Codehighlighter1_2332_2454_Open_Image.style.display='inline'; Codehighlighter1_2332_2454_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(G&nbsp;</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">&nbsp;vecG[i]&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_2332_2454_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_2332_2454_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G&nbsp;</span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000">&nbsp;vecG[i];<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(x&nbsp;</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">&nbsp;vecG[i]&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;</span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000">&nbsp;vecG[i];<br><img id=Codehighlighter1_2409_2448_Open_Image onclick="this.style.display='none'; Codehighlighter1_2409_2448_Open_Text.style.display='none'; Codehighlighter1_2409_2448_Closed_Image.style.display='inline'; Codehighlighter1_2409_2448_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_2409_2448_Closed_Image onclick="this.style.display='none'; Codehighlighter1_2409_2448_Closed_Text.style.display='none'; Codehighlighter1_2409_2448_Open_Image.style.display='inline'; Codehighlighter1_2409_2448_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_2409_2448_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_2409_2448_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flag&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flag)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;flag&nbsp;</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">No</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;:&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Yes</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<img src ="http://www.cppblog.com/menjitianya/aggbug/144291.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-04-15 12:03 <a href="http://www.cppblog.com/menjitianya/archive/2011/04/15/144291.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 3758 Factorial Simplification</title><link>http://www.cppblog.com/menjitianya/archive/2011/04/15/144267.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Fri, 15 Apr 2011 01:11:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/04/15/144267.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/144267.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/04/15/144267.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/144267.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/144267.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 题目链接：http://acm.hdu.edu.cn/showproblem.php?pid=3758/**//*题意：&nbsp;&nbsp;&nbsp;&nbsp;给定N个和M个不大于10000的数(N,M&nbsp;&lt;=&nbsp;1000)，N个数各自的阶乘的乘积除上M个数各自阶乘的乘积是一个很大的数，现在要求将这个数表示成如下形式：&nbsp;&nbsp;&nbsp;&nbsp...&nbsp;&nbsp;<a href='http://www.cppblog.com/menjitianya/archive/2011/04/15/144267.html'>阅读全文</a><img src ="http://www.cppblog.com/menjitianya/aggbug/144267.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-04-15 09:11 <a href="http://www.cppblog.com/menjitianya/archive/2011/04/15/144267.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 3756 Dome of Circus</title><link>http://www.cppblog.com/menjitianya/archive/2011/04/12/144077.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Tue, 12 Apr 2011 14:58:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/04/12/144077.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/144077.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/04/12/144077.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/144077.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/144077.html</trackback:ping><description><![CDATA[<p>题目链接：<a href="http://acm.hdu.edu.cn/showproblem.php?pid=3756">http://acm.hdu.edu.cn/showproblem.php?pid=3756</a></p>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img id=Codehighlighter1_0_869_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_869_Open_Text.style.display='none'; Codehighlighter1_0_869_Closed_Image.style.display='inline'; Codehighlighter1_0_869_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_0_869_Closed_Image onclick="this.style.display='none'; Codehighlighter1_0_869_Closed_Text.style.display='none'; Codehighlighter1_0_869_Open_Image.style.display='inline'; Codehighlighter1_0_869_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_0_869_Closed_Text>/**/</span><span id=Codehighlighter1_0_869_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">题意：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;在一个三维空间中，给定一些点，这些点的z坐标都是大于0的。要求求<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">出一个圆锥（底面是圆形），使得这个圆锥的底面在z&nbsp;=&nbsp;0的平面上，它能够<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">包含所有给定的点并且圆锥的体积要求最小。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">题解：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;数学推导&nbsp;+&nbsp;三分<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">思路：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;这是一个很有意思的题，虽然是三维的，但是可以很容易的转化到二维去<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">。来看X-Z这个平面，我们将所有的点进行圆周映射，然后将所有的点都投影到<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">X-Z平面的的第一象限去，然后问题就转化成了在X-Z平面上找到一条斜率为负<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">的直线L，L和X正方向、Z正方向围成的三角形包含所有点，如果假设L和X轴的<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">交点为R，和Z轴焦点为H，要求pi*H*R^2的值最小。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;然后我们来看看H和R之间有什么千丝万缕的关系。首先L这条线必定和某一<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">个给定的点擦边，也就是经过那个点，我们假设它经过P(a,&nbsp;b)，&nbsp;并且L的斜率<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">为K(K&nbsp;&lt;&nbsp;0)，那么L的方程就可以表示为&nbsp;L:&nbsp;&nbsp;y&nbsp;=&nbsp;K&nbsp;*&nbsp;(x&nbsp;-&nbsp;a)&nbsp;+&nbsp;b，则H和R就<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">可以利用这个方程表示出来：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">H&nbsp;=&nbsp;-a&nbsp;*&nbsp;K&nbsp;+&nbsp;b;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">R&nbsp;=&nbsp;-b&nbsp;/&nbsp;K&nbsp;+&nbsp;a;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">那么所求的圆锥的体积就是：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">V&nbsp;=&nbsp;pi*H*R^2&nbsp;=&nbsp;pi&nbsp;*&nbsp;(-a&nbsp;*&nbsp;K&nbsp;+&nbsp;b)&nbsp;*&nbsp;(-b&nbsp;/&nbsp;K&nbsp;+&nbsp;a)&nbsp;^&nbsp;2<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">容易得到V(K)这个函数的导数：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">V'(K)&nbsp;=&nbsp;-&nbsp;pi&nbsp;*&nbsp;(aK^2&nbsp;+&nbsp;2bK)&nbsp;*&nbsp;(aK&nbsp;-&nbsp;b)^2&nbsp;/&nbsp;K^2<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">影响这个导数的正负性的唯一条件是&nbsp;-(aK^2&nbsp;+&nbsp;2bK)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">当-2b/a&nbsp;&lt;&nbsp;K&nbsp;&lt;&nbsp;0时V'(K)大于零，也就是V的值是随着K递增的。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">当K&nbsp;&lt;&nbsp;-2b/a时V'(K)小于零，也就是V的值是随着K递减的。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">于是可以得出一个结论，当K&nbsp;=&nbsp;-2b/a&nbsp;时V取得最小值。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">于是我们知道了V的单峰性，然后就可以通过枚举半径R，因为R对于V具有单谷<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">性，所以枚举R的时候可以采用三分。每次通过三分R找到最小的H，这个过程可<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">以通过枚举每个点，找到最大的极角alpha，R*tan(alpha)就是H了。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;这里需要注意的就是精度问题了。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"></span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cmath</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;eps&nbsp;1e-6</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;pi&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;acos(</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1.0</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_1013_1134_Open_Image onclick="this.style.display='none'; Codehighlighter1_1013_1134_Open_Text.style.display='none'; Codehighlighter1_1013_1134_Closed_Image.style.display='inline'; Codehighlighter1_1013_1134_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1013_1134_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1013_1134_Closed_Text.style.display='none'; Codehighlighter1_1013_1134_Open_Image.style.display='inline'; Codehighlighter1_1013_1134_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;Point&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1013_1134_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1013_1134_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;x,&nbsp;y,&nbsp;z;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;v,&nbsp;h;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img id=Codehighlighter1_1061_1132_Open_Image onclick="this.style.display='none'; Codehighlighter1_1061_1132_Open_Text.style.display='none'; Codehighlighter1_1061_1132_Closed_Image.style.display='inline'; Codehighlighter1_1061_1132_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1061_1132_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1061_1132_Closed_Text.style.display='none'; Codehighlighter1_1061_1132_Open_Image.style.display='inline'; Codehighlighter1_1061_1132_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;SCANF()&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1061_1132_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1061_1132_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%lf&nbsp;%lf&nbsp;%lf</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">x,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">y,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">z);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;z;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;sqrt(x</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">x&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;y</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">y);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">pt[&nbsp;</span><span style="COLOR: #000000">10001</span><span style="COLOR: #000000">&nbsp;];<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;MaxH,&nbsp;MaxV;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_1198_1370_Open_Image onclick="this.style.display='none'; Codehighlighter1_1198_1370_Open_Text.style.display='none'; Codehighlighter1_1198_1370_Closed_Image.style.display='inline'; Codehighlighter1_1198_1370_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1198_1370_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1198_1370_Closed_Text.style.display='none'; Codehighlighter1_1198_1370_Open_Image.style.display='inline'; Codehighlighter1_1198_1370_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;Calc(</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;R)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1198_1370_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1198_1370_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;Max&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;idx&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_1263_1351_Open_Image onclick="this.style.display='none'; Codehighlighter1_1263_1351_Open_Text.style.display='none'; Codehighlighter1_1263_1351_Closed_Image.style.display='inline'; Codehighlighter1_1263_1351_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1263_1351_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1263_1351_Closed_Text.style.display='none'; Codehighlighter1_1263_1351_Open_Image.style.display='inline'; Codehighlighter1_1263_1351_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1263_1351_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1263_1351_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;nv&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pt[i].v&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;(R&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;pt[i].h);<br><img id=Codehighlighter1_1319_1348_Open_Image onclick="this.style.display='none'; Codehighlighter1_1319_1348_Open_Text.style.display='none'; Codehighlighter1_1319_1348_Closed_Image.style.display='inline'; Codehighlighter1_1319_1348_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1319_1348_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1319_1348_Closed_Text.style.display='none'; Codehighlighter1_1319_1348_Open_Image.style.display='inline'; Codehighlighter1_1319_1348_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(nv&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;Max)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1319_1348_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1319_1348_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Max&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;nv;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;idx&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;i;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;Max&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;R;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_1384_1969_Open_Image onclick="this.style.display='none'; Codehighlighter1_1384_1969_Open_Text.style.display='none'; Codehighlighter1_1384_1969_Closed_Image.style.display='inline'; Codehighlighter1_1384_1969_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1384_1969_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1384_1969_Closed_Text.style.display='none'; Codehighlighter1_1384_1969_Open_Image.style.display='inline'; Codehighlighter1_1384_1969_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1384_1969_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1384_1969_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">t);<br><img id=Codehighlighter1_1433_1956_Open_Image onclick="this.style.display='none'; Codehighlighter1_1433_1956_Open_Text.style.display='none'; Codehighlighter1_1433_1956_Closed_Image.style.display='inline'; Codehighlighter1_1433_1956_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1433_1956_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1433_1956_Closed_Text.style.display='none'; Codehighlighter1_1433_1956_Open_Image.style.display='inline'; Codehighlighter1_1433_1956_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(t</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1433_1956_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1433_1956_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxH&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;MaxV&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_1498_1604_Open_Image onclick="this.style.display='none'; Codehighlighter1_1498_1604_Open_Text.style.display='none'; Codehighlighter1_1498_1604_Closed_Image.style.display='inline'; Codehighlighter1_1498_1604_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1498_1604_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1498_1604_Closed_Text.style.display='none'; Codehighlighter1_1498_1604_Open_Image.style.display='inline'; Codehighlighter1_1498_1604_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1498_1604_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1498_1604_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pt[i].SCANF();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(pt[i].h&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;MaxH)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxH&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pt[i].h;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(pt[i].v&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;MaxV)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxV&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pt[i].v;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;l&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;MaxH&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;eps,&nbsp;r&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;1e6;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;ml,&nbsp;mr;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img id=Codehighlighter1_1681_1881_Open_Image onclick="this.style.display='none'; Codehighlighter1_1681_1881_Open_Text.style.display='none'; Codehighlighter1_1681_1881_Closed_Image.style.display='inline'; Codehighlighter1_1681_1881_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1681_1881_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1681_1881_Closed_Text.style.display='none'; Codehighlighter1_1681_1881_Open_Image.style.display='inline'; Codehighlighter1_1681_1881_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(l&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;1e</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;r)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1681_1881_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1681_1881_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ml&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;l&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;r)&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(l&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;r)&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;lans&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;Calc(ml)&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;ml&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;ml;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;rans&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;Calc(mr)&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;mr&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;mr;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img id=Codehighlighter1_1830_1854_Open_Image onclick="this.style.display='none'; Codehighlighter1_1830_1854_Open_Text.style.display='none'; Codehighlighter1_1830_1854_Closed_Image.style.display='inline'; Codehighlighter1_1830_1854_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1830_1854_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1830_1854_Closed_Text.style.display='none'; Codehighlighter1_1830_1854_Open_Image.style.display='inline'; Codehighlighter1_1830_1854_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(&nbsp;lans&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;rans&nbsp;)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1830_1854_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1830_1854_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;ml&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;1e</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;mr&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;1e</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;ans&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(l&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;r)&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%.3lf&nbsp;%.3lf\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;Calc(ans),&nbsp;ans);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span></div>
<img src ="http://www.cppblog.com/menjitianya/aggbug/144077.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-04-12 22:58 <a href="http://www.cppblog.com/menjitianya/archive/2011/04/12/144077.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 2688 Rotate</title><link>http://www.cppblog.com/menjitianya/archive/2011/04/11/143934.html</link><dc:creator>英雄哪里出来</dc:creator><author>英雄哪里出来</author><pubDate>Mon, 11 Apr 2011 04:19:00 GMT</pubDate><guid>http://www.cppblog.com/menjitianya/archive/2011/04/11/143934.html</guid><wfw:comment>http://www.cppblog.com/menjitianya/comments/143934.html</wfw:comment><comments>http://www.cppblog.com/menjitianya/archive/2011/04/11/143934.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/menjitianya/comments/commentRss/143934.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/menjitianya/services/trackbacks/143934.html</trackback:ping><description><![CDATA[<strong>题目链接：</strong><a href="http://acm.hdu.edu.cn/showproblem.php?pid=2688">http://acm.hdu.edu.cn/showproblem.php?pid=2688</a><br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img id=Codehighlighter1_0_281_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_281_Open_Text.style.display='none'; Codehighlighter1_0_281_Closed_Image.style.display='inline'; Codehighlighter1_0_281_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_0_281_Closed_Image onclick="this.style.display='none'; Codehighlighter1_0_281_Closed_Text.style.display='none'; Codehighlighter1_0_281_Open_Image.style.display='inline'; Codehighlighter1_0_281_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_0_281_Closed_Text>/**/</span><span id=Codehighlighter1_0_281_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">题意：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;给定一串长度为N的序列(N&nbsp;&lt;=&nbsp;3000000)，然后是M(M&lt;=10000)个操作，<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">每个操作有两种形式：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">1.&nbsp;Q&nbsp;询问当前序列的顺序数<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">2.&nbsp;R&nbsp;S&nbsp;E&nbsp;(abs(E-S)&nbsp;&lt;=&nbsp;1000)将下标S到E的数列向左循环旋转一次<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">题解：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;树状数组<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">思路：<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;经典问题，首先将N个数的顺序数用树状数组求出来，这个操作是nlogn<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">的，然后对于每次R操作，统计在[S+1，E]区间中比v[S]大的数和小的数的个数，<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">将之前的顺序数&nbsp;-&nbsp;比它大的数&nbsp;+&nbsp;比它小的数，更新这个值。然后顺序赋值即可。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">Q操作只需要直接输出当前顺序数的值即可。<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif"></span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;maxn&nbsp;10001</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;ans[</span><span style="COLOR: #000000">3000001</span><span style="COLOR: #000000">];<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,&nbsp;m;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;ll&nbsp;__int64</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">ll&nbsp;c[maxn];<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_426_446_Open_Image onclick="this.style.display='none'; Codehighlighter1_426_446_Open_Text.style.display='none'; Codehighlighter1_426_446_Closed_Image.style.display='inline'; Codehighlighter1_426_446_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_426_446_Closed_Image onclick="this.style.display='none'; Codehighlighter1_426_446_Closed_Text.style.display='none'; Codehighlighter1_426_446_Open_Image.style.display='inline'; Codehighlighter1_426_446_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;lowbit(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_426_446_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_426_446_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;x&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_467_528_Open_Image onclick="this.style.display='none'; Codehighlighter1_467_528_Open_Text.style.display='none'; Codehighlighter1_467_528_Closed_Image.style.display='inline'; Codehighlighter1_467_528_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_467_528_Closed_Image onclick="this.style.display='none'; Codehighlighter1_467_528_Closed_Text.style.display='none'; Codehighlighter1_467_528_Open_Image.style.display='inline'; Codehighlighter1_467_528_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;add(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;pos)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_467_528_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_467_528_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_488_526_Open_Image onclick="this.style.display='none'; Codehighlighter1_488_526_Open_Text.style.display='none'; Codehighlighter1_488_526_Closed_Image.style.display='inline'; Codehighlighter1_488_526_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_488_526_Closed_Image onclick="this.style.display='none'; Codehighlighter1_488_526_Closed_Text.style.display='none'; Codehighlighter1_488_526_Open_Image.style.display='inline'; Codehighlighter1_488_526_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(pos&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;maxn)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_488_526_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_488_526_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c[pos]&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;lowbit(pos);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_547_629_Open_Image onclick="this.style.display='none'; Codehighlighter1_547_629_Open_Text.style.display='none'; Codehighlighter1_547_629_Closed_Image.style.display='inline'; Codehighlighter1_547_629_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_547_629_Closed_Image onclick="this.style.display='none'; Codehighlighter1_547_629_Closed_Text.style.display='none'; Codehighlighter1_547_629_Open_Image.style.display='inline'; Codehighlighter1_547_629_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif">ll&nbsp;sum(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;pos)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_547_629_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_547_629_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;ll&nbsp;s&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_576_616_Open_Image onclick="this.style.display='none'; Codehighlighter1_576_616_Open_Text.style.display='none'; Codehighlighter1_576_616_Closed_Image.style.display='inline'; Codehighlighter1_576_616_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_576_616_Closed_Image onclick="this.style.display='none'; Codehighlighter1_576_616_Closed_Text.style.display='none'; Codehighlighter1_576_616_Open_Image.style.display='inline'; Codehighlighter1_576_616_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(pos&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_576_616_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_576_616_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;c[pos];<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos&nbsp;</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">&nbsp;lowbit(pos);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;s;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_643_1380_Open_Image onclick="this.style.display='none'; Codehighlighter1_643_1380_Open_Text.style.display='none'; Codehighlighter1_643_1380_Closed_Image.style.display='inline'; Codehighlighter1_643_1380_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_643_1380_Closed_Image onclick="this.style.display='none'; Codehighlighter1_643_1380_Closed_Text.style.display='none'; Codehighlighter1_643_1380_Open_Image.style.display='inline'; Codehighlighter1_643_1380_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_643_1380_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_643_1380_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i;<br><img id=Codehighlighter1_684_1367_Open_Image onclick="this.style.display='none'; Codehighlighter1_684_1367_Open_Text.style.display='none'; Codehighlighter1_684_1367_Closed_Image.style.display='inline'; Codehighlighter1_684_1367_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_684_1367_Closed_Image onclick="this.style.display='none'; Codehighlighter1_684_1367_Closed_Text.style.display='none'; Codehighlighter1_684_1367_Open_Image.style.display='inline'; Codehighlighter1_684_1367_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n)&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;EOF)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_684_1367_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_684_1367_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">10000</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c[i]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ll&nbsp;val&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_768_840_Open_Image onclick="this.style.display='none'; Codehighlighter1_768_840_Open_Text.style.display='none'; Codehighlighter1_768_840_Closed_Image.style.display='inline'; Codehighlighter1_768_840_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_768_840_Closed_Image onclick="this.style.display='none'; Codehighlighter1_768_840_Closed_Text.style.display='none'; Codehighlighter1_768_840_Open_Image.style.display='inline'; Codehighlighter1_768_840_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_768_840_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_768_840_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">ans[i]);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;sum(ans[i]&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add(ans[i]);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">m);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img id=Codehighlighter1_875_1364_Open_Image onclick="this.style.display='none'; Codehighlighter1_875_1364_Open_Text.style.display='none'; Codehighlighter1_875_1364_Closed_Image.style.display='inline'; Codehighlighter1_875_1364_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_875_1364_Closed_Image onclick="this.style.display='none'; Codehighlighter1_875_1364_Closed_Text.style.display='none'; Codehighlighter1_875_1364_Open_Image.style.display='inline'; Codehighlighter1_875_1364_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(m</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_875_1364_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_875_1364_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;str[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">];<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;str);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img id=Codehighlighter1_937_971_Open_Image onclick="this.style.display='none'; Codehighlighter1_937_971_Open_Text.style.display='none'; Codehighlighter1_937_971_Closed_Image.style.display='inline'; Codehighlighter1_937_971_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_937_971_Closed_Image onclick="this.style.display='none'; Codehighlighter1_937_971_Closed_Text.style.display='none'; Codehighlighter1_937_971_Open_Image.style.display='inline'; Codehighlighter1_937_971_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(str[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">Q</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_937_971_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_937_971_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%I64d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;val);<br><img id=Codehighlighter1_977_1360_Open_Image onclick="this.style.display='none'; Codehighlighter1_977_1360_Open_Text.style.display='none'; Codehighlighter1_977_1360_Closed_Image.style.display='inline'; Codehighlighter1_977_1360_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_977_1360_Closed_Image onclick="this.style.display='none'; Codehighlighter1_977_1360_Closed_Text.style.display='none'; Codehighlighter1_977_1360_Open_Image.style.display='inline'; Codehighlighter1_977_1360_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_977_1360_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_977_1360_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;s,&nbsp;e;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">s,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">e);<br><img id=Codehighlighter1_1035_1085_Open_Image onclick="this.style.display='none'; Codehighlighter1_1035_1085_Open_Text.style.display='none'; Codehighlighter1_1035_1085_Closed_Image.style.display='inline'; Codehighlighter1_1035_1085_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1035_1085_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1035_1085_Closed_Text.style.display='none'; Codehighlighter1_1035_1085_Open_Image.style.display='inline'; Codehighlighter1_1035_1085_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(s&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;e)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1035_1085_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1035_1085_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;tmp&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;s;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;e;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;tmp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img id=Codehighlighter1_1103_1355_Open_Image onclick="this.style.display='none'; Codehighlighter1_1103_1355_Open_Text.style.display='none'; Codehighlighter1_1103_1355_Closed_Image.style.display='inline'; Codehighlighter1_1103_1355_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1103_1355_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1103_1355_Closed_Text.style.display='none'; Codehighlighter1_1103_1355_Open_Image.style.display='inline'; Codehighlighter1_1103_1355_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(s&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;e)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1103_1355_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1103_1355_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;v&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;ans[s];<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;lt&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;bt&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_1179_1306_Open_Image onclick="this.style.display='none'; Codehighlighter1_1179_1306_Open_Text.style.display='none'; Codehighlighter1_1179_1306_Closed_Image.style.display='inline'; Codehighlighter1_1179_1306_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1179_1306_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1179_1306_Closed_Text.style.display='none'; Codehighlighter1_1179_1306_Open_Image.style.display='inline'; Codehighlighter1_1179_1306_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;s;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;e;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1179_1306_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1179_1306_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[i]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;ans[i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br><img id=Codehighlighter1_1229_1251_Open_Image onclick="this.style.display='none'; Codehighlighter1_1229_1251_Open_Text.style.display='none'; Codehighlighter1_1229_1251_Closed_Image.style.display='inline'; Codehighlighter1_1229_1251_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1229_1251_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1229_1251_Closed_Text.style.display='none'; Codehighlighter1_1229_1251_Open_Image.style.display='inline'; Codehighlighter1_1229_1251_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(v&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;ans[i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1229_1251_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1229_1251_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lt&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_1276_1298_Open_Image onclick="this.style.display='none'; Codehighlighter1_1276_1298_Open_Text.style.display='none'; Codehighlighter1_1276_1298_Closed_Image.style.display='inline'; Codehighlighter1_1276_1298_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1276_1298_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1276_1298_Closed_Text.style.display='none'; Codehighlighter1_1276_1298_Open_Image.style.display='inline'; Codehighlighter1_1276_1298_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(v&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;ans[i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1276_1298_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1276_1298_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bt&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[e]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;v;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;val&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;lt&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;bt;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span></div>
<img src ="http://www.cppblog.com/menjitianya/aggbug/143934.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/menjitianya/" target="_blank">英雄哪里出来</a> 2011-04-11 12:19 <a href="http://www.cppblog.com/menjitianya/archive/2011/04/11/143934.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>