﻿<?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++博客-oral+cpp+algorithm-随笔分类-算法</title><link>http://www.cppblog.com/zhuimengboy65/category/8588.html</link><description>从吐丝结茧到破茧而出</description><language>zh-cn</language><lastBuildDate>Sat, 29 May 2010 21:04:18 GMT</lastBuildDate><pubDate>Sat, 29 May 2010 21:04:18 GMT</pubDate><ttl>60</ttl><item><title>把自1970年1月1日以来的秒数转化成年月日</title><link>http://www.cppblog.com/zhuimengboy65/archive/2010/05/29/116684.html</link><dc:creator>春天</dc:creator><author>春天</author><pubDate>Sat, 29 May 2010 05:54:00 GMT</pubDate><guid>http://www.cppblog.com/zhuimengboy65/archive/2010/05/29/116684.html</guid><wfw:comment>http://www.cppblog.com/zhuimengboy65/comments/116684.html</wfw:comment><comments>http://www.cppblog.com/zhuimengboy65/archive/2010/05/29/116684.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhuimengboy65/comments/commentRss/116684.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhuimengboy65/services/trackbacks/116684.html</trackback:ping><description><![CDATA[<p>#include &lt;iostream&gt;<br>using namespace std;</p>
<p>bool IsRound(int year){<br>&nbsp;if((year%100)&amp;&amp;(year%4==0)) return 1;<br>&nbsp;if((year%100==0)&amp;&amp;(year%400==0)) return 1;<br>&nbsp;return 0;<br>}<br>int main() {<br>&nbsp;int n;<br>&nbsp;int year_s[2]= {365*24*60*60, 366*24*60*60};<br>&nbsp;int month_s[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},<br>&nbsp;&nbsp;&nbsp;{31,29,31,30,31,30,31,31,30,31,30,31}};<br>&nbsp;int day_s = 24*60*60;<br>&nbsp;int hour_s = 60*60;<br>&nbsp;int minute_s = 60;</p>
<p>&nbsp;</p>
<p>&nbsp;while(cin&gt;&gt;n){<br>&nbsp;&nbsp;&nbsp; int temp = n;<br>&nbsp;&nbsp;&nbsp; int year=1970;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; int month=1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; int day=1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; int hour=0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; int minute=0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; int second=0;</p>
<p>&nbsp;&nbsp;&nbsp; while(temp&gt;=60){</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; int flag= IsRound(year);<br>&nbsp;&nbsp;&nbsp;&nbsp; if(temp&gt;=year_s[flag]) { year++; temp-=year_s[flag]; }<br>&nbsp;&nbsp;&nbsp;&nbsp; else if(temp&gt;=day_s){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int days = temp/day_s;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp=temp%day_s;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int flag = IsRound(year);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int hh=31;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(days&gt;=hh){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; days-=month_s[flag][i++];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; hh=month_s[flag][i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; month+= i;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; day+=days;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; }else if(temp&gt;=hour_s){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hour=temp/hour_s;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp%=hour_s;<br>&nbsp;&nbsp;&nbsp;&nbsp; }else if(temp&gt;=minute_s){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; minute = temp/minute_s;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp%=minute_s;<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp; second = temp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout&lt;&lt;year&lt;&lt;"-";<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;if(month/10==0) cout&lt;&lt;"0";<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;cout&lt;&lt;month&lt;&lt;"-";<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;if(day/10==0) cout&lt;&lt;"0";<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;cout&lt;&lt;day&lt;&lt;" ";<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;if(hour/10==0) cout&lt;&lt;"0";<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;cout&lt;&lt;hour&lt;&lt;":";<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;if(minute/10==0) cout&lt;&lt;"0";<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;cout&lt;&lt;minute&lt;&lt;":";<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;if(second/10==0) cout&lt;&lt;"0";<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;cout&lt;&lt;second&lt;&lt;endl;<br>&nbsp;}</p>
<p><br>&nbsp;return 0;<br>}<br></p>
<img src ="http://www.cppblog.com/zhuimengboy65/aggbug/116684.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhuimengboy65/" target="_blank">春天</a> 2010-05-29 13:54 <a href="http://www.cppblog.com/zhuimengboy65/archive/2010/05/29/116684.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DFS,BFS,DFS+ID</title><link>http://www.cppblog.com/zhuimengboy65/archive/2008/10/22/64723.html</link><dc:creator>春天</dc:creator><author>春天</author><pubDate>Wed, 22 Oct 2008 11:02:00 GMT</pubDate><guid>http://www.cppblog.com/zhuimengboy65/archive/2008/10/22/64723.html</guid><wfw:comment>http://www.cppblog.com/zhuimengboy65/comments/64723.html</wfw:comment><comments>http://www.cppblog.com/zhuimengboy65/archive/2008/10/22/64723.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhuimengboy65/comments/commentRss/64723.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhuimengboy65/services/trackbacks/64723.html</trackback:ping><description><![CDATA[In a Nutshell
Search Time Space When to use<br>&nbsp; &nbsp; DFS O(c k) O(k) Must search tree anyway, know the level the answers are on, or you aren't looking for the shallowest number. <br>&nbsp;&nbsp;&nbsp; BFS O(c d ) O(c d ) Know answers are very near top of tree, or want shallowest answer.<br>&nbsp; &nbsp; DFS+ID O(c d) O(d) Want to do BFS, don't have enough space, and can spare the time.
<br>d is the depth of the answer
k is the depth searched
d &lt;= k
Remember the ordering properties of each search. If the program needs to produce a list sorted shortest solution first (in terms of distance from the root node), use breadth first search or iterative deepening. For other orders, depth first search is the right strategy.
If there isn't enough time to search the entire tree, use the algorithm that is more likely to find the answer. If the answer is expected to be in one of the rows of nodes closest to the root, use breadth first search or iterative deepening. Conversely, if the answer is expected to be in the leaves, use the simpler depth first search.
Be sure to keep space constraints in mind. If memory is insufficient to maintain the queue for breadth first search but time is available, use iterative deepening. <br>&nbsp;&nbsp;&nbsp; quote from http://ace.delos.com/usacotext2?a=y9SZdbB6WeB&amp;S=rec <img src ="http://www.cppblog.com/zhuimengboy65/aggbug/64723.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhuimengboy65/" target="_blank">春天</a> 2008-10-22 19:02 <a href="http://www.cppblog.com/zhuimengboy65/archive/2008/10/22/64723.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>