﻿<?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++博客-希望的海洋-随笔分类-HDU</title><link>http://www.cppblog.com/snowshine09/category/17459.html</link><description>Ain't about how fast I get there,ain't about what's waiting on the other side</description><language>zh-cn</language><lastBuildDate>Sun, 18 Sep 2011 14:07:36 GMT</lastBuildDate><pubDate>Sun, 18 Sep 2011 14:07:36 GMT</pubDate><ttl>60</ttl><item><title>hdu 3591取石子（一堆）</title><link>http://www.cppblog.com/snowshine09/archive/2011/09/17/156044.html</link><dc:creator>拥梦的小鱼</dc:creator><author>拥梦的小鱼</author><pubDate>Sat, 17 Sep 2011 11:55:00 GMT</pubDate><guid>http://www.cppblog.com/snowshine09/archive/2011/09/17/156044.html</guid><wfw:comment>http://www.cppblog.com/snowshine09/comments/156044.html</wfw:comment><comments>http://www.cppblog.com/snowshine09/archive/2011/09/17/156044.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/snowshine09/comments/commentRss/156044.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/snowshine09/services/trackbacks/156044.html</trackback:ping><description><![CDATA[<p>hdu 3591</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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cmath</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">map</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">vector</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">iomanip</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></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"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_188_380_Open_Image" onclick="this.style.display='none'; Codehighlighter1_188_380_Open_Text.style.display='none'; Codehighlighter1_188_380_Closed_Image.style.display='inline'; Codehighlighter1_188_380_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_188_380_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_188_380_Closed_Text.style.display='none'; Codehighlighter1_188_380_Open_Image.style.display='inline'; Codehighlighter1_188_380_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></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_188_380_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_188_380_Open_Text"><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">int</span><span style="color: #000000">&nbsp;T,count</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">T;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(T</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_228_367_Open_Image" onclick="this.style.display='none'; Codehighlighter1_228_367_Open_Text.style.display='none'; Codehighlighter1_228_367_Closed_Image.style.display='inline'; Codehighlighter1_228_367_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_228_367_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_228_367_Closed_Text.style.display='none'; Codehighlighter1_228_367_Open_Image.style.display='inline'; Codehighlighter1_228_367_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&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_228_367_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_228_367_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,k;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">n</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">k;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">Case&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">count</span><span style="color: #000000">++&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">:&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">((n</span><span style="color: #000000">&amp;</span><span style="color: #000000">1</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">k</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)</span><span style="color: #000000">||</span><span style="color: #000000">k</span><span style="color: #000000">&gt;=</span><span style="color: #000000">n)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">first</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">second</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></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">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"  alt="" />}</span></span></div>
<p><br />//cankao others<br />本题类似我曾今玩过的的一个NDS解密游戏《雷顿教授与魔神之笛》里的一道谜题。游戏里是给你15个围成圈的水龙头，开始它们全都是打开漏水的。接着你要跟电脑博弈，从电脑开始，双方可以选择关闭连续的两个水龙头（当然，已关的不能再打开了）也可以只选择关掉一个，最终没水龙头可关的将失败。在没学相关知识之前那迷题一直让我挺头疼的。。。</p>
<p>那个游戏的答案解法是，由于电脑一定会先关掉两个水龙头，接着你只要关掉剩余水龙头的中间那个，因而将剩余的水龙头分成数目相等的两个部分。那后无论电脑操作哪一部分的一或二个水龙头，你只要一样对称地关掉另一部分得水龙头。那你一定会是胜利者！</p>
<p><br /></p>
<p>本题相当于是该迷题的一个拓展。</p>
<p>我们首先要分几种情况考虑：</p>
<p>1.当 &nbsp;K=1时，若N为奇数，则first wins，N为偶数则second wins。</p>
<p>2.当 &nbsp;K&gt;=N时，first wins。</p>
<p>3.当 &nbsp;N&gt;K&gt;1时，情况类似上面提到过的谜题，若first的最先操作使得剩下的水龙头为偶数，如果你能把剩下的取完那就直接胜利，如果不能那就拿走中间的若干个偶数个硬币使得剩下的硬币被分为数目相等的两堆。接着对方对某堆进行操作你就对另一堆进行同样的操作，这时是second wins。first的最先操作使得剩下的水龙头为奇数时同理可证second wins。</p>
<p>那就OK了。</p><img src ="http://www.cppblog.com/snowshine09/aggbug/156044.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/snowshine09/" target="_blank">拥梦的小鱼</a> 2011-09-17 19:55 <a href="http://www.cppblog.com/snowshine09/archive/2011/09/17/156044.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>