用户操作
[留言]  [发消息]  [加为好友] 
订阅我的博客
XML聚合    FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
northwolves的公告
<a href="http://www2.clustrmaps.com/counter/maps.php?url=http://blog.csdn.net/northwolves" id="clustrMapsLink"><img src="http://www2.clustrmaps.com/counter/index2.php?url=http://blog.csdn.net/northwolves" style="border:1px solid;" alt="Locations of visitors to this page" title="Locations of visitors to this page" id="clustrMapsImg" width=225 height=150 onError="this.onError=null; this.src='http://clustrmaps.com/images/clustrmaps-back-soon.jpg'; document.getElementById('clustrMapsLink').href='http://clustrmaps.com'" /> </a> <!-- Beginning of Freelancer.com Affiliates Widget --> <script type="text/javascript"><!-- GAF_text_color = "black"; GAF_link_color = "green"; GAF_title_color = "blue"; //--></script> <script src="http://www.getafreelancer.com/widgets/projects/vertical.js"></script> <div id="GAF_projects_vertical_box" style="width: 230px;padding: 0px; font-family:sans-serif; font-size: 12px;"> <div style="padding: 5px; overflow: hidden"> <div style="padding-bottom: 4px"><div style="float:right"><a href="http://www.getafreelancer.com/widgets/"><img src="http://www.getafreelancer.com/img/widgets/duder.png" alt="Make Money Now" height=30 border=0></a></div> <a href="http://www.getafreelancer.com/" target="_blank"><font color="blue" style="text-decoration: none">Freelance jobs</font></a> on <b><a href="http://www.getafreelancer.com/" target="_blank"><font color="blue">Freelancer.com</font></a></b> </div> <div id="GAF_projects_vertical"> </div> </div> <div align="right"> Find more <a href="http://www.getafreelancer.com/sellers/" target="_blank">freelance jobs</a></div> </div> <script src="http://api.getafreelancer.com/Project/Search.json?aff=320338&callback=GAF_update_projects_vertical_callback&order=rand&count=5&iads=true&nonpublic=0&charset=UTF-8"></script> <!-- End of Freelancer.com Affiliates Widget -->
文章分类
my app
存档

原创  猴子选大王的四种VB解法 收藏

题目:

一堆猴子编号依次是1,2,3 ...n ,这群猴子(n个)按照1到n的顺序围坐一圈,从第1开始报数,报双数的猴子离开此圈,这样依次下来,直到圈中只剩下最后一只猴子,则该猴子为大王。

解法:

1.集合的方法(O(2N)):

2.直接循环取模(O(N)):

3.递归(O(LOG N)):

4. 公式:

以上四种方法不仅代码越来越短,而且效率越来越高.

发表于 @ 2009年02月10日 15:30:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇:The Recent Ten Years | 新一篇:Nine-digit Fractions(II)

  • 发表评论
  • 评论内容:
  •  
Copyright © northwolves
Powered by CSDN Blog