﻿<?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++博客-&amp;豪-随笔分类-算法&amp;ACM</title><link>http://www.cppblog.com/qywyh/category/885.html</link><description>豪-&gt;blog</description><language>zh-cn</language><lastBuildDate>Thu, 12 Aug 2010 17:39:26 GMT</lastBuildDate><pubDate>Thu, 12 Aug 2010 17:39:26 GMT</pubDate><ttl>60</ttl><item><title>用stl打spfa短了1k代码，慢了200ms</title><link>http://www.cppblog.com/qywyh/archive/2007/11/03/35809.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 03 Nov 2007 08:40:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/11/03/35809.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/35809.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/11/03/35809.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/35809.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/35809.html</trackback:ping><description><![CDATA[<p>&nbsp;原来用stl的优先队列这么爽，比赛时候多用，heap太容易打错了，毕竟没ghost_wei那么bt(heap,就几行,都打烂了-_-)<br><br>pku3159:</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">queue</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;INF&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">28</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MAXN&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">30010</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_141_300_Open_Image onclick="this.style.display='none'; Codehighlighter1_141_300_Open_Text.style.display='none'; Codehighlighter1_141_300_Closed_Image.style.display='inline'; Codehighlighter1_141_300_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_141_300_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_141_300_Closed_Text.style.display='none'; Codehighlighter1_141_300_Open_Image.style.display='inline'; Codehighlighter1_141_300_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;PQNode&nbsp;</span><span id=Codehighlighter1_141_300_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_141_300_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;u,&nbsp;key;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">pq默认用&lt;判断优先级,key大优先,若要key小优先,则加上!或&lt;改成&gt;即可</span><span style="COLOR: #008000"><br><img id=Codehighlighter1_265_292_Open_Image onclick="this.style.display='none'; Codehighlighter1_265_292_Open_Text.style.display='none'; Codehighlighter1_265_292_Closed_Image.style.display='inline'; Codehighlighter1_265_292_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_265_292_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_265_292_Closed_Text.style.display='none'; Codehighlighter1_265_292_Open_Image.style.display='inline'; Codehighlighter1_265_292_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;friend&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;PQNode&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a,&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;PQNode&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b)&nbsp;</span><span id=Codehighlighter1_265_292_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_265_292_Open_Text><span style="COLOR: #000000">{&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">(a.key&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;b.key);&nbsp;}</span></span><span style="COLOR: #000000">&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,&nbsp;m;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>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;adjv[MAXN],&nbsp;adjw[MAXN];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_383_1098_Open_Image onclick="this.style.display='none'; Codehighlighter1_383_1098_Open_Text.style.display='none'; Codehighlighter1_383_1098_Closed_Image.style.display='inline'; Codehighlighter1_383_1098_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_383_1098_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_383_1098_Closed_Text.style.display='none'; Codehighlighter1_383_1098_Open_Image.style.display='inline'; Codehighlighter1_383_1098_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;dijkstraPQ(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;st,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;en)&nbsp;</span><span id=Codehighlighter1_383_1098_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_383_1098_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;v,&nbsp;w,&nbsp;dist[MAXN],&nbsp;chk[MAXN];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;priority_queue</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">PQNode</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;pq;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;PQNode&nbsp;tmp,&nbsp;cp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;memset(chk,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(chk));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;dist[i]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;INF;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;dist[st]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;tmp.u&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;st;&nbsp;tmp.key&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 src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;pq.push(tmp);<br><img id=Codehighlighter1_640_1081_Open_Image onclick="this.style.display='none'; Codehighlighter1_640_1081_Open_Text.style.display='none'; Codehighlighter1_640_1081_Closed_Image.style.display='inline'; Codehighlighter1_640_1081_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_640_1081_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_640_1081_Closed_Text.style.display='none'; Codehighlighter1_640_1081_Open_Image.style.display='inline'; Codehighlighter1_640_1081_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">pq.empty())&nbsp;</span><span id=Codehighlighter1_640_1081_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_640_1081_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cp&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pq.top();<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pq.pop();<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(cp.u&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;en)&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;dist[en];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(chk[cp.u])&nbsp;</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chk[cp.u]&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 id=Codehighlighter1_824_1075_Open_Image onclick="this.style.display='none'; Codehighlighter1_824_1075_Open_Text.style.display='none'; Codehighlighter1_824_1075_Closed_Image.style.display='inline'; Codehighlighter1_824_1075_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_824_1075_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_824_1075_Closed_Text.style.display='none'; Codehighlighter1_824_1075_Open_Image.style.display='inline'; Codehighlighter1_824_1075_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">adjv[cp.u].size();&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span id=Codehighlighter1_824_1075_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_824_1075_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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;adjv[cp.u][i];&nbsp;w&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;adjw[cp.u][i];<br><img id=Codehighlighter1_939_1065_Open_Image onclick="this.style.display='none'; Codehighlighter1_939_1065_Open_Text.style.display='none'; Codehighlighter1_939_1065_Closed_Image.style.display='inline'; Codehighlighter1_939_1065_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_939_1065_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_939_1065_Closed_Text.style.display='none'; Codehighlighter1_939_1065_Open_Image.style.display='inline'; Codehighlighter1_939_1065_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">chk[v]&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;(dist[v]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">INF&nbsp;</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">&nbsp;dist[v]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">cp.key</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">w))&nbsp;</span><span id=Codehighlighter1_939_1065_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_939_1065_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dist[v]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;cp.key</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">w;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp.u&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;v;&nbsp;tmp.key&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;dist[v];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pq.push(tmp);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_1112_1407_Open_Image onclick="this.style.display='none'; Codehighlighter1_1112_1407_Open_Text.style.display='none'; Codehighlighter1_1112_1407_Closed_Image.style.display='inline'; Codehighlighter1_1112_1407_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_1112_1407_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1112_1407_Closed_Text.style.display='none'; Codehighlighter1_1112_1407_Open_Image.style.display='inline'; Codehighlighter1_1112_1407_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;</span><span id=Codehighlighter1_1112_1407_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1112_1407_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;j,&nbsp;k,&nbsp;u,&nbsp;v,&nbsp;w;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;freopen(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">input.txt</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">r</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;stdin);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d%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">m);<br><img id=Codehighlighter1_1229_1350_Open_Image onclick="this.style.display='none'; Codehighlighter1_1229_1350_Open_Text.style.display='none'; Codehighlighter1_1229_1350_Closed_Image.style.display='inline'; Codehighlighter1_1229_1350_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1229_1350_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1229_1350_Closed_Text.style.display='none'; Codehighlighter1_1229_1350_Open_Image.style.display='inline'; Codehighlighter1_1229_1350_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">m;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span id=Codehighlighter1_1229_1350_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1229_1350_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d%d%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">u,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">v,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">w);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;&nbsp;v</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adjv[u].push_back(v);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adjw[u].push_back(w);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;dijkstraPQ(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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 src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<img src ="http://www.cppblog.com/qywyh/aggbug/35809.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-11-03 16:40 <a href="http://www.cppblog.com/qywyh/archive/2007/11/03/35809.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>三次样条插值</title><link>http://www.cppblog.com/qywyh/archive/2007/10/20/34674.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 20 Oct 2007 05:07:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/10/20/34674.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/34674.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/10/20/34674.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/34674.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/34674.html</trackback:ping><description><![CDATA[<p>具体推导看书&lt;&lt;数值分析&gt;&gt;<br>code：<br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MAXN&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;x[MAXN],&nbsp;y[MAXN];&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">下标从0..n</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;alph[MAXN],&nbsp;beta[MAXN],&nbsp;a[MAXN],&nbsp;b[MAXN];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;h[MAXN];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;m[MAXN];&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">各点的一阶导数;</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_229_251_Open_Image onclick="this.style.display='none'; Codehighlighter1_229_251_Open_Text.style.display='none'; Codehighlighter1_229_251_Closed_Image.style.display='inline'; Codehighlighter1_229_251_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_229_251_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_229_251_Closed_Text.style.display='none'; Codehighlighter1_229_251_Open_Image.style.display='inline'; Codehighlighter1_229_251_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>inline&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;sqr(</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;pa)&nbsp;</span><span id=Codehighlighter1_229_251_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_229_251_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;pa&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;pa;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_283_647_Open_Image onclick="this.style.display='none'; Codehighlighter1_283_647_Open_Text.style.display='none'; Codehighlighter1_283_647_Closed_Image.style.display='inline'; Codehighlighter1_283_647_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_283_647_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_283_647_Closed_Text.style.display='none'; Codehighlighter1_283_647_Open_Image.style.display='inline'; Codehighlighter1_283_647_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;sunc(</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;p,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i)&nbsp;</span><span id=Codehighlighter1_283_647_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_283_647_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&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;(p&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[i])&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;(x[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;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[i]))&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;sqr((p&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[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;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;(x[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;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[i]))&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;y[i]<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&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;(p&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[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;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;(x[i]&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[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;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;sqr((p&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[i])&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;(x[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;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[i]))&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;y[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 src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;(p&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[i])&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;sqr((p&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[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;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;(x[i]&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[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;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;m[i]<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;(p&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[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;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;sqr((p&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[i])&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;(x[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;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[i]))&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;m[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 src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_661_1796_Open_Image onclick="this.style.display='none'; Codehighlighter1_661_1796_Open_Text.style.display='none'; Codehighlighter1_661_1796_Closed_Image.style.display='inline'; Codehighlighter1_661_1796_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_661_1796_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_661_1796_Closed_Text.style.display='none'; Codehighlighter1_661_1796_Open_Image.style.display='inline'; Codehighlighter1_661_1796_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;</span><span id=Codehighlighter1_661_1796_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_661_1796_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;j;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;xx;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;freopen(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">threeInsert.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">r</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;stdin);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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 src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(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;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%lf%lf</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">x[i],&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">y[i]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;scanf("%lf%lf",&nbsp;&amp;m[0],&nbsp;&amp;m[n]);</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(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;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;h[i]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;x[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;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;x[i];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">第一种边界条件<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">alph[0]&nbsp;=&nbsp;0;&nbsp;alph[n]&nbsp;=&nbsp;1;&nbsp;beta[0]&nbsp;=&nbsp;2&nbsp;*&nbsp;m[0];&nbsp;beta[n]&nbsp;=&nbsp;2&nbsp;*&nbsp;m[n];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">第二种边界条件</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;alph[</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">1</span><span style="COLOR: #000000">;&nbsp;alph[n]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;beta[</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">3</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;(y[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;y[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;h[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];&nbsp;beta[n]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;(y[n]&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;y[n&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;h[n&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 id=Codehighlighter1_1154_1315_Open_Image onclick="this.style.display='none'; Codehighlighter1_1154_1315_Open_Text.style.display='none'; Codehighlighter1_1154_1315_Closed_Image.style.display='inline'; Codehighlighter1_1154_1315_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1154_1315_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1154_1315_Closed_Text.style.display='none'; Codehighlighter1_1154_1315_Open_Image.style.display='inline'; Codehighlighter1_1154_1315_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(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;n&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</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span id=Codehighlighter1_1154_1315_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1154_1315_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alph[i]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;h[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;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;(h[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;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;h[i]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;beta[i]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;((</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;alph[i])&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;(y[i]&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;y[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;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;h[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;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;alph[i]&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;(y[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;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;y[i])&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;h[i]);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;a[</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">&nbsp;alph[</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">2</span><span style="COLOR: #000000">;&nbsp;b[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;beta[</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">2</span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_1392_1543_Open_Image onclick="this.style.display='none'; Codehighlighter1_1392_1543_Open_Text.style.display='none'; Codehighlighter1_1392_1543_Closed_Image.style.display='inline'; Codehighlighter1_1392_1543_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1392_1543_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1392_1543_Closed_Text.style.display='none'; Codehighlighter1_1392_1543_Open_Image.style.display='inline'; Codehighlighter1_1392_1543_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(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;n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span id=Codehighlighter1_1392_1543_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1392_1543_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;alph[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;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;alph[i])&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;a[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 src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b[i]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(beta[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;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;alph[i])&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;b[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;</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;(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;alph[i])&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;a[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 src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;m[n&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&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_1592_1637_Open_Image onclick="this.style.display='none'; Codehighlighter1_1592_1637_Open_Text.style.display='none'; Codehighlighter1_1592_1637_Closed_Image.style.display='inline'; Codehighlighter1_1592_1637_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1592_1637_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1592_1637_Closed_Text.style.display='none'; Codehighlighter1_1592_1637_Open_Image.style.display='inline'; Codehighlighter1_1592_1637_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;n;&nbsp;i&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;i</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)&nbsp;</span><span id=Codehighlighter1_1592_1637_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1592_1637_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m[i]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;a[i]&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;m[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;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;b[i];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%lf</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">xx);<br><img id=Codehighlighter1_1690_1745_Open_Image onclick="this.style.display='none'; Codehighlighter1_1690_1745_Open_Text.style.display='none'; Codehighlighter1_1690_1745_Closed_Image.style.display='inline'; Codehighlighter1_1690_1745_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1690_1745_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1690_1745_Closed_Text.style.display='none'; Codehighlighter1_1690_1745_Open_Image.style.display='inline'; Codehighlighter1_1690_1745_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(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 id=Codehighlighter1_1690_1745_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1690_1745_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(xx&nbsp;</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">&nbsp;x[i]&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;xx&nbsp;</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">&nbsp;x[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;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%lf\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;sunc(xx,&nbsp;i));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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 src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000">&nbsp;</span></div>
<img src ="http://www.cppblog.com/qywyh/aggbug/34674.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-10-20 13:07 <a href="http://www.cppblog.com/qywyh/archive/2007/10/20/34674.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>龙贝格积分2457jlu</title><link>http://www.cppblog.com/qywyh/archive/2007/10/20/34658.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Fri, 19 Oct 2007 17:02:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/10/20/34658.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/34658.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/10/20/34658.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/34658.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/34658.html</trackback:ping><description><![CDATA[Sailboat
<hr>
<div class=prob_text twffan="done">
<h2>Problem H: Sailboat</h2>
<p>In the sailboat race, the contestant is requested to along with the prearrange path. Sailing ship's power comes from wind power and contestant's manpower. The wind power can completely used.</p>
<p>In a competition, the contestants are requested to along with a 1/4 circles with radius R, the sailboat will goto east from south. During this process, the wind direction is straight from west to the east with constant speed and power.</p>
<p>In order to maintain the travel direction, the athlete must adjust the sail to the vertical angle from movement direction in any time.</p>
<p align=center><img src="http://acm.jlu.edu.cn/joj/images/problems/2457_1.jpg" twffan="done"></p>
<p>If the speed of sailboat is proportional to the power at movement direction, the proportional factor is <em>k</em>. Supposes the wind power is <em>f</em>, the athlete manpower is <em>h</em>, please given the time of sailboat from the beginning to the end.</p>
<h3>Input</h3>
<p>The first line of each case consists of 4 double number, that is radius of path: <em>R</em>, wind power: <em>f</em>,athlete manpower: <em>h</em> and proportional factor:<em>k</em>. In order to avoid the floating point error, you needn't output the answer directly. The next line is a integer n, the following n lines gives a double value which is candidate answer. </p>
<h3>Output</h3>
<p>For each candidate of each case, Only "Yes" or "No" should be printed. Output "Yes" if the relative error to your answer is less than 3%, otherwise "No". For example, if the model answer is 100, and the candidate is 98 or 102, you should output "Yes". Output one blank line between neighboring case</p>
<h3>Sample Input</h3>
<pre>1.0 2.0 1.0 1.0
2
0.35
0.76
</pre>
<h3>Sample Output</h3>
<pre>No
Yes
</pre>
</div>
<p class=prob_src>
<p><em><strong>Problem Source:</strong> provided by skywind</em></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee" twffan="done"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><span style="COLOR: #000000" twffan="done">#include&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">iostream</span><span style="COLOR: #000000" twffan="done">&gt;</span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done">#include&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">cmath</span><span style="COLOR: #000000" twffan="done">&gt;</span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">using</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #0000ff" twffan="done">namespace</span><span style="COLOR: #000000" twffan="done">&nbsp;std;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">const</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;MAXN&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">100</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">const</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #0000ff" twffan="done">double</span><span style="COLOR: #000000" twffan="done">&nbsp;PI&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;acos(</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">1.0</span><span style="COLOR: #000000" twffan="done">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">double</span><span style="COLOR: #000000" twffan="done">&nbsp;R,&nbsp;F,&nbsp;H,&nbsp;K,&nbsp;ans;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;n,&nbsp;cas;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img id=Codehighlighter1_171_210_Open_Image onclick="this.style.display='none'; Codehighlighter1_171_210_Open_Text.style.display='none'; Codehighlighter1_171_210_Closed_Image.style.display='inline'; Codehighlighter1_171_210_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_171_210_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_171_210_Closed_Text.style.display='none'; Codehighlighter1_171_210_Open_Image.style.display='inline'; Codehighlighter1_171_210_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">double</span><span style="COLOR: #000000" twffan="done">&nbsp;func(</span><span style="COLOR: #0000ff" twffan="done">double</span><span style="COLOR: #000000" twffan="done">&nbsp;x)&nbsp;</span><span id=Codehighlighter1_171_210_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_171_210_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">return</span><span style="COLOR: #000000" twffan="done">&nbsp;R&nbsp;</span><span style="COLOR: #000000" twffan="done">/</span><span style="COLOR: #000000" twffan="done">&nbsp;K&nbsp;</span><span style="COLOR: #000000" twffan="done">/</span><span style="COLOR: #000000" twffan="done">&nbsp;(H&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;F&nbsp;</span><span style="COLOR: #000000" twffan="done">*</span><span style="COLOR: #000000" twffan="done">&nbsp;cos(x));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top twffan="done">}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img id=Codehighlighter1_267_848_Open_Image onclick="this.style.display='none'; Codehighlighter1_267_848_Open_Text.style.display='none'; Codehighlighter1_267_848_Closed_Image.style.display='inline'; Codehighlighter1_267_848_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_267_848_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_267_848_Closed_Text.style.display='none'; Codehighlighter1_267_848_Open_Image.style.display='inline'; Codehighlighter1_267_848_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">double</span><span style="COLOR: #000000" twffan="done">&nbsp;romberg(</span><span style="COLOR: #0000ff" twffan="done">double</span><span style="COLOR: #000000" twffan="done">&nbsp;a,&nbsp;</span><span style="COLOR: #0000ff" twffan="done">double</span><span style="COLOR: #000000" twffan="done">&nbsp;b,&nbsp;</span><span style="COLOR: #0000ff" twffan="done">double</span><span style="COLOR: #000000" twffan="done">&nbsp;EPS&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;1e</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">6</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_267_848_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_267_848_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img id=Codehighlighter1_296_298_Open_Image onclick="this.style.display='none'; Codehighlighter1_296_298_Open_Text.style.display='none'; Codehighlighter1_296_298_Closed_Image.style.display='inline'; Codehighlighter1_296_298_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_296_298_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_296_298_Closed_Text.style.display='none'; Codehighlighter1_296_298_Open_Image.style.display='inline'; Codehighlighter1_296_298_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">double</span><span style="COLOR: #000000" twffan="done">&nbsp;t[MAXN][MAXN]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span id=Codehighlighter1_296_298_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_296_298_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">}</span></span><span style="COLOR: #000000" twffan="done">,&nbsp;tmp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;i,&nbsp;j,&nbsp;k,&nbsp;k2,&nbsp;m,&nbsp;m4;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;t[</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">][</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;(func(a)&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;func(b))&nbsp;</span><span style="COLOR: #000000" twffan="done">*</span><span style="COLOR: #000000" twffan="done">&nbsp;(b&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;a)&nbsp;</span><span style="COLOR: #000000" twffan="done">/</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">2</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;k&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;&nbsp;k2&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;<br><img id=Codehighlighter1_416_826_Open_Image onclick="this.style.display='none'; Codehighlighter1_416_826_Open_Text.style.display='none'; Codehighlighter1_416_826_Closed_Image.style.display='inline'; Codehighlighter1_416_826_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_416_826_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_416_826_Closed_Text.style.display='none'; Codehighlighter1_416_826_Open_Image.style.display='inline'; Codehighlighter1_416_826_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">while</span><span style="COLOR: #000000" twffan="done">&nbsp;(</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_416_826_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_416_826_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;<br><img id=Codehighlighter1_470_543_Open_Image onclick="this.style.display='none'; Codehighlighter1_470_543_Open_Text.style.display='none'; Codehighlighter1_470_543_Closed_Image.style.display='inline'; Codehighlighter1_470_543_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_470_543_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_470_543_Closed_Text.style.display='none'; Codehighlighter1_470_543_Open_Image.style.display='inline'; Codehighlighter1_470_543_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(i&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">;&nbsp;i&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">&nbsp;k2;&nbsp;i</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_470_543_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_470_543_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp&nbsp;</span><span style="COLOR: #000000" twffan="done">+=</span><span style="COLOR: #000000" twffan="done">&nbsp;func(a&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;(</span><span style="COLOR: #000000" twffan="done">2</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">*</span><span style="COLOR: #000000" twffan="done">&nbsp;i&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span style="COLOR: #000000" twffan="done">*</span><span style="COLOR: #000000" twffan="done">&nbsp;(b&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;a)&nbsp;</span><span style="COLOR: #000000" twffan="done">/</span><span style="COLOR: #000000" twffan="done">&nbsp;(</span><span style="COLOR: #000000" twffan="done">2</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">*</span><span style="COLOR: #000000" twffan="done">&nbsp;k2));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t[</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">][k]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;(t[</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">][k&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">]&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;tmp&nbsp;</span><span style="COLOR: #000000" twffan="done">*</span><span style="COLOR: #000000" twffan="done">&nbsp;(b&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;a)&nbsp;</span><span style="COLOR: #000000" twffan="done">/</span><span style="COLOR: #000000" twffan="done">&nbsp;k2)&nbsp;</span><span style="COLOR: #000000" twffan="done">/</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">2</span><span style="COLOR: #000000" twffan="done">;<br><img id=Codehighlighter1_651_744_Open_Image onclick="this.style.display='none'; Codehighlighter1_651_744_Open_Text.style.display='none'; Codehighlighter1_651_744_Closed_Image.style.display='inline'; Codehighlighter1_651_744_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_651_744_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_651_744_Closed_Text.style.display='none'; Codehighlighter1_651_744_Open_Image.style.display='inline'; Codehighlighter1_651_744_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">for</span><span style="COLOR: #000000" twffan="done">&nbsp;(m&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">,&nbsp;m4</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">4</span><span style="COLOR: #000000" twffan="done">;&nbsp;m&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;=</span><span style="COLOR: #000000" twffan="done">&nbsp;k;&nbsp;m</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">,&nbsp;m4&nbsp;</span><span style="COLOR: #000000" twffan="done">*=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">4</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_651_744_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_651_744_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t[m][k&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;m]&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;(m4&nbsp;</span><span style="COLOR: #000000" twffan="done">*</span><span style="COLOR: #000000" twffan="done">&nbsp;t[m&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">][k&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;m&nbsp;</span><span style="COLOR: #000000" twffan="done">+</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">]&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;t[m&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">][k&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;m])&nbsp;</span><span style="COLOR: #000000" twffan="done">/</span><span style="COLOR: #000000" twffan="done">&nbsp;(m4&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(fabs(t[k][</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">]&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;t[k&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">1</span><span style="COLOR: #000000" twffan="done">][</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">])&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">&nbsp;EPS)&nbsp;</span><span style="COLOR: #0000ff" twffan="done">break</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">;&nbsp;k2&nbsp;</span><span style="COLOR: #000000" twffan="done">*=</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">2</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">return</span><span style="COLOR: #000000" twffan="done">&nbsp;t[k][</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top twffan="done">}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img id=Codehighlighter1_864_988_Open_Image onclick="this.style.display='none'; Codehighlighter1_864_988_Open_Text.style.display='none'; Codehighlighter1_864_988_Closed_Image.style.display='inline'; Codehighlighter1_864_988_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_864_988_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_864_988_Closed_Text.style.display='none'; Codehighlighter1_864_988_Open_Image.style.display='inline'; Codehighlighter1_864_988_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">void</span><span style="COLOR: #000000" twffan="done">&nbsp;solve()&nbsp;</span><span id=Codehighlighter1_864_988_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_864_988_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">double</span><span style="COLOR: #000000" twffan="done">&nbsp;tmp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">%lf</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">tmp);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(fabs(tmp&nbsp;</span><span style="COLOR: #000000" twffan="done">-</span><span style="COLOR: #000000" twffan="done">&nbsp;ans)&nbsp;</span><span style="COLOR: #000000" twffan="done">/</span><span style="COLOR: #000000" twffan="done">&nbsp;ans&nbsp;</span><span style="COLOR: #000000" twffan="done">&lt;</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0.03</span><span style="COLOR: #000000" twffan="done">)&nbsp;printf(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">Yes\n</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">else</span><span style="COLOR: #000000" twffan="done">&nbsp;printf(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">No\n</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top twffan="done">}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top twffan="done"><br><img id=Codehighlighter1_1002_1262_Open_Image onclick="this.style.display='none'; Codehighlighter1_1002_1262_Open_Text.style.display='none'; Codehighlighter1_1002_1262_Closed_Image.style.display='inline'; Codehighlighter1_1002_1262_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_1002_1262_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1002_1262_Closed_Text.style.display='none'; Codehighlighter1_1002_1262_Open_Image.style.display='inline'; Codehighlighter1_1002_1262_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top twffan="done"></span><span style="COLOR: #0000ff" twffan="done">int</span><span style="COLOR: #000000" twffan="done">&nbsp;main()&nbsp;</span><span id=Codehighlighter1_1002_1262_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_1002_1262_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;freopen(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">2457.in</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">,&nbsp;</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">r</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">,&nbsp;stdin);<br><img id=Codehighlighter1_1103_1246_Open_Image onclick="this.style.display='none'; Codehighlighter1_1103_1246_Open_Text.style.display='none'; Codehighlighter1_1103_1246_Closed_Image.style.display='inline'; Codehighlighter1_1103_1246_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_1103_1246_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1103_1246_Closed_Text.style.display='none'; Codehighlighter1_1103_1246_Open_Image.style.display='inline'; Codehighlighter1_1103_1246_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">while</span><span style="COLOR: #000000" twffan="done">&nbsp;(scanf(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">%lf%lf%lf%lf%d</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">R,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">F,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">H,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">K,&nbsp;</span><span style="COLOR: #000000" twffan="done">&amp;</span><span style="COLOR: #000000" twffan="done">n)&nbsp;</span><span style="COLOR: #000000" twffan="done">!=</span><span style="COLOR: #000000" twffan="done">&nbsp;EOF)&nbsp;</span><span id=Codehighlighter1_1103_1246_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_1103_1246_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">if</span><span style="COLOR: #000000" twffan="done">&nbsp;(cas)&nbsp;printf(</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">\n</span><span style="COLOR: #000000" twffan="done">"</span><span style="COLOR: #000000" twffan="done">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">else</span><span style="COLOR: #000000" twffan="done">&nbsp;cas</span><span style="COLOR: #000000" twffan="done">++</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="COLOR: #000000" twffan="done">=</span><span style="COLOR: #000000" twffan="done">&nbsp;romberg(</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">,&nbsp;PI</span><span style="COLOR: #000000" twffan="done">/</span><span style="COLOR: #000000" twffan="done">2</span><span style="COLOR: #000000" twffan="done">);<br><img id=Codehighlighter1_1209_1240_Open_Image onclick="this.style.display='none'; Codehighlighter1_1209_1240_Open_Text.style.display='none'; Codehighlighter1_1209_1240_Closed_Image.style.display='inline'; Codehighlighter1_1209_1240_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top twffan="done"><img id=Codehighlighter1_1209_1240_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1209_1240_Closed_Text.style.display='none'; Codehighlighter1_1209_1240_Open_Image.style.display='inline'; Codehighlighter1_1209_1240_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">while</span><span style="COLOR: #000000" twffan="done">&nbsp;(n</span><span style="COLOR: #000000" twffan="done">--</span><span style="COLOR: #000000" twffan="done">)&nbsp;</span><span id=Codehighlighter1_1209_1240_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff" twffan="done"><img src="http://www.cppblog.com/Images/dot.gif" twffan="done"></span><span id=Codehighlighter1_1209_1240_Open_Text twffan="done"><span style="COLOR: #000000" twffan="done">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;solve();<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000" twffan="done"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top twffan="done">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff" twffan="done">return</span><span style="COLOR: #000000" twffan="done">&nbsp;</span><span style="COLOR: #000000" twffan="done">0</span><span style="COLOR: #000000" twffan="done">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top twffan="done">}</span></span></div>
<img src ="http://www.cppblog.com/qywyh/aggbug/34658.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-10-20 01:02 <a href="http://www.cppblog.com/qywyh/archive/2007/10/20/34658.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>三分法求函数极值buaa1024</title><link>http://www.cppblog.com/qywyh/archive/2007/10/18/34522.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Thu, 18 Oct 2007 03:00:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/10/18/34522.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/34522.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/10/18/34522.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/34522.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/34522.html</trackback:ping><description><![CDATA[<h2>Easy Problem</h2>
<div>
<div><font color=blue>Time limit:</font>1000 ms &nbsp; <font color=blue>Memory limit:</font>65536 KB </div>
<div><font color=blue>Total Submit:</font>1755 (462 users) &nbsp; <font color=blue>Accepted Submit:</font>366 (332 users) </div>
</div>
<!-- don't add "<br>" here !!! -->
<div class=problem style="TEXT-ALIGN: left">
<h4>Description</h4>
In this problem, you're to calculate the distance between a point <em>P</em>(<em>x</em><sub><em>p</em></sub>, <em>y</em><sub><em>p</em></sub>, <em>z</em><sub><em>p</em></sub>)</span> and a segment (<em>x</em><sub>1</sub>, <em>y</em><sub>1</sub>, <em>z</em><sub>1</sub>) &#8722; (<em>x</em><sub>2</sub>, <em>y</em><sub>2</sub>, <em>z</em><sub>2</sub>)</span>, in a 3D space, i.e. the minimal distance from P to any point <em>Q</em>(<em>x</em><sub><em>q</em></sub>, <em>y</em><sub><em>q</em></sub>, <em>z</em><sub><em>q</em></sub>)</span> on the segment (a segment is part of a line).
<h4>Input</h4>
The first line contains a single integer T (1 &#8804; <em>T</em> &#8804; 1000), the number of test cases. Each test case is a single line containing 9 integers <em>x</em><sub><em>p</em></sub>, <em>y</em><sub><em>p</em></sub>, <em>z</em><sub><em>p</em></sub>, <em>x</em><sub>1</sub>, <em>y</em><sub>1</sub>, <em>z</em><sub>1</sub>, <em>x</em><sub>2</sub>, <em>y</em><sub>2</sub>, <em>z</em><sub>2</sub></span>. These integers are all in [-1000,1000].
<h4>Output</h4>
For each test case, print the case number and the minimal distance, to two decimal places.
<h4>Sample Input</h4>
<div class=sample_data id=sample_input>3 <br>0 0 0 0 1 0 1 1 0 <br>1 0 0 1 0 1 1 1 0 <br>-1 -1 -1 0 1 0 -1 0 -1 <br></div>
<h4>Sample Output</h4>
<div class=sample_data id=sample_output>Case 1: 1.00 <br>Case 2: 0.71 <br>Case 3: 1.00 <br></div>
<h4>Problem Source</h4>
The 32nd ACM-ICPC Beijing First Round Internet Contest </div>
<br>其实和二分差不多，划个函数曲线出来，分三段，比划一下就很容易理解了：）<br><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_95_187_Open_Image onclick="this.style.display='none'; Codehighlighter1_95_187_Open_Text.style.display='none'; Codehighlighter1_95_187_Closed_Image.style.display='inline'; Codehighlighter1_95_187_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_95_187_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_95_187_Closed_Text.style.display='none'; Codehighlighter1_95_187_Open_Image.style.display='inline'; Codehighlighter1_95_187_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;dist(</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;l[],&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;r[])&nbsp;</span><span id=Codehighlighter1_95_187_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_95_187_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;sqrt((l[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">r[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(l[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">r[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">(l[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">r[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(l[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">r[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">(l[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">r[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(l[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">r[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_201_1029_Open_Image onclick="this.style.display='none'; Codehighlighter1_201_1029_Open_Text.style.display='none'; Codehighlighter1_201_1029_Closed_Image.style.display='inline'; Codehighlighter1_201_1029_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_201_1029_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_201_1029_Closed_Text.style.display='none'; Codehighlighter1_201_1029_Open_Image.style.display='inline'; Codehighlighter1_201_1029_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;</span><span id=Codehighlighter1_201_1029_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_201_1029_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;freopen("1024.in",&nbsp;"r",&nbsp;stdin);</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,&nbsp;cas</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;l[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">],&nbsp;r[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">],&nbsp;p[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">],&nbsp;p1[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">],&nbsp;p2[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">],&nbsp;d1,&nbsp;d2;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&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 id=Codehighlighter1_347_1027_Open_Image onclick="this.style.display='none'; Codehighlighter1_347_1027_Open_Text.style.display='none'; Codehighlighter1_347_1027_Closed_Image.style.display='inline'; Codehighlighter1_347_1027_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_347_1027_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_347_1027_Closed_Text.style.display='none'; Codehighlighter1_347_1027_Open_Image.style.display='inline'; Codehighlighter1_347_1027_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">&nbsp;(n</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)&nbsp;</span><span id=Codehighlighter1_347_1027_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_347_1027_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%lf%lf%lf%lf%lf%lf%lf%lf%lf</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">p[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">],&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">p[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">],&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">p[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">],&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">l[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">],&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">l[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">],&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">l[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">],&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">r[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">],&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">r[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">],&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">r[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]);<br><img id=Codehighlighter1_492_966_Open_Image onclick="this.style.display='none'; Codehighlighter1_492_966_Open_Text.style.display='none'; Codehighlighter1_492_966_Closed_Image.style.display='inline'; Codehighlighter1_492_966_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_492_966_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_492_966_Closed_Text.style.display='none'; Codehighlighter1_492_966_Open_Image.style.display='inline'; Codehighlighter1_492_966_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">&nbsp;(dist(l,&nbsp;r)&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;1e</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">)&nbsp;</span><span id=Codehighlighter1_492_966_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_492_966_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p1[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(l[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;r[</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">2</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p1[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(l[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;r[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])&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 src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p1[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(l[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;r[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">])&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 src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p2[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(r[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;p1[</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">2</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p2[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(r[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;p1[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])&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 src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p2[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(r[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;p1[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">])&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 src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d1&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;dist(p1,&nbsp;p);&nbsp;d2&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;dist(p2,&nbsp;p);<br><img id=Codehighlighter1_805_877_Open_Image onclick="this.style.display='none'; Codehighlighter1_805_877_Open_Text.style.display='none'; Codehighlighter1_805_877_Closed_Image.style.display='inline'; Codehighlighter1_805_877_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_805_877_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_805_877_Closed_Text.style.display='none'; Codehighlighter1_805_877_Open_Image.style.display='inline'; Codehighlighter1_805_877_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(d2&nbsp;</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">&nbsp;d1)&nbsp;</span><span id=Codehighlighter1_805_877_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_805_877_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;p2[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];&nbsp;r[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;p2[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];&nbsp;r[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;p2[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">];<br><img id=Codehighlighter1_884_956_Open_Image onclick="this.style.display='none'; Codehighlighter1_884_956_Open_Text.style.display='none'; Codehighlighter1_884_956_Closed_Image.style.display='inline'; Codehighlighter1_884_956_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_884_956_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_884_956_Closed_Text.style.display='none'; Codehighlighter1_884_956_Open_Image.style.display='inline'; Codehighlighter1_884_956_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span id=Codehighlighter1_884_956_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_884_956_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;p1[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];&nbsp;l[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;p1[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];&nbsp;l[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;p1[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Case&nbsp;%d:&nbsp;%.2lf\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">cas,&nbsp;dist(p,l));<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span></div>
<br>
<img src ="http://www.cppblog.com/qywyh/aggbug/34522.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-10-18 11:00 <a href="http://www.cppblog.com/qywyh/archive/2007/10/18/34522.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>为了大作业报告好写点，重写了RBTree</title><link>http://www.cppblog.com/qywyh/archive/2007/09/23/32741.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sun, 23 Sep 2007 13:34:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/09/23/32741.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/32741.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/09/23/32741.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/32741.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/32741.html</trackback:ping><description><![CDATA[扩展了一点，有兴趣的可以去看看，MFC去，sigh~<br><a href="http://www.cppblog.com/qywyh/articles/32740.html">http://www.cppblog.com/qywyh/articles/32740.html</a><br>
<img src ="http://www.cppblog.com/qywyh/aggbug/32741.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-09-23 21:34 <a href="http://www.cppblog.com/qywyh/archive/2007/09/23/32741.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>扩展的欧拉函数 pku1091</title><link>http://www.cppblog.com/qywyh/archive/2007/09/02/31432.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sun, 02 Sep 2007 14:57:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/09/02/31432.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/31432.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/09/02/31432.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/31432.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/31432.html</trackback:ping><description><![CDATA[<p>欧拉函数一般形式: <br>当 n 为素数时: phi(n) = n-1<br>当 n 为合数时: phi(n) = n&#8719;(1-1/p) 其中(p为n的素数因子)<br><br>题目<a href="http://acm.pku.edu.cn/JudgeOnline/problem?id=1091" target=_blank>pku1091</a>，要求我们求 x1..xn,m这样的序列的个数，其中xi(1&lt;=i&lt;=n), 使 gcd(x1, ..,xn,m)=1;<br>我们按欧拉函数的形式猜想如下方程：<br>当 n 为素数时: phi(m,n) = m^n-1<br>当 n 为合数时: phi(m,n) = m^n&#8719;(1-1/p^n) 其中(p为n的素数因子)<br><br>不给出严格数学证明(不会-_-)，上两式具体含义：<br>当 n为素数 phi(m,n) = m^n-1&nbsp;显然成立<br>当 n 为合数时 可以假象有一个m进制n位的数，然后其中一位有m的约数p的概率为1/p, 则n位同时有p的约数的概率就为(1-1/p^n), 运用乘法原理，可以得式 phi(m,n) = m^n&#8719;(1-1/p^n)<br>&nbsp;<br>code:<br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>using&nbsp;namespace&nbsp;std;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>typedef&nbsp;__int64&nbsp;llong;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;llong&nbsp;MAXN&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">110000</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>llong&nbsp;tf[MAXN],&nbsp;su[MAXN],&nbsp;ns,&nbsp;num[MAXN],&nbsp;nn;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>void&nbsp;&nbsp;init()&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;llong&nbsp;i,&nbsp;j;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">MAXN;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(!tf[i])&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;su[ns</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">i;&nbsp;j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">MAXN;&nbsp;j</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">i)&nbsp;tf[j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>llong&nbsp;ppow(llong&nbsp;a,&nbsp;llong&nbsp;b)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;llong&nbsp;ret</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;llong&nbsp;i;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">b;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;ret&nbsp;</span><span style="COLOR: #000000">*=</span><span style="COLOR: #000000">&nbsp;a;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;ret;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;llong&nbsp;n,&nbsp;m,&nbsp;i,&nbsp;p;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;llong&nbsp;ans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;init();<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">&nbsp;(scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%I64d%I64d</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">m)!</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">EOF)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">m;&nbsp;nn</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;ans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">ns;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(p%su[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&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">&nbsp;(p%su[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;p</span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000">su[i];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[nn</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">su[i];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(p</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)&nbsp;break;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(!nn)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;ppow(m,n)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;ppow(m,n);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">nn;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;ans</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">ppow(num[i],n)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(ppow(num[i],n)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&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;ans);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>}</span></div>
<img src ="http://www.cppblog.com/qywyh/aggbug/31432.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-09-02 22:57 <a href="http://www.cppblog.com/qywyh/archive/2007/09/02/31432.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>连分数学习笔记</title><link>http://www.cppblog.com/qywyh/archive/2007/08/28/31020.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Tue, 28 Aug 2007 06:59:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/08/28/31020.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/31020.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/08/28/31020.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/31020.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/31020.html</trackback:ping><description><![CDATA[<p>(1)定理:设x0,x1,x2,...是无穷实数列,xj&gt;0,j&gt;=1,那么,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(i)对任意的整数 n&gt;= 1, r&gt;=1有<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;X0,...,Xn-1,Xn,...,Xn+r&gt; = &lt;X0,...,Xn-1,&lt;Xn,...,Xn+r&gt;&gt;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;&nbsp;&nbsp;&lt;X0,...,Xn-1,Xn+1/&lt;Xn+1,...,Xn+r&gt;&gt;.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;特别地有<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;X0,...,Xn-1,Xn,Xn+1&gt; = &lt;X0,...,Xn-1,Xn+1/Xn+1&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: #000000" twffan="done">注:用该定理可以求连分数的值<br><br><span style="COLOR: #000000" twffan="done">(2)对于连分数数数列 &lt;X0,...Xn&gt;&nbsp;有递推关系:<br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pn = XnPn-1+Pn-2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Qn =&nbsp;XnQn-1+Qn-2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;定义:&nbsp; P-2 = 0; P-1 = 1; Q-2 = 1; Q-1 = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;所以:&nbsp;&nbsp;P0 = X0; Q0 = 1; P1 = X1X0+1; Q1 = X1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;特别地:当 Xi=1 时, {Pn}, {Qn}为Fbi数列</span></p>
<p><span style="COLOR: #000000" twffan="done"><br>(3)pell方程: x^2+ny^2=+-1的解法:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;若n是平方数,则无解, 否则:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;先求出sqrt(n)的连分数序列&lt;x0,x1..xn&gt; 其中xn = 2*x0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;对于 x^2+ny^2=-1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;若n为奇数,则 x=Pn-1, y=Qn-1; n为偶数时无解<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;对于 x^2+ny^2=1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;若n为偶数,则 x=Pn-1, y=Qn-1; n为奇数时x=P2n-1, y=Q2n-1<br>&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;<br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<img src ="http://www.cppblog.com/qywyh/aggbug/31020.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-08-28 14:59 <a href="http://www.cppblog.com/qywyh/archive/2007/08/28/31020.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>中国剩余定理(同余方程组)小结</title><link>http://www.cppblog.com/qywyh/archive/2007/08/27/30943.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 27 Aug 2007 08:46:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/08/27/30943.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/30943.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/08/27/30943.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/30943.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/30943.html</trackback:ping><description><![CDATA[<p>问题简单来说就是&nbsp;a = ai (mod ni)&nbsp;&nbsp;&nbsp;求未知数a,<br>&nbsp;以下小结略去证明, 只是对定理作了必要的解释, 要了解相关定理,可查阅数论资料.<br><br>中国余数定理:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;设 n=n1*n2...nk, 其中因子两两互质.有:&nbsp;&nbsp;a-----(a1,a2,...,ak), 其中ai = a mod ni, 则 a和(a1,a2,...,ak)关系是一一对应的.就是说可以由 a求出(a1,a2,...,ak), 也可以由(a1,a2,...,ak)求出a<br><br>推论1:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;对于 a=ai&nbsp; (mod ni) 的同余方程,有唯一解<br><br>下面说说由(a1, a2, ..., ak)求a的方法:<br>定义 mi = n1*n2*...nk / ni;&nbsp;&nbsp;&nbsp;ci = mi(mf&nbsp; mod ni);&nbsp;&nbsp;&nbsp;其中 mi*mf&nbsp;&nbsp;mod ni = 1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;则 a = (a1*c1+a2*c2+...+ak*ck)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(mod n)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(注:由此等式可求a%n, 当n很大时)</p>
<p>中国剩余定理关键是mf的求法,如果理解了扩展欧几里得 ax+by=d, 就可以想到:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mi*mf&nbsp;&nbsp;mod ni = 1 =&gt; mi*mf+ni*y=1;<br><br>代码如下:<br></p>
<p>&#160;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>using&nbsp;namespace&nbsp;std;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MAXN&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;nn,&nbsp;a[MAXN],&nbsp;n[MAXN];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;egcd(</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="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">x,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">y)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;d;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(b&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;y&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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;a;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;egcd(b,&nbsp;a%b,&nbsp;y,&nbsp;x);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y&nbsp;</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">x;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;d;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;lmes()&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;tm</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;mf,&nbsp;y,&nbsp;ret</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;m;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">nn;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;tm&nbsp;</span><span style="COLOR: #000000">*=</span><span style="COLOR: #000000">&nbsp;n[i];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">nn;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;tm</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">n[i];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;egcd(m,&nbsp;n[i],&nbsp;mf,&nbsp;y);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ret&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;(a[i]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">m</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(mf%n[i]))%tm;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;(ret</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">tm)%tm;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;a[</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">4</span><span style="COLOR: #000000">;&nbsp;a[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;n[</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">5</span><span style="COLOR: #000000">;&nbsp;n[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;nn&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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;lmes());<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>}</span></div>
<p><br>&nbsp;</p>
<img src ="http://www.cppblog.com/qywyh/aggbug/30943.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-08-27 16:46 <a href="http://www.cppblog.com/qywyh/archive/2007/08/27/30943.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>解模线性方程小结</title><link>http://www.cppblog.com/qywyh/archive/2007/08/27/30918.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 27 Aug 2007 03:14:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/08/27/30918.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/30918.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/08/27/30918.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/30918.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/30918.html</trackback:ping><description><![CDATA[<p>对于扩展欧几里得主要部分说明:<br>1. d' = bx'+(a mod b)y', d' = gcd(b, a mod b);<br>&nbsp;&nbsp;&nbsp; 设 d = gcd(a, b), 因为 d = d', 所以<br>&nbsp;&nbsp;&nbsp; d = d' = bx'+(a mod b)y' = bx' + (a-floor(a/b)*b)y' = ay'+b(x'-floor(a/b)y');<br>&nbsp;&nbsp;&nbsp; 故有迭代:<br>&nbsp;&nbsp;&nbsp; x = y'; y = x'-floor(a/b)y';<br><br>对于解方程主要部分说明:<br>1.首先给出两个定理(证明请查看相关数论书):<br>&nbsp;&nbsp;&nbsp;A. 方程 ax = b (mod n) 有解, 当且仅当 gcd(a, n) | b;<br>&nbsp;&nbsp;&nbsp;B. 方程 ax = b (mod n) 有d个不同的解, 其中 d = gcd(a, n);<br>2.证明方程有一解是: x0 = x'(b/d) mod n;<br>&nbsp;&nbsp;&nbsp;由&nbsp;a*x0 = a*x'(b/d) (mod n)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a*x0 = d (b/d) (mod n)&nbsp;&nbsp; (由于 ax' = d (mod n))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= b (mod n)<br>&nbsp;&nbsp;&nbsp;证明方程有d个解: xi = x0 + i*(n/d)&nbsp; (mod n);<br>&nbsp;&nbsp;&nbsp;由 a*xi (mod n) = a * (x0 + i*(n/d)) (mod n)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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*x0+a*i*(n/d)) (mod n)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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 * x0 (mod n)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(由于 d | a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= b<br><br>代码如下:</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>using&nbsp;namespace&nbsp;std;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;egcd(</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="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">x,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">y)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(b&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;y&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 src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;a;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;tx,&nbsp;ty,&nbsp;d;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;egcd(b,&nbsp;a%b,&nbsp;tx,&nbsp;ty);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;ty;&nbsp;y&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;tx</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">ty;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;d;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>void&nbsp;mels(</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="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;tx,&nbsp;ty,&nbsp;d,&nbsp;x0,&nbsp;i;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;d&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;egcd(a,&nbsp;n,&nbsp;tx,&nbsp;ty);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(b%d</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x0&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;((tx</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">d)%n</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">n)%n;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">d;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;(x0</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">d)%n);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">No&nbsp;solutions!</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>}<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;mels(</span><span style="COLOR: #000000">14</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">30</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>}</span></div>
<img src ="http://www.cppblog.com/qywyh/aggbug/30918.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-08-27 11:14 <a href="http://www.cppblog.com/qywyh/archive/2007/08/27/30918.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>好久没写了.</title><link>http://www.cppblog.com/qywyh/archive/2007/07/23/28655.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 23 Jul 2007 13:04:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/07/23/28655.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/28655.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/07/23/28655.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/28655.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/28655.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp; 好久没写了，主要是不知道写什么，发个刚写好的比较通用的堆吧，sigh~<br><br>&nbsp;&nbsp;&nbsp; <a href="http://www.cppblog.com/qywyh/articles/28653.html">http://www.cppblog.com/qywyh/articles/28653.html</a>
<img src ="http://www.cppblog.com/qywyh/aggbug/28655.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-07-23 21:04 <a href="http://www.cppblog.com/qywyh/archive/2007/07/23/28655.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>校赛解题报告 By Scintilla</title><link>http://www.cppblog.com/qywyh/archive/2007/04/29/23150.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 28 Apr 2007 17:18:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/04/29/23150.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/23150.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/04/29/23150.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/23150.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/23150.html</trackback:ping><description><![CDATA[<p>Problem A: Modular multiplication of polynomials<br>A题是一道模拟题，主要考察选手数组的和循环控制的运用能力。<br>题目要求模拟的是多项式除法，且给出了具体的运算规则，异或运算。给出f(x),g(x)两个多项式相乘，然后除以h(x)多项式，求其余数(亦为多项式)。先用两重循环将f(x),g(x)相乘，用一数组记录相乘后多项式k(x)的x^i的系数，然后做多项式除法。设被除数的最高次为x^n, 除数h(x)的最高次为y^m, 直到n&lt;m时候循环结束。</p>
<p>Problem B:Checking an Alibi<br>这题其实就是求每个点到1号点的最短路。 然后判断每只牛所在地到1号点的需时是否小于等于M.<br>题目没明确说有没有重边，一般情况下是要考虑的。 在比赛时，我们认为数据中有长度为0的边，与题目中1－70000不符。但ACM就是这样，题目出问题是常有的事。在确定自己程序没错的前提下，选手们只能考经验和感觉去猜。</p>
<p>Problem C:The Game of Mafia<br>直接搜索就行了，白天和黑夜轮着搜，注意一下只剩下他自己的时候的情况就可以了。</p>
<p>Problem D:Multiplication Puzzle<br>这题是经典的动态规划。<br>用a[1000]表示愿数组，d[i][j]表示让第i个数与第j个数碰面（删掉他们之间的元素）的最小代价。<br>方程是：<br>&nbsp;d[i][j]= max(d[i][k]+d[k][j]+a[k]*a[i]*a[j]，i&lt;k&lt;j)<br>时间复杂度是O(n^3)。</p>
<p>Problem E:Zip<br>这题有两种操作A和B<br>对于操作A来说只要统计一下各种字母出现的次数就可以很容易得到S'了<br>而对于操作B来说统计一下序列S'的各种字母的出现次数，然后根据p就可以得到序列的第一个字母和第二个字母，然后根据根据第一个字母就可以得到最后一个字母<br>比如对于样例来说：<br>xelpame&nbsp;&nbsp; 7<br>a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x<br>e&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e<br>e&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; l<br>l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p<br>m&nbsp;&nbsp;&nbsp;&nbsp; a<br>p&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m<br>x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e<br>确实了第二个字母是x,第一个字母是e，e出现第一次的时候就可以得到最后一个字母是e，<br>所以根据最后一个字母倒过来生成前面的序列，从对应e的最后一次出现，可以得到倒数第二个字母是l，然后对于l最后出现一次，可以确实l前面是p，然后一直填上去就可以得到原序列S=example</p>
<p>Promble F: Wall<br>F题考察的是选手基本的计算几何知识。<br>读懂题意后就是求凸包的周长+一个圆的周长, 求凸包可以先选取最左下角的点，然后以该点为基准对所有点作极角排序，然后就是用Graham扫描法求凸包了。</p>
<p>Problem G:Ouroboros Snake<br>这题可以用构造算法。 题目有一个限制，2^N 个数不重不漏的出现，这就是关键所在。可以想到，必然有N个零连着，这就是要求数列的开始（以后不可能有N个零连着了）。然后我们每次取后面N-1位，加0看看前是否有这N位。有，那么这一位不能是0（要不就违反了不重不漏了），只能是1。否则就加0。<br>但是仅仅这样并不能得出正确的答案。 怎么办呢？<br>想到这个构造算法的结尾必然是很多个1连着（因为加0的话，这N位在前面出现过了）。理想的情况是N个1。那么象 1000，1100，1110这些前面全是1，后面全是0的数就在首尾相接（这是一个圆环）的时候出现了。<br>修正办法立刻有了，就是在一开始时把象 1000，1100，1110这些前面全是1，后面全是0的数标志为已经出现过。然后用我们之前说的那种构造法一位位的确定那一位是0还是1。<br>经过检验，发现这样就符合要求了。 </p>
<img src ="http://www.cppblog.com/qywyh/aggbug/23150.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-04-29 01:18 <a href="http://www.cppblog.com/qywyh/archive/2007/04/29/23150.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对一些DP题目的小结</title><link>http://www.cppblog.com/qywyh/archive/2007/04/20/22399.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Fri, 20 Apr 2007 10:10:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/04/20/22399.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/22399.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/04/20/22399.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/22399.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/22399.html</trackback:ping><description><![CDATA[<p>PKU 3093&nbsp;Margaritas on the River Walk<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;先对输入的数组排序，然后类似于01对a[i]做决策，核心代码加了注释：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;for (i=1; i&lt;=n; i++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (j=1; j&lt;=maxsum; j++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (j &gt;= sum[i]) d[i][j] = 1; //j比sum[i]大，肯定这时候d[i][j]=1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i][j] = d[i-1][j];//不考虑a[i]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (j-a[i]&gt;=0) {//考虑a[i]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (d[i-1][j-a[i]] &gt; 0)&nbsp;d[i][j] += d[i-1][j-a[i]];//把a[i]加进以前的选择里面<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else d[i][j]++;//a[i]单独作为一个选择(这里需要先对a[i]排序，消除后效性)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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>&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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br><br>PKU 1037 A decorative fence <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 先dp算出以i为起点的序列的个数，再组合数学<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; td[n][i]和tu[n][i]分别表示个数为n，以i开始的上升和下降的序列个数<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 易知:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; td[n][1] = 0; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; td[n][i] = sigma(tu[n-1][j], j从1..i-1)&nbsp; = td[n][i-1] + tu[n-1][i-1] ;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tu[n][i]&nbsp; = td[n][n+i-1];<br><br>PKU 2677 Tour<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;双调欧几里德旅行商问题(明显阶段dp)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;动态规划方程 ：d[i+1][i] = mint(d[i+1][i], d[i][j]+g[j][i+1]);&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i+1][j] = mint(d[i+1][j], d[i][j]+g[i][i+1]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&lt;=j&lt;i&nbsp;&nbsp;&nbsp;</p>
<p>PKU 2288 Islands and Bridges<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;集合DP<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;状态表示: d[i][j][k] (i为13为二进制表示点的状态, j为当前节点, k为到达j的前驱节点)<br><br></p>
<img src ="http://www.cppblog.com/qywyh/aggbug/22399.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-04-20 18:10 <a href="http://www.cppblog.com/qywyh/archive/2007/04/20/22399.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>简单总结一下做过的而又有价值的题</title><link>http://www.cppblog.com/qywyh/archive/2007/04/03/21202.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Tue, 03 Apr 2007 15:52:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/04/03/21202.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/21202.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/04/03/21202.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/21202.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/21202.html</trackback:ping><description><![CDATA[<p>pku 2513&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;" twffan="done">AC&nbsp;&nbsp;&nbsp;&nbsp;</span>火星人了, 第一次用hash, 以前都是用map偷懒的, 不过这题用trie应该会更好, 建好图之后就是DFS判连通,然后欧拉回路了.<br>pku 3216&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;" twffan="done">AC&nbsp;&nbsp;&nbsp;&nbsp;</span>二分图最小路径覆盖, 建立图的时候要求一次多源最短路(这个害我wa了好几次).<br>pku 3211&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp;&nbsp;理解题目后就是最每一种颜色做01背包了.<br>pku 3214&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #ff0000;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 这的确是一道好题, 先后序遍历heap,每次减去一个sub值, 然后对得到的序列求最长不降子序列,要nlogn的才能过.<br>pku 3213&nbsp;&nbsp;&nbsp;<span style="color: #ff0000;" twffan="done"> AC&nbsp;&nbsp;&nbsp; <span style="color: #000000;" twffan="done">看了解题报告才会做,先进行坐标转换[(x-y)/2, (x+y)/2], 然后求sig|xi-xj|+sig|yi-yj|的最小值.<br>pku 3215&nbsp;&nbsp;&nbsp; <span style="color: red;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 理解题意后其实是一道比较简单的计算几何,但是很容易WA,按方程和X轴的交点分段,然后枚举交点,统计x轴上下各自线段个数<br></span></span>pku 1177&nbsp;&nbsp;&nbsp; <span style="color: red;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 线段树, 4k的代码, 学会了测度和连续线段数, 记在笔记本上了, 随时复习. <br>pku 2564&nbsp;&nbsp;&nbsp; <span style="color: red;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 再次火星人,第一次写trie, 标号法DP, 题目描述很阴险.<br>tju&nbsp;&nbsp;&nbsp;2762&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 基本的线段树,&nbsp;&nbsp;&nbsp;用了ghost_wei的写法，省了B[]和E[]，基本思想是二分<br>pku 1699&nbsp;&nbsp;&nbsp; <span style="color: red;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 简单搜索，写下的目的是这道题用了alpha-beta剪枝<br>pku&nbsp;1195&nbsp;&nbsp;&nbsp; <span style="color: red;" twffan="done">AC&nbsp;</span>&nbsp;&nbsp; 二维树状数组，详细看李睿的论文吧.<br>pku 2482&nbsp;&nbsp;&nbsp; <span style="color: red;" twffan="done">AC&nbsp;&nbsp;&nbsp; <span style="color: #000000;" twffan="done">二叉统计树+树状DP+扫描线，绝对是一道好题.</span></span> <br>pku 1038&nbsp;&nbsp;&nbsp; <span style="color: red;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 被这题恶了一天，算法艺术上的方法超时，换了解题报告的那个A(x, y, p)的状态定义才过了，程序写的真好，特别是那滚动数组<br>ural 1031&nbsp;&nbsp; &nbsp;<span style="color: #ff0000;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 由单调性，可以O(n)的时间与处理，然后就O(n)的线性DP, 阴险地方是start可能小于end.<br><span style="color: #000000;" twffan="done">pku 1850</span>&nbsp;&nbsp;&nbsp; <span style="color: #ff0000;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 组合数学啊，以前一直不会，今天终于搞出来了，用DP先算出不符合的字符串数，然后将输入字符串转换成26进制-不符合的个数<br>pku 3067&nbsp;&nbsp;&nbsp; <span style="color: red;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 和star差不多，还是数状数组最好写.<br>ural 1018&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 树形DP, 把边的苹果数看成在树的节点上，然后做树状dp, 当然开始要先dfs一次建树<br>pku 2800&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;" twffan="done">AC</span>&nbsp;&nbsp;&nbsp; 数论，k mod i&nbsp; = k - floor(k/i) * i<br>pku 2516&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">AC&nbsp;&nbsp;&nbsp; <span style="color: #000000;">拆点，然后二分图最佳匹配</span></span></p><img src ="http://www.cppblog.com/qywyh/aggbug/21202.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-04-03 23:52 <a href="http://www.cppblog.com/qywyh/archive/2007/04/03/21202.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ghost_wei给的任务,练好DP,练好基本功</title><link>http://www.cppblog.com/qywyh/archive/2007/02/28/19050.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 28 Feb 2007 07:00:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/02/28/19050.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/19050.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/02/28/19050.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/19050.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/19050.html</trackback:ping><description><![CDATA[<p>pku 1014&nbsp;&nbsp;&nbsp;<font color=#0000ff>已做</font><br>pku&nbsp;1037&nbsp;&nbsp;&nbsp;<br>pku&nbsp;1050&nbsp;&nbsp;&nbsp;<font color=#0000ff>已做<br><font color=#000000>pku&nbsp;1088&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<br><font color=#000000>pku&nbsp;1141&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<br><font color=#000000>pku&nbsp;1159&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<br><font color=#000000>pku&nbsp;1163&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<br><font color=#000000>pku&nbsp;1322&nbsp;&nbsp;&nbsp;<font color=#ff0000>AC<br></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 看到题目就害怕，概率的-_-结果分析之下原来也不难<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 状态d[i][j]表示有j种颜色,拿了i个巧克力的最优值<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 方程: d[i+1][j+1] = d[i][j]*(c-j)/c;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (c为总颜色数)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d[i+1][j-1] = d[i][j]*j/c;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 由于只是保留3位小数，所以加优化if (n&gt;1000) n = 1000+n%2; //至于为什么要分奇偶性，这个还不太懂-_-这道算是ac一半而已<br></font><font color=#0000ff><font color=#000000>pku 2904&nbsp;&nbsp; </font><font color=#ff0000>AC<br></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></font></font></font></font></font><font color=#000000>dp[k][i][j]表示k个邮筒时候放鞭炮数为i..j时候的最优值<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color=#000000>转移方程为:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[k][i][j] = min{t+max(d[k-1][i][t-1],d[k][t+1][j])};<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color=#0000ff><font color=#0000ff><font color=#0000ff><font color=#0000ff><font color=#0000ff><font color=#0000ff><font color=#000000>状态转移时候就是考虑选t个鞭炮放时候爆或不爆</font><br><font color=#000000>pku&nbsp;1458&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<br><font color=#000000>pku&nbsp;1579&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<font color=#0000ff><font color=#000000>&nbsp;</font></font><br><font color=#000000>pku&nbsp;1695&nbsp;&nbsp;&nbsp;<font color=#ff0000>AC</font>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d[i][j][k]表示到达第i个点时候另外两辆车分别在点j和k时候的最优值<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;方程：&nbsp;d[i+1][j][k] = min(d[i+1][j][k], d[i][j][k]+g[i][i+1]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i+1][i][k] = min(d[i+1][i][k], d[i][j][k]+g[j][i+1]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d[i+1][i][j] = min(d[i+1][i][j], d[i][j][k]+g[k][i+1]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//初始条件d[1][1][1] = 0;</font><br><font color=#000000>pku&nbsp;1732&nbsp;&nbsp; <font color=#ff0000>AC<br></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 线型模型，本想用trie的，结果用map偷懒了。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d[i] = min{d[j]} + 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&lt;=j&lt;i &amp;&amp; j+1..i字符合法<br><font color=#000000>pku&nbsp;1953&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<br><font color=#000000>pku&nbsp;1976&nbsp;&nbsp; <font color=#ff0000>AC</font><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;先对区间做预处理,&nbsp;后面不足的coaches补0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d[k][j] = max{d[k-1][p]}+b[j];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&lt;=p&lt;=j-m (b为处理后的区间数组,m是一台locomotiv的容量)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 由单调性可以在状态转移时候保存前一次转移时候的最大值再和b[j-m]做比较，把O(n^2)压缩到O(n)的时间复杂度<br><font color=#000000>pku&nbsp;2386&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<br><font color=#000000>pku&nbsp;2479&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<br><font color=#000000>pku&nbsp;2951&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做</font></font></font>&nbsp;&nbsp;&nbsp;</font></font>&nbsp;&nbsp;&nbsp;<br><font color=#000000>pku&nbsp;3036&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<br><font color=#000000>pku&nbsp;3014&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<br><font color=#000000>pku&nbsp;2229&nbsp;&nbsp;&nbsp;</font><font color=#0000ff>已做<br><font color=#000000>pku&nbsp;1185&nbsp;&nbsp;&nbsp;<font color=#ff0000>AC<br><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最经典的状态DP,我用三进制表示每行状态，然后递推，结果tle,分析之后，枚举出有效状态，再推, 1000ms左右，<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 还是不够&nbsp;快， 张伟达的论文上有更快的算法。</font><br></font><font color=#000000>pku 1276&nbsp;&nbsp;&nbsp;<span style="COLOR: red">AC</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;01背包<br><br>有空把以前的也再做一次!~&nbsp;&nbsp;&nbsp;</font></font></font></font></font></font></font></font></font></font></font></font></font></font></p>
<img src ="http://www.cppblog.com/qywyh/aggbug/19050.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-02-28 15:00 <a href="http://www.cppblog.com/qywyh/archive/2007/02/28/19050.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>这就是树状dp..好难啊..</title><link>http://www.cppblog.com/qywyh/archive/2007/02/10/18619.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Sat, 10 Feb 2007 10:58:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/02/10/18619.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/18619.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/02/10/18619.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/18619.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/18619.html</trackback:ping><description><![CDATA[pku 2486 apple tree<br /><br />解法：<br /><br />/////////////////////////////////////////////////////////////////////<br />//Apple Tree<br />//数组二维go，bk<br />//go[t][i]代表节点t的所有子树上走i步不返回,取得的最大苹果数<br />//bk[t][i]代表节点t的所有子树上走i步并返回,取得的最大苹果数<br />//求节点为x，实行不断合并子树求最优值<br />//当前合并到了q棵子树：<br />//go[x][i]就是这q棵子树上走i步不返回的最优值<br />//bk[x][i]就是这q棵子树上走i步并返回的最优值<br />//合并第q+1棵子树(不妨设第q+1棵子树的根为y)的时候，有<br />//go[x][i] = max( bk[x][j]+go[y][i-j], bk[y][j]+go[x][i-j] ), j=0.....i<br />//bk[x][i] = max( bk[x][j]+bk[y][i-j] ) j=0,.....i;<br />////////////////////////////////////////////////////////////////////////////<br /><br />代码：<a href="/qywyh/articles/18618.html">http://www.cppblog.com/qywyh/articles/18618.html</a><br /><img src ="http://www.cppblog.com/qywyh/aggbug/18619.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-02-10 18:58 <a href="http://www.cppblog.com/qywyh/archive/2007/02/10/18619.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>&lt;&lt;算法导论&gt;&gt;笔记2 -- 计数排序</title><link>http://www.cppblog.com/qywyh/archive/2007/02/06/18488.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Tue, 06 Feb 2007 12:43:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/02/06/18488.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/18488.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/02/06/18488.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/18488.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/18488.html</trackback:ping><description><![CDATA[
		<p>当k比较小的时候，可获得O(n)的时间复杂度.<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />using namespace std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> arrLen </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">5</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_106_353_Open_Image" onclick="this.style.display='none'; Codehighlighter1_106_353_Open_Text.style.display='none'; Codehighlighter1_106_353_Closed_Image.style.display='inline'; Codehighlighter1_106_353_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_106_353_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_106_353_Closed_Text.style.display='none'; Codehighlighter1_106_353_Open_Image.style.display='inline'; Codehighlighter1_106_353_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> countingSort(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">a, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">b, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> k) </span>
				<span id="Codehighlighter1_106_353_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_106_353_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">a数组元素在[0..k]</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">c </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">[k</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (i</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">k; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) c[i] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (i</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">arrLen; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) c[a[i]]</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">包含小于或等于i的元素个数</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (i</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">k; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) c[i] </span>
						<span style="COLOR: #000000">+=</span>
						<span style="COLOR: #000000"> c[i</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">];<br /><img id="Codehighlighter1_312_351_Open_Image" onclick="this.style.display='none'; Codehighlighter1_312_351_Open_Text.style.display='none'; Codehighlighter1_312_351_Closed_Image.style.display='inline'; Codehighlighter1_312_351_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_312_351_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_312_351_Closed_Text.style.display='none'; Codehighlighter1_312_351_Open_Image.style.display='inline'; Codehighlighter1_312_351_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (j</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">arrLen</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; j</span>
						<span style="COLOR: #000000">&gt;=</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; j</span>
						<span style="COLOR: #000000">--</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_312_351_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_312_351_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        b[c[a[j]]</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"> a[j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        c[a[j]]</span>
								<span style="COLOR: #000000">--</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img id="Codehighlighter1_367_530_Open_Image" onclick="this.style.display='none'; Codehighlighter1_367_530_Open_Text.style.display='none'; Codehighlighter1_367_530_Closed_Image.style.display='inline'; Codehighlighter1_367_530_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_367_530_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_367_530_Closed_Text.style.display='none'; Codehighlighter1_367_530_Open_Image.style.display='inline'; Codehighlighter1_367_530_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main() </span>
				<span id="Codehighlighter1_367_530_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_367_530_Open_Text">
						<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_386_400_Open_Image" onclick="this.style.display='none'; Codehighlighter1_386_400_Open_Text.style.display='none'; Codehighlighter1_386_400_Closed_Image.style.display='inline'; Codehighlighter1_386_400_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_386_400_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_386_400_Closed_Text.style.display='none'; Codehighlighter1_386_400_Open_Image.style.display='inline'; Codehighlighter1_386_400_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> a[arrLen] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span id="Codehighlighter1_386_400_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_386_400_Open_Text">
								<span style="COLOR: #000000">{</span>
								<span style="COLOR: #000000">4</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">4</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">3</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">}</span>
						</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> b[arrLen];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    countingSort(a, b, </span>
						<span style="COLOR: #000000">5</span>
						<span style="COLOR: #000000">);<br /><img id="Codehighlighter1_468_494_Open_Image" onclick="this.style.display='none'; Codehighlighter1_468_494_Open_Text.style.display='none'; Codehighlighter1_468_494_Closed_Image.style.display='inline'; Codehighlighter1_468_494_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_468_494_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_468_494_Closed_Text.style.display='none'; Codehighlighter1_468_494_Open_Image.style.display='inline'; Codehighlighter1_468_494_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">5</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">) </span>
						<span id="Codehighlighter1_468_494_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_468_494_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%d </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">, b[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    printf(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    system(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">pause</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/18488.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-02-06 20:43 <a href="http://www.cppblog.com/qywyh/archive/2007/02/06/18488.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>&lt;&lt;算法导论&gt;&gt;笔记1</title><link>http://www.cppblog.com/qywyh/archive/2007/02/05/18398.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 05 Feb 2007 11:43:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2007/02/05/18398.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/18398.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2007/02/05/18398.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/18398.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/18398.html</trackback:ping><description><![CDATA[循环不变式<br /><br />循环不变式主要用来帮助我们理解算法的正确性。<br /><br />初始化：它在循环的第一轮迭代开始之前，应该是正确的。<br /><br />保持：如果在循环的某一次迭代开始之前它是正确，那么，在下一次迭代开始之前，它也应该保持正确。<br /><br />终止：当循环结束时，不变式给了我们一个有用的性质，它有助于表明算法是正确的。<img src ="http://www.cppblog.com/qywyh/aggbug/18398.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2007-02-05 19:43 <a href="http://www.cppblog.com/qywyh/archive/2007/02/05/18398.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>压缩状态DP</title><link>http://www.cppblog.com/qywyh/archive/2006/10/18/13823.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 18 Oct 2006 09:32:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/10/18/13823.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/13823.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/10/18/13823.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/13823.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/13823.html</trackback:ping><description><![CDATA[
		<p>压缩状态DP, 一般用于n*m矩阵 n &lt;&lt; m 或 m &lt;&lt; n的情况.<br />用每一行或每一列表示状态(关键在于进制表示和状态转移)<br /><br />pku3020代码链接:<a href="/qywyh/articles/13822.html">http://www.cppblog.com/qywyh/articles/13822.html</a><br /><br />看了ghost_wei大牛的代码, 滚动数组, 位运算, 出神入化啊, 而且敲题时间为10分钟(我用了一个下午-_-) , 无限仰慕啊!:)</p>
		<p> </p>
<img src ="http://www.cppblog.com/qywyh/aggbug/13823.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-10-18 17:32 <a href="http://www.cppblog.com/qywyh/archive/2006/10/18/13823.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>第一个用邻接表实现的算法（拓扑排序）</title><link>http://www.cppblog.com/qywyh/archive/2006/10/11/13567.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 11 Oct 2006 05:10:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/10/11/13567.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/13567.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/10/11/13567.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/13567.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/13567.html</trackback:ping><description><![CDATA[
		<p>纪念一下：）<br /><br />链接:<a href="/qywyh/articles/13566.html">http://www.cppblog.com/qywyh/articles/13566.html</a><br /><br />发现最近很久没认真上过课了， 这样下去肯定不行的， 不能再这样了。</p>
<img src ="http://www.cppblog.com/qywyh/aggbug/13567.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-10-11 13:10 <a href="http://www.cppblog.com/qywyh/archive/2006/10/11/13567.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>北京网络赛失败后的总结(scintilla+U)</title><link>http://www.cppblog.com/qywyh/archive/2006/10/10/13552.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Tue, 10 Oct 2006 15:53:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/10/10/13552.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/13552.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/10/10/13552.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/13552.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/13552.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: <br><br>原则1:一道题不能卡太久时间 (标准1.5-2小时)<br>原则2:减少罚时, 3次wa后应该想想算法有没有问题(其中每次wa都是经过认真修改后的程序) <br>原则3:比赛心态, 比赛时候要冷静<br><br>........&nbsp;&nbsp;<a href='http://www.cppblog.com/qywyh/archive/2006/10/10/13552.html'>阅读全文</a><img src ="http://www.cppblog.com/qywyh/aggbug/13552.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-10-10 23:53 <a href="http://www.cppblog.com/qywyh/archive/2006/10/10/13552.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>终于把RBTree敲出来了， 累.</title><link>http://www.cppblog.com/qywyh/archive/2006/09/15/12489.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Thu, 14 Sep 2006 17:15:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/09/15/12489.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/12489.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/09/15/12489.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/12489.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/12489.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 基本测试没问题， 有bug请指出:)										#include 				&lt;				iostream				&gt;																								using				 				namespace				 std;				const				 				int				 MAXSIZE 				=...&nbsp;&nbsp;<a href='http://www.cppblog.com/qywyh/archive/2006/09/15/12489.html'>阅读全文</a><img src ="http://www.cppblog.com/qywyh/aggbug/12489.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-09-15 01:15 <a href="http://www.cppblog.com/qywyh/archive/2006/09/15/12489.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>第一次用两种数据结构解的题目， 纪念一下</title><link>http://www.cppblog.com/qywyh/archive/2006/09/06/12085.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 06 Sep 2006 05:30:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/09/06/12085.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/12085.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/09/06/12085.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/12085.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/12085.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: USE 并查集和线段树The k-th Largest GroupTime Limit:2000MS  Memory Limit:131072KTotal Submit:1222 Accepted:290 DescriptionNewman likes playing with cats. He possesses lots of cats in his home. Because the num...&nbsp;&nbsp;<a href='http://www.cppblog.com/qywyh/archive/2006/09/06/12085.html'>阅读全文</a><img src ="http://www.cppblog.com/qywyh/aggbug/12085.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-09-06 13:30 <a href="http://www.cppblog.com/qywyh/archive/2006/09/06/12085.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Floyd-warshall(经典DP, 能用于有向图)</title><link>http://www.cppblog.com/qywyh/archive/2006/08/29/11821.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Tue, 29 Aug 2006 07:27:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/08/29/11821.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11821.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/08/29/11821.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11821.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11821.html</trackback:ping><description><![CDATA[
		<p>闻说还能用在负权,和有环图...继续研究<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> MAXN </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">101</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> INF </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1000000</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> g[MAXN][MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> d[MAXN][MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> floyd(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_102_448_Open_Image" onclick="this.style.display='none'; Codehighlighter1_102_448_Open_Text.style.display='none'; Codehighlighter1_102_448_Closed_Image.style.display='inline'; Codehighlighter1_102_448_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_102_448_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_102_448_Closed_Text.style.display='none'; Codehighlighter1_102_448_Open_Image.style.display='inline'; Codehighlighter1_102_448_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_102_448_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_102_448_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">  i, j, k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (i</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (j</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; j</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">n; j</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            d[i][j] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> g[i][j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (k</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; k</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">n; k</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_236_432_Open_Image" onclick="this.style.display='none'; Codehighlighter1_236_432_Open_Text.style.display='none'; Codehighlighter1_236_432_Closed_Image.style.display='inline'; Codehighlighter1_236_432_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_236_432_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_236_432_Closed_Text.style.display='none'; Codehighlighter1_236_432_Open_Image.style.display='inline'; Codehighlighter1_236_432_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_236_432_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_236_432_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (i</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; i</span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000">n; i</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; j</span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000">n; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_312_429_Open_Image" onclick="this.style.display='none'; Codehighlighter1_312_429_Open_Text.style.display='none'; Codehighlighter1_312_429_Closed_Image.style.display='inline'; Codehighlighter1_312_429_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_312_429_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_312_429_Closed_Text.style.display='none'; Codehighlighter1_312_429_Open_Image.style.display='inline'; Codehighlighter1_312_429_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
								<span id="Codehighlighter1_312_429_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_312_429_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (d[i][k] </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> INF </span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000"> d[k][j] </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> INF<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000"> d[i][k] </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> d[k][j] </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> d[i][j])<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    d[i][j] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> d[i][k] </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> d[k][j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/11821.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-08-29 15:27 <a href="http://www.cppblog.com/qywyh/archive/2006/08/29/11821.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>acm要学的内容(转载 踏雪赤兔's BLOG)</title><link>http://www.cppblog.com/qywyh/archive/2006/08/17/11381.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Thu, 17 Aug 2006 15:44:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/08/17/11381.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11381.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/08/17/11381.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11381.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11381.html</trackback:ping><description><![CDATA[//------------------------------<br />给我一年时间,  把你们都搞<br />定, 呵呵, 做个好梦先!~<br />------------------------------//<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">图论 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       路径问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              最短路径 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                     </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> 边权最短路径 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />BFS <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                     非负边权最短路径 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Dijkstra <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       可以用Dijkstra解决的问题的特征 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                     负边权最短路径 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Bellman</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">Ford <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       Bellman</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">Ford的Yen</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">氏优化 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       差分约束系统 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                            Floyd <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       广义路径问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       传递闭包 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       极小极大距离 </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> 极大极小距离 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Euler Path </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> Tour <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       圈套圈算法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       混合图的 Euler Path </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> Tour <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Hamilton Path </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> Tour <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       特殊图的Hamilton Path </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> Tour 构造 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />生成树问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              最小生成树 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                     第k小生成树 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              最优比率生成树 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">1分数规划 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              度限制生成树 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       连通性问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       强大的DFS算法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              无向图连通性 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                     割点 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />割边 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />二连通分支 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              有向图连通性 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                     强连通分支 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">SAT <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       最小点基 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />有向无环图 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       拓扑排序 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       有向无环图与动态规划的关系 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />二分图匹配问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       一般图问题与二分图问题的转换思路 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />最大匹配 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       有向图的最小路径覆盖 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> 1矩阵的最小覆盖 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       完备匹配 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       最优匹配 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />网络流问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       网络流模型的简单特征和与线性规划的关系 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       最大流最小割定理 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       最大流问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />有上下界的最大流问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       循环流 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />最小费用最大流 </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> 最大费用最大流 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />弦图的性质和判定 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />组合数学 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       解决组合数学问题时常用的思想 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       逼近 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       递推 </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> 动态规划 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       概率问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       Polya 定理 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />计算几何 </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> 解析几何 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       计算几何的核心：叉积 </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> 面积 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       解析几何的主力：复数 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />基本形 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       点 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       直线，线段 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       多边形 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />凸多边形 </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> 凸包 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       凸包算法的引进，卷包裹法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       Graham 扫描法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       水平序的引进，共线凸包的补丁 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />完美凸包算法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       相关判定 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              两直线相交 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              两线段相交 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              点在任意多边形内的判定 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              点在凸多边形内的判定 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       经典问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              最小外接圆 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                     近似O(n)的最小外接圆算法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              点集直径 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                     旋转卡壳，对踵点 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       多边形的三角剖分 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />数学 </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> 数论 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       最大公约数 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              Euclid 算法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                     扩展的Euclid算法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                            同余方程 </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> 二元一次不定方程 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                            同余方程组 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       线性方程组 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              高斯消元法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       解mod 2域上的线性方程组 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       整系数方程组的精确解法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />矩阵 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       行列式的计算 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       利用矩阵乘法快速计算递推关系 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       分数 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              分数树 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              连分数逼近 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       数论计算 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              求N的约数个数 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              求phi(N) <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              求约数和 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              …… <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       素数问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              概率判素算法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              概率因子分解 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />数据结构： <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       组织结构 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              二叉堆 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                     左偏树 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              胜者树 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              Treap <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />统计结构 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />树状数组 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />虚二叉树 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />线段树 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       矩形面积并 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       圆形面积并 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       关系结构 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              Hash 表 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />并查集 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       路径压缩思想的应用 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       STL 中的数据结构 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              vector <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              deque <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> map <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />动态规划 </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> 记忆化搜索 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       动态规划和记忆化搜索在思考方式上的区别 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       最长子序列系列问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />              最长不下降子序列 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       最长公共子序列 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       一类NP问题的动态规划解法 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       树型动态规划 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       背包问题 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       动态规划的优化 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       四边形不等式 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       状态设计 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />u       规划方向（？） <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />常用思想 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       二分 <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       最小表示法 </span></div><img src ="http://www.cppblog.com/qywyh/aggbug/11381.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-08-17 23:44 <a href="http://www.cppblog.com/qywyh/archive/2006/08/17/11381.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>新学了并查集, 不知道能不能用呢^_^</title><link>http://www.cppblog.com/qywyh/archive/2006/08/16/11301.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 16 Aug 2006 12:22:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/08/16/11301.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11301.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/08/16/11301.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11301.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11301.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> MAXN </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">100</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> UFset<br /><img id="Codehighlighter1_77_155_Open_Image" onclick="this.style.display='none'; Codehighlighter1_77_155_Open_Text.style.display='none'; Codehighlighter1_77_155_Closed_Image.style.display='inline'; Codehighlighter1_77_155_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_77_155_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_77_155_Closed_Text.style.display='none'; Codehighlighter1_77_155_Open_Image.style.display='inline'; Codehighlighter1_77_155_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_77_155_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_77_155_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> parent[MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    UFset();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> Find(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> Union(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />UFset::UFset()<br /><img id="Codehighlighter1_174_213_Open_Image" onclick="this.style.display='none'; Codehighlighter1_174_213_Open_Text.style.display='none'; Codehighlighter1_174_213_Closed_Image.style.display='inline'; Codehighlighter1_174_213_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_174_213_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_174_213_Closed_Text.style.display='none'; Codehighlighter1_174_213_Open_Image.style.display='inline'; Codehighlighter1_174_213_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_174_213_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_174_213_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(parent, </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #0000ff">sizeof</span>
						<span style="COLOR: #000000">(parent));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> UFset::Find(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x)<br /><img id="Codehighlighter1_239_346_Open_Image" onclick="this.style.display='none'; Codehighlighter1_239_346_Open_Text.style.display='none'; Codehighlighter1_239_346_Closed_Image.style.display='inline'; Codehighlighter1_239_346_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_239_346_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_239_346_Closed_Text.style.display='none'; Codehighlighter1_239_346_Open_Image.style.display='inline'; Codehighlighter1_239_346_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_239_346_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_239_346_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (parent[x] </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> x;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_280_337_Open_Image" onclick="this.style.display='none'; Codehighlighter1_280_337_Open_Text.style.display='none'; Codehighlighter1_280_337_Closed_Image.style.display='inline'; Codehighlighter1_280_337_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_280_337_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_280_337_Closed_Text.style.display='none'; Codehighlighter1_280_337_Open_Image.style.display='inline'; Codehighlighter1_280_337_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_280_337_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_280_337_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        parent[x] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> Find(parent[x]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> parent[x];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> 压缩路径</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />
						</span>
						<span style="COLOR: #000000">}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> UFset::Union(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> x, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> y)<br /><img id="Codehighlighter1_381_629_Open_Image" onclick="this.style.display='none'; Codehighlighter1_381_629_Open_Text.style.display='none'; Codehighlighter1_381_629_Closed_Image.style.display='inline'; Codehighlighter1_381_629_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_381_629_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_381_629_Closed_Text.style.display='none'; Codehighlighter1_381_629_Open_Image.style.display='inline'; Codehighlighter1_381_629_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_381_629_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_381_629_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> pX </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> Find(x);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> pY </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> Find(y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (pX </span>
						<span style="COLOR: #000000">!=</span>
						<span style="COLOR: #000000"> pY)<br /><img id="Codehighlighter1_447_627_Open_Image" onclick="this.style.display='none'; Codehighlighter1_447_627_Open_Text.style.display='none'; Codehighlighter1_447_627_Closed_Image.style.display='inline'; Codehighlighter1_447_627_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_447_627_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_447_627_Closed_Text.style.display='none'; Codehighlighter1_447_627_Open_Image.style.display='inline'; Codehighlighter1_447_627_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_447_627_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_447_627_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        tmp </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> parent[pX] </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> parent[pY]; </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> 加权合并</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (parent[pX] </span>
								<span style="COLOR: #000000">&gt;</span>
								<span style="COLOR: #000000"> parent[pY])<br /><img id="Codehighlighter1_523_568_Open_Image" onclick="this.style.display='none'; Codehighlighter1_523_568_Open_Text.style.display='none'; Codehighlighter1_523_568_Closed_Image.style.display='inline'; Codehighlighter1_523_568_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_523_568_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_523_568_Closed_Text.style.display='none'; Codehighlighter1_523_568_Open_Image.style.display='inline'; Codehighlighter1_523_568_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_523_568_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_523_568_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pX] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> pY;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pY] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
										<img id="Codehighlighter1_579_624_Open_Image" onclick="this.style.display='none'; Codehighlighter1_579_624_Open_Text.style.display='none'; Codehighlighter1_579_624_Closed_Image.style.display='inline'; Codehighlighter1_579_624_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_579_624_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_579_624_Closed_Text.style.display='none'; Codehighlighter1_579_624_Open_Image.style.display='inline'; Codehighlighter1_579_624_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_579_624_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_579_624_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pY] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> pX;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            parent[pX] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> tmp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_643_656_Open_Image" onclick="this.style.display='none'; Codehighlighter1_643_656_Open_Text.style.display='none'; Codehighlighter1_643_656_Closed_Image.style.display='inline'; Codehighlighter1_643_656_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_643_656_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_643_656_Closed_Text.style.display='none'; Codehighlighter1_643_656_Open_Image.style.display='inline'; Codehighlighter1_643_656_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_643_656_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_643_656_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>有bug请指正:)<img src ="http://www.cppblog.com/qywyh/aggbug/11301.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-08-16 20:22 <a href="http://www.cppblog.com/qywyh/archive/2006/08/16/11301.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Dijkstra单源最短路径</title><link>http://www.cppblog.com/qywyh/archive/2006/08/09/11043.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 09 Aug 2006 06:51:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/08/09/11043.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/11043.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/08/09/11043.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/11043.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/11043.html</trackback:ping><description><![CDATA[
		<p>原来是这样的， 每次从候选集合dist选取一个加入set中， 然后调整候选集， 使其满足， d[u] 为起点经过set里面的点到达u的最短路径。<br /><br />这是我理解写的从1-&gt;n的dijkstra程序:<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> COSTDATA<br /><img id="Codehighlighter1_16_38_Open_Image" onclick="this.style.display='none'; Codehighlighter1_16_38_Open_Text.style.display='none'; Codehighlighter1_16_38_Closed_Image.style.display='inline'; Codehighlighter1_16_38_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_16_38_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_16_38_Closed_Text.style.display='none'; Codehighlighter1_16_38_Open_Image.style.display='inline'; Codehighlighter1_16_38_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_16_38_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_16_38_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> visit;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> dijkstra(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_62_634_Open_Image" onclick="this.style.display='none'; Codehighlighter1_62_634_Open_Text.style.display='none'; Codehighlighter1_62_634_Closed_Image.style.display='inline'; Codehighlighter1_62_634_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_62_634_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_62_634_Closed_Text.style.display='none'; Codehighlighter1_62_634_Open_Image.style.display='inline'; Codehighlighter1_62_634_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_62_634_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_62_634_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j, u, min;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    COSTDATA dist[MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">set</span>
						<span style="COLOR: #000000">[MAXN];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> setNum;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">set</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"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; dist[</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">].visit </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; dist[</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">].q </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    setNum </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (i</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_218_265_Open_Image" onclick="this.style.display='none'; Codehighlighter1_218_265_Open_Text.style.display='none'; Codehighlighter1_218_265_Closed_Image.style.display='inline'; Codehighlighter1_218_265_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_218_265_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_218_265_Closed_Text.style.display='none'; Codehighlighter1_218_265_Open_Image.style.display='inline'; Codehighlighter1_218_265_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_218_265_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_218_265_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dist[i].q </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> g[</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">][i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dist[i].visit </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (setNum </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_288_613_Open_Image" onclick="this.style.display='none'; Codehighlighter1_288_613_Open_Text.style.display='none'; Codehighlighter1_288_613_Closed_Image.style.display='inline'; Codehighlighter1_288_613_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_288_613_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_288_613_Closed_Text.style.display='none'; Codehighlighter1_288_613_Open_Image.style.display='inline'; Codehighlighter1_288_613_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_288_613_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_288_613_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        min </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> MAXNUM;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (i</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; i</span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000">n; i</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_331_428_Open_Image" onclick="this.style.display='none'; Codehighlighter1_331_428_Open_Text.style.display='none'; Codehighlighter1_331_428_Closed_Image.style.display='inline'; Codehighlighter1_331_428_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_331_428_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_331_428_Closed_Text.style.display='none'; Codehighlighter1_331_428_Open_Image.style.display='inline'; Codehighlighter1_331_428_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_331_428_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_331_428_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (min </span>
										<span style="COLOR: #000000">&gt;</span>
										<span style="COLOR: #000000"> dist[i].q </span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000"> dist[i].visit </span>
										<span style="COLOR: #000000">!=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_387_424_Open_Image" onclick="this.style.display='none'; Codehighlighter1_387_424_Open_Text.style.display='none'; Codehighlighter1_387_424_Closed_Image.style.display='inline'; Codehighlighter1_387_424_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_387_424_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_387_424_Closed_Text.style.display='none'; Codehighlighter1_387_424_Open_Image.style.display='inline'; Codehighlighter1_387_424_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_387_424_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_387_424_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                u </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                min </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> dist[i].q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dist[u].visit </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">set</span>
								<span style="COLOR: #000000">[</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">setNum] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> u;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (i</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; i</span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000">n; i</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_499_609_Open_Image" onclick="this.style.display='none'; Codehighlighter1_499_609_Open_Text.style.display='none'; Codehighlighter1_499_609_Closed_Image.style.display='inline'; Codehighlighter1_499_609_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_499_609_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_499_609_Closed_Text.style.display='none'; Codehighlighter1_499_609_Open_Image.style.display='inline'; Codehighlighter1_499_609_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_499_609_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_499_609_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (dist[i].visit </span>
										<span style="COLOR: #000000">!=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000"> dist[i].q </span>
										<span style="COLOR: #000000">&gt;</span>
										<span style="COLOR: #000000"> dist[u].q</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000">g[u][i])<br /><img id="Codehighlighter1_565_605_Open_Image" onclick="this.style.display='none'; Codehighlighter1_565_605_Open_Text.style.display='none'; Codehighlighter1_565_605_Closed_Image.style.display='inline'; Codehighlighter1_565_605_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_565_605_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_565_605_Closed_Text.style.display='none'; Codehighlighter1_565_605_Open_Image.style.display='inline'; Codehighlighter1_565_605_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_565_605_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_565_605_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                dist[i].q </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> dist[u].q</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">g[u][i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> dist[n].q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
		<p> 我再根据wy的代码，再优化了一下， 以下是任意两点的最短路径程序：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img id="Codehighlighter1_0_78_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_78_Open_Text.style.display='none'; Codehighlighter1_0_78_Closed_Image.style.display='inline'; Codehighlighter1_0_78_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
				<img id="Codehighlighter1_0_78_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_78_Closed_Text.style.display='none'; Codehighlighter1_0_78_Open_Image.style.display='inline'; Codehighlighter1_0_78_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				<span id="Codehighlighter1_0_78_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span>
				<span id="Codehighlighter1_0_78_Open_Text">
						<span style="COLOR: #008000">/*</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> *    beg : 起点;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> *  end : 终点;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> *  n : 顶点个数;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> *  g : 邻接矩阵, 为全局变量, 下标(1, 1)起;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> </span>
						<span style="COLOR: #008000">*/</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> dijkstra(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> beg, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> end, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_119_642_Open_Image" onclick="this.style.display='none'; Codehighlighter1_119_642_Open_Text.style.display='none'; Codehighlighter1_119_642_Closed_Image.style.display='inline'; Codehighlighter1_119_642_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_119_642_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_119_642_Closed_Text.style.display='none'; Codehighlighter1_119_642_Open_Image.style.display='inline'; Codehighlighter1_119_642_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_119_642_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_119_642_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i, j, u, min;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">dist </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">[n</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">visit </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">[n</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (i</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_219_262_Open_Image" onclick="this.style.display='none'; Codehighlighter1_219_262_Open_Text.style.display='none'; Codehighlighter1_219_262_Closed_Image.style.display='inline'; Codehighlighter1_219_262_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_219_262_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_219_262_Closed_Text.style.display='none'; Codehighlighter1_219_262_Open_Image.style.display='inline'; Codehighlighter1_219_262_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_219_262_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_219_262_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dist[i] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> MAXNUM;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        visit[i] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">false</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    dist[beg] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (i</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_303_620_Open_Image" onclick="this.style.display='none'; Codehighlighter1_303_620_Open_Text.style.display='none'; Codehighlighter1_303_620_Closed_Image.style.display='inline'; Codehighlighter1_303_620_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_303_620_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_303_620_Closed_Text.style.display='none'; Codehighlighter1_303_620_Open_Image.style.display='inline'; Codehighlighter1_303_620_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_303_620_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_303_620_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        min </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> MAXNUM;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; j</span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000">n; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_346_426_Open_Image" onclick="this.style.display='none'; Codehighlighter1_346_426_Open_Text.style.display='none'; Codehighlighter1_346_426_Closed_Image.style.display='inline'; Codehighlighter1_346_426_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_346_426_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_346_426_Closed_Text.style.display='none'; Codehighlighter1_346_426_Open_Image.style.display='inline'; Codehighlighter1_346_426_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_346_426_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_346_426_Open_Text">
										<span style="COLOR: #000000">{    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (min </span>
										<span style="COLOR: #000000">&gt;</span>
										<span style="COLOR: #000000"> dist[j] </span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">!</span>
										<span style="COLOR: #000000">visit[j])<br /><img id="Codehighlighter1_387_422_Open_Image" onclick="this.style.display='none'; Codehighlighter1_387_422_Open_Text.style.display='none'; Codehighlighter1_387_422_Closed_Image.style.display='inline'; Codehighlighter1_387_422_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_387_422_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_387_422_Closed_Text.style.display='none'; Codehighlighter1_387_422_Open_Image.style.display='inline'; Codehighlighter1_387_422_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_387_422_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_387_422_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                u </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> j;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                min </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> dist[j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (min </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> MAXNUM) </span>
								<span style="COLOR: #0000ff">break</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        visit[u] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">true</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; j</span>
								<span style="COLOR: #000000">&lt;=</span>
								<span style="COLOR: #000000">n; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_500_592_Open_Image" onclick="this.style.display='none'; Codehighlighter1_500_592_Open_Text.style.display='none'; Codehighlighter1_500_592_Closed_Image.style.display='inline'; Codehighlighter1_500_592_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_500_592_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_500_592_Closed_Text.style.display='none'; Codehighlighter1_500_592_Open_Image.style.display='inline'; Codehighlighter1_500_592_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_500_592_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_500_592_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (</span>
										<span style="COLOR: #000000">!</span>
										<span style="COLOR: #000000">visit[j] </span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000"> dist[j] </span>
										<span style="COLOR: #000000">&gt;</span>
										<span style="COLOR: #000000"> dist[u]</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000">g[u][j])<br /><img id="Codehighlighter1_552_588_Open_Image" onclick="this.style.display='none'; Codehighlighter1_552_588_Open_Text.style.display='none'; Codehighlighter1_552_588_Closed_Image.style.display='inline'; Codehighlighter1_552_588_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_552_588_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_552_588_Closed_Text.style.display='none'; Codehighlighter1_552_588_Open_Image.style.display='inline'; Codehighlighter1_552_588_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_552_588_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_552_588_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                dist[j] </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> dist[u]</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">g[u][j];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (u </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> end) </span>
								<span style="COLOR: #0000ff">break</span>
								<span style="COLOR: #000000">;        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> dist[end];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/11043.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-08-09 14:51 <a href="http://www.cppblog.com/qywyh/archive/2006/08/09/11043.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>二分查找解单调方程..</title><link>http://www.cppblog.com/qywyh/archive/2006/05/08/6789.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 08 May 2006 13:24:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/05/08/6789.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/6789.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/05/08/6789.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/6789.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/6789.html</trackback:ping><description><![CDATA[
		<p align="center">
				<font color="blue" size="5">Crossed ladders</font>
				<br />Time Limit:1000MS  Memory Limit:65536K<br />Total Submit:1837 Accepted:605 </p>
		<p>
				<font color="blue" size="5">Description</font>
				<br />
				<font face="Times New Roman" size="3">A narrow street is lined with tall buildings. An x foot long ladder is rested at the base of the building on the right side of the street and leans on the building on the left side. A y foot long ladder is rested at the base of the building on the left side of the street and leans on the building on the right side. The point where the two ladders cross is exactly c feet from the ground. How wide is the street? <br /><center><img src="http://acm.pku.edu.cn/JudgeOnline/images/2507_1.jpg" twffan="done" /></center></font>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
				<font color="blue" size="5">Input</font>
				<br />
				<font face="Times New Roman" size="3">Each line of input contains three positive floating point numbers giving the values of x, y, and c. </font>
		</p>
		<p>
				<font color="blue" size="5">Output</font>
				<br />
				<font face="Times New Roman" size="3">For each line of input, output one line with a floating point number giving the width of the street in feet, with three decimal digits in the fraction. </font>
		</p>
		<p>
				<font color="blue" size="5">Sample Input</font>
				<br />
				<font face="Times New Roman" size="3">
						<pre>30 40 10
12.619429 8.163332 3
10 10 3
10 10 1
</pre>
				</font>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
				<font color="blue" size="5">Sample Output</font>
				<br />
				<font face="Times New Roman" size="3">
						<pre>26.033
7.000
8.000
9.798
</pre>
				</font>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
				<font color="blue" size="5">Source</font>
				<br />
				<font face="Times New Roman" size="3">The UofA Local 2000.10.14<br /><br />My Code:<br /></font>
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> round(</span>
				<span style="COLOR: #0000ff">double</span>
				<span style="COLOR: #000000"> x, </span>
				<span style="COLOR: #0000ff">double</span>
				<span style="COLOR: #000000"> y, </span>
				<span style="COLOR: #0000ff">double</span>
				<span style="COLOR: #000000"> h) <br /><img id="Codehighlighter1_141_657_Open_Image" onclick="this.style.display='none'; Codehighlighter1_141_657_Open_Text.style.display='none'; Codehighlighter1_141_657_Closed_Image.style.display='inline'; Codehighlighter1_141_657_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_141_657_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_141_657_Closed_Text.style.display='none'; Codehighlighter1_141_657_Open_Image.style.display='inline'; Codehighlighter1_141_657_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_141_657_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_141_657_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000"> s1, s2, s;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000"> t, beg, end;<br /><img id="Codehighlighter1_196_222_Open_Image" onclick="this.style.display='none'; Codehighlighter1_196_222_Open_Text.style.display='none'; Codehighlighter1_196_222_Closed_Image.style.display='inline'; Codehighlighter1_196_222_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_196_222_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_196_222_Closed_Text.style.display='none'; Codehighlighter1_196_222_Open_Image.style.display='inline'; Codehighlighter1_196_222_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (x </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> y) </span>
						<span id="Codehighlighter1_196_222_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_196_222_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        s </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> sqrt(x</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">x</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">4</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">h</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">h);<br /><img id="Codehighlighter1_229_589_Open_Image" onclick="this.style.display='none'; Codehighlighter1_229_589_Open_Text.style.display='none'; Codehighlighter1_229_589_Closed_Image.style.display='inline'; Codehighlighter1_229_589_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_229_589_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_229_589_Closed_Text.style.display='none'; Codehighlighter1_229_589_Open_Image.style.display='inline'; Codehighlighter1_229_589_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> </span>
						<span id="Codehighlighter1_229_589_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_229_589_Open_Text">
								<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_244_263_Open_Image" onclick="this.style.display='none'; Codehighlighter1_244_263_Open_Text.style.display='none'; Codehighlighter1_244_263_Closed_Image.style.display='inline'; Codehighlighter1_244_263_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_244_263_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_244_263_Closed_Text.style.display='none'; Codehighlighter1_244_263_Open_Image.style.display='inline'; Codehighlighter1_244_263_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (y </span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000"> x) </span>
								<span id="Codehighlighter1_244_263_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_244_263_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            swap(x, y);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        beg </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        end </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> x;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        s </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> (beg </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> end) </span>
								<span style="COLOR: #000000">/</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        t </span>
								<span style="COLOR: #000000">=</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"> sqrt(x</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">x</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">s</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">s) </span>
								<span style="COLOR: #000000">+</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"> sqrt(y</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">y</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">s</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">s);<br /><img id="Codehighlighter1_389_586_Open_Image" onclick="this.style.display='none'; Codehighlighter1_389_586_Open_Text.style.display='none'; Codehighlighter1_389_586_Closed_Image.style.display='inline'; Codehighlighter1_389_586_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_389_586_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_389_586_Closed_Text.style.display='none'; Codehighlighter1_389_586_Open_Image.style.display='inline'; Codehighlighter1_389_586_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">while</span>
								<span style="COLOR: #000000"> (fabs(t</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">/</span>
								<span style="COLOR: #000000">h)</span>
								<span style="COLOR: #000000">&gt;</span>
								<span style="COLOR: #000000">0.000000001</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_389_586_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_389_586_Open_Text">
										<span style="COLOR: #000000">{<br /><img id="Codehighlighter1_407_450_Open_Image" onclick="this.style.display='none'; Codehighlighter1_407_450_Open_Text.style.display='none'; Codehighlighter1_407_450_Closed_Image.style.display='inline'; Codehighlighter1_407_450_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_407_450_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_407_450_Closed_Text.style.display='none'; Codehighlighter1_407_450_Open_Image.style.display='inline'; Codehighlighter1_407_450_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (t </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">/</span>
										<span style="COLOR: #000000">h) </span>
										<span id="Codehighlighter1_407_450_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_407_450_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                beg </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> s;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                s </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> (beg </span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000"> end) </span>
												<span style="COLOR: #000000">/</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">2</span>
												<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_470_513_Open_Image" onclick="this.style.display='none'; Codehighlighter1_470_513_Open_Text.style.display='none'; Codehighlighter1_470_513_Closed_Image.style.display='inline'; Codehighlighter1_470_513_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_470_513_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_470_513_Closed_Text.style.display='none'; Codehighlighter1_470_513_Open_Image.style.display='inline'; Codehighlighter1_470_513_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">else</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (t </span>
										<span style="COLOR: #000000">&gt;</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">/</span>
										<span style="COLOR: #000000">h) </span>
										<span id="Codehighlighter1_470_513_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_470_513_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                end </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> s;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                s </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> (beg </span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000"> end) </span>
												<span style="COLOR: #000000">/</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">2</span>
												<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_520_536_Open_Image" onclick="this.style.display='none'; Codehighlighter1_520_536_Open_Text.style.display='none'; Codehighlighter1_520_536_Closed_Image.style.display='inline'; Codehighlighter1_520_536_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_520_536_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_520_536_Closed_Text.style.display='none'; Codehighlighter1_520_536_Open_Image.style.display='inline'; Codehighlighter1_520_536_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">else</span>
										<span style="COLOR: #000000"> </span>
										<span id="Codehighlighter1_520_536_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_520_536_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
												<span style="COLOR: #0000ff">break</span>
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            t </span>
										<span style="COLOR: #000000">=</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"> sqrt(x</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000">x</span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">s</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000">s) </span>
										<span style="COLOR: #000000">+</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"> sqrt(y</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000">y</span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">s</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000">s);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> setiosflags(ios::</span>
						<span style="COLOR: #0000ff">fixed</span>
						<span style="COLOR: #000000">) </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> setprecision(</span>
						<span style="COLOR: #000000">3</span>
						<span style="COLOR: #000000">) </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> s </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main() <br /><img id="Codehighlighter1_672_754_Open_Image" onclick="this.style.display='none'; Codehighlighter1_672_754_Open_Text.style.display='none'; Codehighlighter1_672_754_Closed_Image.style.display='inline'; Codehighlighter1_672_754_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_672_754_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_672_754_Closed_Text.style.display='none'; Codehighlighter1_672_754_Open_Image.style.display='inline'; Codehighlighter1_672_754_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_672_754_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_672_754_Open_Text">
						<span style="COLOR: #000000">{ <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000"> x, y, h;<br /><img id="Codehighlighter1_720_741_Open_Image" onclick="this.style.display='none'; Codehighlighter1_720_741_Open_Text.style.display='none'; Codehighlighter1_720_741_Closed_Image.style.display='inline'; Codehighlighter1_720_741_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_720_741_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_720_741_Closed_Text.style.display='none'; Codehighlighter1_720_741_Open_Image.style.display='inline'; Codehighlighter1_720_741_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (cin </span>
						<span style="COLOR: #000000">&gt;&gt;</span>
						<span style="COLOR: #000000"> x </span>
						<span style="COLOR: #000000">&gt;&gt;</span>
						<span style="COLOR: #000000"> y </span>
						<span style="COLOR: #000000">&gt;&gt;</span>
						<span style="COLOR: #000000"> h) </span>
						<span id="Codehighlighter1_720_741_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_720_741_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        round(x, y, h);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.cppblog.com/qywyh/aggbug/6789.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-05-08 21:24 <a href="http://www.cppblog.com/qywyh/archive/2006/05/08/6789.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>4月16号 第二届SCUT/ICPC 7题纪实</title><link>http://www.cppblog.com/qywyh/archive/2006/04/18/5799.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Mon, 17 Apr 2006 16:02:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/04/18/5799.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/5799.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/04/18/5799.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/5799.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/5799.html</trackback:ping><description><![CDATA[
		<p>9点45 进场。来到64号机前，放好3本牛津高阶，一片紧张，电脑桌面上就只有pc^2的登陆界面。</p>
		<p>10点 比赛开始， 看了一下题， 看到在北大的上面做过的"TO THE MAX" ， 万分惊喜， 快速找出 《算法设计与分析》， 同时分配任务给我的队友, chgsh看A题， xp 看B题。心情很紧张，快速的敲这最大子矩阵和的函数， 当时想，这次第一次做出题目的肯定是我们了。。。敲好，提交， NO-wrong answer。心一下子塌下来， 这时候别对队很多都做出的A题(深红色气球)，和G题(粉红色气球)， 这时， chgsh的A题手写出来的， 我就过一旁看C题， 因为我觉得TO THE MAX应该是敲函数的时候出现了一点差错， 要找比较难， 还是先把简单题快点做出来， TO THE MAX晚点再改也行，反正我知道那题不会有太多人能做出来的。。</p>
		<p>10点30 chgsh的代码敲完， 调试没问题， 交， NO-wrong answer， 晕， 再改程序， 再交， NO-wrong answer！那时候我们的心情都凝结了， 没想到第一题都做不出， 看到很多红色气球都升起来的， 而我们队还一个气球都没有， 再检查代码， 原来漏掉了结束的标志， 改好， 交! "YES!", 我们不禁叫了出来， 我们互相握手，以示鼓励，毕竟这是0的突破， 意义很大啊！</p>
		<p>10点50 xp把写好的B题敲到电脑里面， 交， NO-wrong answer， xp检查代码， 这时我们心情也镇定了， 没有被这NO影响， 我续看C题， 想出来了， xp还在改， 我就继续看G题(这题当时已经有很多人做出来了,所以我想也不难), 想不到就是汉诺塔, 顿时信心十足。这时，晓萍再交程序 NO， 晕死。这时xp叫我一起检查程序，同时把算法告诉我， 我看了程序， 感觉程序一点都没错， 郁闷死。随手把pc^2点出来, 最郁闷的事情发生了， xp交题的时候选错题， 再交, YES! 第二道搞定!</p>
		<p>11点20 我决定先把E题(TO THE MAX)检查一遍, 果然, 变量n敲成k了, 改好提交, YES! 我差点跳了起来, 我自己终于做出一题了, 而且那题那个时候还没几个队做出来。chgsh和xp都很高兴， 我们再次握手以示鼓励！</p>
		<p>11点50 我继续敲G题(汉诺塔)， 抄了书上的递归程序， 测试， 超时， chgsh说把答案打表吧， 当时我灵机一动， 答案会不会有规律的呢， 决定做个循环把答案打印出来， Bingo, 果然, a[i+1] = 2*a[i] + 1。迅速把程序敲上，提交， YES!</p>
		<p>12点 我继续敲C题, 感觉这题比较简单,这时chgsh已经把D题(两页纸的E文)看懂了, 他就和xp商量D题, 而我就继续敲, 当时气氛又紧张了起来,  我想， 如果我把这题拿下了， 那我们对就完成了5题， 拿个小奖应该没问题了。 可能就是这样过于心急， 第一次提交没过， 检查时漏掉了一种情况， 改好交， YES! 看着我们面前那五个颜色的气球。这时已经是12点15分了， 看着面前的面包， 虽然肚子饿， 但是在这种气氛下， 怎么吃得下啊？</p>
		<p>
				<br />12点20分  结合chgsh和我对F题的理解， 觉得F题也不难， 不过F题要考虑的情况很多， 当时头脑发晕， 心情也急， 老是想快点把第6题也做出来(因为这时旁边的队也做了5题)， 于是没有对情况仔细分析， 就去敲代码。。。</p>
		<p>
				<br />13点  代码敲好了， SAMPLE通过， 交吧， NO-wrong answer, 早有预感， 这时xp在手写D题，我想了下我的程序， n个if, n个case, 好混乱， 乱改了一下， 交，在NO-wrong answer， 没法了， 我坐在那里，头好晕。。这时， xp说他的代码写好了，让他试试，OK， 正好我也去冷静下， 仔细想想， F题的情况。</p>
		<p>14点 xp敲代码， 而我还在那里发呆， 偶尔看看xp的代码， n个for语句(那题我题意都没理解), 也看不懂他的算法, 头脑就还在发热, 郁闷! 这是chgsh跑过来和我说F题的解法, 给了他想的几个测试数据我, 那几个测试数据就像是救命的灵药, 我开始重新整理思路, 想好F题要改的地方, 这时xp的程序SAMPLE都还没通过, 于是就让我先改F题, 大家都觉得, 做出F题的机会比较大。于是我把我的程序又改了一遍， 再交还是NO-wrong answer。。。。。这时已经离比赛结束只剩下20分钟了。</p>
		<p>14点40分  我们的心情都异常的紧张， 因为这时候已经有不少的队伍已经做出了5题(我们旁边那队早就做出了6题了)， 而且我们罚时比较多， 所以情况对我们很不利， 我们必须做出第6题才能有较大的机会拿奖。可是， 对F题， 我已经没有办法了， xp的D题他也没把握， 这时候， chgsh又想到了几个使我的程序错的测试数据， 于是赶紧改上， 没问题， 交。这时候只剩下不到15分钟了， 返回结果：YES!  居然YES了, 是YES!那种感觉, 只能用狂喜来形容!我们再次握手, 我们有机会了!</p>
		<p>14点45分 我们还没有放弃, xp上去改他的D题, 居然前两组SAMPLE过了, 叫他赶紧交, 交了再改, 只剩下10分钟了, NO-wrong answer! 这是我们三个一起注视这显示器, 到底那里错呢? 按我的经验, 肯定是溢出问题, 于是叫xp把程序里的1e10改成1000000000交上去试试。 本就没想过能过的， 谁知道， 跳出一个YES的对话框， "过了?" , "我们队做了7题了！"， "xp你太厉害了"， 我们兴奋得差点从椅子上跳起来。我想现在最不爽的肯定是我们旁边的那队， 一直领先我们， 居然在最后20分钟出现了奇迹。。。</p>
		<p>15点 比赛结束 周杰老师公布:"有2支队做完了8题， 两支队做了7题。。。" <br /></p>
		<p>
				<br />后记：这次比赛， 给我的唯一感觉就是神奇， 真的是太神奇了， 特别是最后20分钟做出两题， 是三个人合作的成果， 这就是ACM的乐趣， 在这， 我要感谢我的队友chgsh和xp, 我要说："AUCS， 好样的!"<br /><br /><br />我们队(team64)的排名:<br /><img height="177" alt="r_rank.jpg" src="http://www.cppblog.com/images/cppblog_com/qywyh/538/r_rank.jpg" width="178" border="0" /><br /><br /></p>
<img src ="http://www.cppblog.com/qywyh/aggbug/5799.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-04-18 00:02 <a href="http://www.cppblog.com/qywyh/archive/2006/04/18/5799.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>终于做出了一题IOI了，有点心得。</title><link>http://www.cppblog.com/qywyh/archive/2006/02/21/3369.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Tue, 21 Feb 2006 05:09:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/02/21/3369.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/3369.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/02/21/3369.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/3369.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/3369.html</trackback:ping><description><![CDATA[<P align=center><FONT color=blue size=5>The Triangle</FONT> <BR>Time Limit:1000MS&nbsp; Memory Limit:10000K</P>
<P><FONT color=blue size=5>Description</FONT><BR><FONT face="Times New Roman" size=3>
<CENTER><PRE>7
<BR>3   8
<BR>8   1   0
<BR>2   7   4   4
<BR>4   5   2   6   5
<BR>
<BR>(Figure 1)</PRE></CENTER><BR>Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right. <BR></FONT>
<P></P>
<P><FONT color=blue size=5>Input</FONT><BR><FONT face="Times New Roman" size=3>Your program is to read from standard input. The first line contains one integer N: the number of rows in the triangle. The following N lines describe the data of the triangle. The number of rows in the triangle is &gt; 1 but &lt;= 100. The numbers in the triangle, all integers, are between 0 and 99. </FONT></P>
<P><FONT color=blue size=5>Output</FONT><BR><FONT face="Times New Roman" size=3>Your program is to write to standard output. The highest sum is written as an integer.</FONT></P>
<P><FONT color=blue size=5>Sample Input</FONT><BR><FONT face="Times New Roman" size=3><PRE>5
7
3 8
8 1 0 
2 7 4 4
4 5 2 6 5</PRE></FONT>
<P></P>
<P><FONT color=blue size=5>Sample Output</FONT><BR><FONT face="Times New Roman" size=3><PRE>30</PRE></FONT>
<P></P>
<P><FONT color=blue size=5>Source</FONT><BR><FONT face="Times New Roman" size=3>IOI 1994<BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;main()<BR><IMG id=Codehighlighter1_52_752_Open_Image onclick="this.style.display='none'; Codehighlighter1_52_752_Open_Text.style.display='none'; Codehighlighter1_52_752_Closed_Image.style.display='inline'; Codehighlighter1_52_752_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_52_752_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_52_752_Closed_Text.style.display='none'; Codehighlighter1_52_752_Open_Image.style.display='inline'; Codehighlighter1_52_752_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_52_752_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_52_752_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;n,digital_num;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;result[</SPAN><SPAN style="COLOR: #000000">100</SPAN><SPAN style="COLOR: #000000">][</SPAN><SPAN style="COLOR: #000000">100</SPAN><SPAN style="COLOR: #000000">];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">num;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i,j;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;cin</SPAN><SPAN style="COLOR: #000000">&gt;&gt;</SPAN><SPAN style="COLOR: #000000">n;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;digital_num&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;n;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;num&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">[digital_num];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(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</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">n;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_216_638_Open_Image onclick="this.style.display='none'; Codehighlighter1_216_638_Open_Text.style.display='none'; Codehighlighter1_216_638_Closed_Image.style.display='inline'; Codehighlighter1_216_638_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_216_638_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_216_638_Closed_Text.style.display='none'; Codehighlighter1_216_638_Open_Image.style.display='inline'; Codehighlighter1_216_638_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_216_638_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_216_638_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(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</SPAN><SPAN style="COLOR: #000000">&lt;=</SPAN><SPAN style="COLOR: #000000">i;&nbsp;j</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_245_635_Open_Image onclick="this.style.display='none'; Codehighlighter1_245_635_Open_Text.style.display='none'; Codehighlighter1_245_635_Closed_Image.style.display='inline'; Codehighlighter1_245_635_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_245_635_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_245_635_Closed_Text.style.display='none'; Codehighlighter1_245_635_Open_Image.style.display='inline'; Codehighlighter1_245_635_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_245_635_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_245_635_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</SPAN><SPAN style="COLOR: #000000">&gt;&gt;</SPAN><SPAN style="COLOR: #000000">num[j];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(i</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result[i][j]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;num[j];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(i</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_318_631_Open_Image onclick="this.style.display='none'; Codehighlighter1_318_631_Open_Text.style.display='none'; Codehighlighter1_318_631_Closed_Image.style.display='inline'; Codehighlighter1_318_631_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_318_631_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_318_631_Closed_Text.style.display='none'; Codehighlighter1_318_631_Open_Image.style.display='inline'; Codehighlighter1_318_631_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_318_631_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_318_631_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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">&nbsp;(j</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result[i][j]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;result[i</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">][j]</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">num[j];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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">&nbsp;(j</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">i)<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result[i][j]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;result[i</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">][j</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">num[j];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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">&nbsp;(j</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">&amp;&amp;</SPAN><SPAN style="COLOR: #000000">j</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">i)<BR><IMG id=Codehighlighter1_458_626_Open_Image onclick="this.style.display='none'; Codehighlighter1_458_626_Open_Text.style.display='none'; Codehighlighter1_458_626_Closed_Image.style.display='inline'; Codehighlighter1_458_626_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_458_626_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_458_626_Closed_Text.style.display='none'; Codehighlighter1_458_626_Open_Image.style.display='inline'; Codehighlighter1_458_626_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_458_626_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_458_626_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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">&nbsp;(result[i</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">][j]</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">result[i</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">][j</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">])<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result[i][j]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;result[i</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">][j]</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">num[j];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result[i][j]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;result[i</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">][j</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">num[j];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(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</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">n;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(result[n</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">][i]</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">max)<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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;result[n</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">][i];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;cout</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">max</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">endl;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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 src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></FONT>上面是通过的原程序。140k,15MS。<BR><BR><BR>这道题目，过得好辛苦，从开始的递归，到递推加回溯，到穷举，到穷举加剪枝，结果就从TLE-&gt;TLE-&gt;TLE-&gt;WA.&nbsp; 一直用着要保留路径的方法，所以怎么也做不出来，后来换了个思维角度，保存每一步的结果，动态规划，终于就AC了。做了这题，另我复习了好几种方法，也对DP有了深得认识，可以说这是搞竞赛的好题目，经典，推荐！！<img src ="http://www.cppblog.com/qywyh/aggbug/3369.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-02-21 13:09 <a href="http://www.cppblog.com/qywyh/archive/2006/02/21/3369.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>今天又过条简单题,呵呵</title><link>http://www.cppblog.com/qywyh/archive/2006/02/08/3141.html</link><dc:creator>豪</dc:creator><author>豪</author><pubDate>Wed, 08 Feb 2006 15:40:00 GMT</pubDate><guid>http://www.cppblog.com/qywyh/archive/2006/02/08/3141.html</guid><wfw:comment>http://www.cppblog.com/qywyh/comments/3141.html</wfw:comment><comments>http://www.cppblog.com/qywyh/archive/2006/02/08/3141.html#Feedback</comments><slash:comments>14</slash:comments><wfw:commentRss>http://www.cppblog.com/qywyh/comments/commentRss/3141.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/qywyh/services/trackbacks/3141.html</trackback:ping><description><![CDATA[原题: <FONT color=#0000ff size=5>A Simple Task</FONT><BR>Given a positive integer n and the odd integer o and the nonnegative<BR>integer p such that n = o2^p.<BR><BR><BR>Example<BR><BR>For n = 24, o = 3 and p = 3.<BR><BR><BR>Task<BR><BR>Write a program which for each data set:<BR><BR>reads a positive integer n,<BR><BR>computes the odd integer o and the nonnegative integer p such that n = o2^p,<BR><BR>writes the result.<BR><BR><BR>Input<BR><BR>The first line of the input contains exactly one positive integer d<BR>equal to the number of data sets, 1 &lt;= d &lt;= 10. The data sets follow.<BR><BR>Each data set consists of exactly one line containing exactly one<BR>integer n, 1 &lt;= n &lt;= 10^6.<BR><BR><BR>Output<BR><BR><BR>Line i, 1 &lt;= i &lt;= d, corresponds to the i-th input and should contain two<BR>integers o and p separated by a single space such that n = o2^p.<BR><BR><BR>Sample Input<BR><BR>1<BR>24<BR><BR><BR>Sample Output<BR><BR>3 3<BR>
<CENTER><FONT color=blue size=+2><BR></FONT>&nbsp;</CENTER>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top>#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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></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 src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;main()<BR><IMG id=Codehighlighter1_68_654_Open_Image onclick="this.style.display='none'; Codehighlighter1_68_654_Open_Text.style.display='none'; Codehighlighter1_68_654_Closed_Image.style.display='inline'; Codehighlighter1_68_654_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_68_654_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_68_654_Closed_Text.style.display='none'; Codehighlighter1_68_654_Open_Image.style.display='inline'; Codehighlighter1_68_654_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_68_654_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_68_654_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;set_num;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #0000ff">set</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;NULL;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i,j,k;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;temp;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">bool</SPAN><SPAN style="COLOR: #000000">&nbsp;flag;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;cin</SPAN><SPAN style="COLOR: #000000">&gt;&gt;</SPAN><SPAN style="COLOR: #000000">set_num;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">set</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">[set_num];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;i</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">set_num;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</SPAN><SPAN style="COLOR: #000000">&gt;&gt;</SPAN><SPAN style="COLOR: #0000ff">set</SPAN><SPAN style="COLOR: #000000">[i];<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;i</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">set_num;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_251_639_Open_Image onclick="this.style.display='none'; Codehighlighter1_251_639_Open_Text.style.display='none'; Codehighlighter1_251_639_Closed_Image.style.display='inline'; Codehighlighter1_251_639_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_251_639_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_251_639_Closed_Text.style.display='none'; Codehighlighter1_251_639_Open_Image.style.display='inline'; Codehighlighter1_251_639_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_251_639_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_251_639_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">set</SPAN><SPAN style="COLOR: #000000">[i]</SPAN><SPAN style="COLOR: #000000">%</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_274_322_Open_Image onclick="this.style.display='none'; Codehighlighter1_274_322_Open_Text.style.display='none'; Codehighlighter1_274_322_Closed_Image.style.display='inline'; Codehighlighter1_274_322_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_274_322_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_274_322_Closed_Text.style.display='none'; Codehighlighter1_274_322_Open_Image.style.display='inline'; Codehighlighter1_274_322_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_274_322_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_274_322_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #0000ff">set</SPAN><SPAN style="COLOR: #000000">[i]</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">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">endl;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">continue</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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">false</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(j&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">;j</SPAN><SPAN style="COLOR: #000000">&lt;=</SPAN><SPAN style="COLOR: #0000ff">set</SPAN><SPAN style="COLOR: #000000">[i]</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">;j</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_385_636_Open_Image onclick="this.style.display='none'; Codehighlighter1_385_636_Open_Text.style.display='none'; Codehighlighter1_385_636_Closed_Image.style.display='inline'; Codehighlighter1_385_636_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_385_636_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_385_636_Closed_Text.style.display='none'; Codehighlighter1_385_636_Open_Image.style.display='inline'; Codehighlighter1_385_636_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_385_636_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_385_636_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp&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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">(temp</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #0000ff">set</SPAN><SPAN style="COLOR: #000000">[i])<BR><IMG id=Codehighlighter1_433_608_Open_Image onclick="this.style.display='none'; Codehighlighter1_433_608_Open_Text.style.display='none'; Codehighlighter1_433_608_Closed_Image.style.display='inline'; Codehighlighter1_433_608_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_433_608_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_433_608_Closed_Text.style.display='none'; Codehighlighter1_433_608_Open_Image.style.display='inline'; Codehighlighter1_433_608_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_433_608_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_433_608_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;j</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">pow(</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">,k);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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">&nbsp;(temp</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #0000ff">set</SPAN><SPAN style="COLOR: #000000">[i])<BR><IMG id=Codehighlighter1_487_578_Open_Image onclick="this.style.display='none'; Codehighlighter1_487_578_Open_Text.style.display='none'; Codehighlighter1_487_578_Closed_Image.style.display='inline'; Codehighlighter1_487_578_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_487_578_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_487_578_Closed_Text.style.display='none'; Codehighlighter1_487_578_Open_Image.style.display='inline'; Codehighlighter1_487_578_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_487_578_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_487_578_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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">j</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">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">k</SPAN><SPAN style="COLOR: #000000">&lt;&lt;</SPAN><SPAN style="COLOR: #000000">endl;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(flag)<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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 src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&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 src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></SPAN></DIV>上面是我提交的程序<BR>在zju提交编译错误一次&nbsp; 因为标准c++&nbsp;&nbsp; pow函数为 pow(double,&lt;type&gt;)第一个参数必须为double,但是我再shantou 上用pow(int,int)就过了,都是编译器惹的祸...<img src ="http://www.cppblog.com/qywyh/aggbug/3141.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/qywyh/" target="_blank">豪</a> 2006-02-08 23:40 <a href="http://www.cppblog.com/qywyh/archive/2006/02/08/3141.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>