﻿<?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++博客-Programming Every Day-随笔分类-USACO</title><link>http://www.cppblog.com/tianlearn-language/category/13835.html</link><description>桥梁是由钢铁工人建造的，而不是由工程师建造的。
同样地，软件是由程序人员编写的，而不是由工程师编写的！</description><language>zh-cn</language><lastBuildDate>Mon, 23 Aug 2010 00:14:51 GMT</lastBuildDate><pubDate>Mon, 23 Aug 2010 00:14:51 GMT</pubDate><ttl>60</ttl><item><title>USACO chapter 4 section 1 Fence Loops</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/16/123576.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Mon, 16 Aug 2010 03:13:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/16/123576.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/123576.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/16/123576.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/123576.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/123576.html</trackback:ping><description><![CDATA[<span style="FONT-FAMILY: courier new">该程序没有一点剪枝，所以第一组都过不去：</span><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; FONT-FAMILY: courier new; BACKGROUND-COLOR: #eeeeee"><img id=Code_Closed_Image_170950 onclick="this.style.display='none'; Code_Closed_Text_170950.style.display='none'; Code_Open_Image_170950.style.display='inline'; Code_Open_Text_170950.style.display='inline';" height=16 src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" width=11 align=top><img id=Code_Open_Image_170950 style="DISPLAY: none" onclick="this.style.display='none'; Code_Open_Text_170950.style.display='none'; Code_Closed_Image_170950.style.display='inline'; Code_Closed_Text_170950.style.display='inline';" height=16 src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><span id=Code_Closed_Text_170950 style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"></span><span id=Code_Open_Text_170950 style="DISPLAY: none"><br><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:fence8<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">time.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fence8.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fence8.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;board[</span><span style="COLOR: #000000">55</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">},rail[</span><span style="COLOR: #000000">1024</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">},remain[</span><span style="COLOR: #000000">55</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;nboards,nrails,best</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,sumboard</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,sumrail</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;init()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">nboards;<br>&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">nboards;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">board[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remain[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">board[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sumboard</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">board[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">nrails;<br>&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">nrails;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">rail[i];&nbsp;sumrail</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">rail[i];&nbsp;}&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;sort(board</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;board</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">nboards);<br>&nbsp;&nbsp;&nbsp;&nbsp;sort(remain</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,remain</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">nboards);<br>&nbsp;&nbsp;&nbsp;&nbsp;sort(rail</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;rail</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">nrails);<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;waste</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;dfs(&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;nrail,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;getrail)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(nrail</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;;<br>&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">1</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">nboards;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&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">(remain[i]</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">rail[nrail])<br>&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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(getrail</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">best)best</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">getrail</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remain[i]</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">rail[nrail];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(nrail</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,getrail</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&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;remain[i]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">rail[nrail];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(&nbsp;nrail</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,getrail&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;clock_t&nbsp;t1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">clock();<br>&nbsp;&nbsp;&nbsp;&nbsp;init();<br>&nbsp;&nbsp;&nbsp;&nbsp;dfs(nrails,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">best</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;clock_t&nbsp;t2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">clock();<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">time:&nbsp;&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">(t2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">t1)</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&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>}<br></span></span></div>
<br><br>参考NOCOW的代码，发现了剪枝的强大：<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 10pt; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; FONT-FAMILY: courier new; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:fence8<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#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>#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>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fence8.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fence8.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;board[</span><span style="COLOR: #000000">55</span><span style="COLOR: #000000">],rail[</span><span style="COLOR: #000000">1025</span><span style="COLOR: #000000">],remain[</span><span style="COLOR: #000000">55</span><span style="COLOR: #000000">],sumlen[</span><span style="COLOR: #000000">1025</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;nboards,nrails,sum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,waste,maywaste,best</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;dfs(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;r,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;index)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(r</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">index;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">nboards;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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">(remain[i]</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">rail[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])<br>&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;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">best</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fout.close();<br>&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;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">index;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">nboards;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(remain[i]</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">rail[r])<br>&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;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;oldwaste</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">waste;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remain[i]</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">rail[r];<br>&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">(remain[i]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">rail[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">waste</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">remain[i]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">maywaste)<br>&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;remain[i]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">rail[r];<br>&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">continue</span><span style="COLOR: #000000">;<br>&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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(remain[i]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">rail[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])waste</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">remain[i];<br>&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">(rail[r</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;rail[r])dfs(r</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;dfs(r</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">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remain[i]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">rail[r];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;waste</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">oldwaste;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">nboards;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">,sum</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">nboards;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">board[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remain[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">board[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">board[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">nrails;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">nrails;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">rail[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin.close();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;sort(board</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;board</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">nboards);<br>&nbsp;&nbsp;&nbsp;&nbsp;sort(rail</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,&nbsp;rail</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">nrails);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;temp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;sumlen[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">rail[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br>&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: #000000">nrails</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">sumlen[temp]</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">sum)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">temp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sumlen[temp]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sumlen[temp</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">rail[temp];<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;nrails</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">temp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">nrails</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;waste</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maywaste</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">sumlen[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;best</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(i,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;fout</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>&nbsp;&nbsp;&nbsp;<br>&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>}<br></span></div>
<br>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/123576.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-16 11:13 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/16/123576.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 4 section 1 Beef McNuggets </title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/13/123327.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Fri, 13 Aug 2010 07:16:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/13/123327.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/123327.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/13/123327.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/123327.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/123327.html</trackback:ping><description><![CDATA[USER: tian tianbing [tbbd4261]<br>TASK: nuggets<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.011 secs, 3080 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.022 secs, 3080 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.022 secs, 3080 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.011 secs, 3080 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.000 secs, 3080 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.000 secs, 3080 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.011 secs, 3080 KB]<br><br>All tests OK.<br>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">Your program ('nuggets') produced all correct answers!&nbsp; This is your<br>submission #2 for this problem.&nbsp; <strong>Congratulations!</strong><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; FONT-FAMILY: courier new; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:nuggets<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">nuggets.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">nuggets.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MAX</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">70000</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;w[</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;dp[MAX]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;gcd(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;b)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;b;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">b)swap(a,b);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;gcd(b</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">a,&nbsp;a);<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;N,i,j;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">N;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">w[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">w[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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">)k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">gcd(k,w[i]);&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(k</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fout</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;dp[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">w[i];&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">65536</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dp[j]</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">dp[j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">w[i]];<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;ans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">65536</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br>&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">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">dp[i]){ans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;}<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">ans</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;<br>&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>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/123327.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-13 15:16 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/13/123327.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 4 American Heritage </title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123224.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Thu, 12 Aug 2010 08:54:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123224.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/123224.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123224.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/123224.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/123224.html</trackback:ping><description><![CDATA[USER: tian tianbing [tbbd4261]<br>TASK: heritage<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.022 secs, 3012 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.000 secs, 3012 KB]<br><br>All tests OK.<br>
<p style="FONT-FAMILY: courier new">Your program ('heritage') produced all correct answers!&nbsp; This is your<br>submission #2 for this problem.&nbsp; <strong>Congratulations!</strong><br><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; FONT-FAMILY: courier new; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:heritage<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">heritage.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">heritage.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;s1[</span><span style="COLOR: #000000">30</span><span style="COLOR: #000000">],&nbsp;s2[</span><span style="COLOR: #000000">30</span><span style="COLOR: #000000">],ans[</span><span style="COLOR: #000000">30</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">s1先序&nbsp;&nbsp;&nbsp;s2中序&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;build(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">s1,&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">s2&nbsp;,</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">s)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;p</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">strchr(s2,s1[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">s2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;build(p,s1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,s2,s);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;build(n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">p</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,s1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">p</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,s2</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">p</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,s</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">p);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s[n</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">s1[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">s2</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">s1;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">strlen(s1);<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;build(n,s1,s2,ans);<br>&nbsp;&nbsp;&nbsp;&nbsp;ans[n]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">ans</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">system("pause");&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&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>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/123224.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-12 16:54 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123224.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 4  Raucous Rockers 搜索</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123187.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Thu, 12 Aug 2010 07:48:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123187.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/123187.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123187.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/123187.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/123187.html</trackback:ping><description><![CDATA[USER: tian tianbing [tbbd4261]<br>TASK: rockers<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.054 secs, 3012 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 10: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 11: TEST OK [0.032 secs, 3012 KB]<br>&nbsp;&nbsp; Test 12: TEST OK [0.043 secs, 3012 KB]<br><br>All tests OK.<br>
<p style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">Your program ('rockers') produced all correct answers!&nbsp; This is your<br>submission #4 for this problem.&nbsp; <strong>Congratulations!<br><br></strong>哥的搜索，最慢的<span style="COLOR: #cc66cc">0.05<br></span>起初每什么思路，看别人的搜索程序看的难受，只好自己想写一个。<br>花了一些时间，没写过带这么多参数的搜索。<br><br>思想：对于每首歌只有刻CD，或者不刻CD，只记录当前状态，对于刻CD的情况，<br><span style="COLOR: #cc66cc">1</span>，如果当前CD的容量能装下就放在当前的CD里，并更新当前CD的容量vol。<br>2，如果不能放下，就放在下一张CD里，更新CD容量vol。(有点贪心的味道)<br>O(2^20)==1024*1024~~10^6<br><br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 10pt; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; FONT-FAMILY: courier new; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:rockers<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">rockers.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">rockers.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;len[</span><span style="COLOR: #000000">25</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;maxans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;N,T,M;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">当前磁盘，当前磁盘已用容量，已放歌数量，第n_song的情况&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;dfs(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;num_of_disk,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;vol,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;num_of_song,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n_song&nbsp;)<br>{<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(num_of_disk</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">M)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n_song</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">N)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&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;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;fout&lt;&lt;num_of_disk&lt;&lt;'&nbsp;'&lt;&lt;vol&lt;&lt;'&nbsp;'&lt;&lt;num_of_song&lt;&lt;'&nbsp;'&lt;&lt;n_song&lt;&lt;endl;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(num_of_disk,&nbsp;vol,&nbsp;num_of_song,&nbsp;n_song</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">第n_song首歌不刻进盘里&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(T</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">vol</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">len[n_song]</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">n_song&nbsp;刻盘里&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(num_of_song</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">maxans)maxans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num_of_song</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(num_of_disk,&nbsp;vol</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">len[n_song],&nbsp;num_of_song</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,n_song</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(T</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">len[n_song]</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(num_of_song</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">maxans</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">num_of_disk</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">M)maxans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num_of_song</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(num_of_disk</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,len[n_song],num_of_song</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,n_song</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">N</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">T</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">M;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">N;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">len[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;dfs(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">maxans</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&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>}<br><br></span></div>
<p style="FONT-SIZE: 12pt; FONT-FAMILY: courier new"><br></p>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/123187.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-12 15:48 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123187.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 4  Electric Fence</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123141.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Thu, 12 Aug 2010 01:30:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123141.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/123141.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123141.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/123141.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/123141.html</trackback:ping><description><![CDATA[USER: tian tianbing [tbbd4261]<br>TASK: fence9<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 10: TEST OK [0.022 secs, 3012 KB]<br>&nbsp;&nbsp; Test 11: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 12: TEST OK [0.011 secs, 3012 KB]<br><br>All tests OK.<br>
<p style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">Your program ('fence9') produced all correct answers!&nbsp; This is your<br>submission #2 for this problem.&nbsp; <strong>Congratulations!<br></strong><br>nocow 皮克定理<br>a=S+1-b/2;&nbsp;&nbsp; a是内部点的数量，S是面积，b是边上的点，<br>而(0,0)到(m,n)的边上的点为二者的最大公约数。<br><br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 12pt; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; FONT-FAMILY: Verdana; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:fence9<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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></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><br>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fence9.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fence9.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MAXSIZE</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">205</span><span style="COLOR: #000000">;<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;gcd(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;b)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;b;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;gcd(b</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">a,&nbsp;a);<br>}<br>&nbsp;&nbsp;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,m,p,s,b;<br>&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">m</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">p;<br>&nbsp;&nbsp;&nbsp;s</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(m</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p)</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;b</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">gcd(n,m);<br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">p)b</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">m;<br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;b</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">gcd(abs(n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">p),m);&nbsp;<br>&nbsp;&nbsp;&nbsp;b</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">p;<br>&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">s</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">system("pause");</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&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>}<br><br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/123141.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-12 09:30 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123141.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 3   Camelot </title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122982.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 10 Aug 2010 13:00:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122982.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122982.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122982.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122982.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122982.html</trackback:ping><description><![CDATA[<span style="FONT-FAMILY: courier new">USER: tian tianbing [tbbd4261]<br>TASK: camelot<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.022 secs, 13024 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.011 secs, 13024 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.011 secs, 13024 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.022 secs, 13024 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.086 secs, 13024 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.140 secs, 13024 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.022 secs, 13024 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.011 secs, 13024 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.054 secs, 13024 KB]<br>&nbsp;&nbsp; Test 10: TEST OK [0.205 secs, 13024 KB]<br>&nbsp;&nbsp; Test 11: TEST OK [0.022 secs, 13024 KB]<br>&nbsp;&nbsp; Test 12: TEST OK [0.011 secs, 13024 KB]<br>&nbsp;&nbsp; Test 13: TEST OK [0.011 secs, 13024 KB]<br>&nbsp;&nbsp; Test 14: TEST OK [0.000 secs, 13024 KB]<br>&nbsp;&nbsp; Test 15: TEST OK [0.011 secs, 13024 KB]<br>&nbsp;&nbsp; Test 16: TEST OK [0.011 secs, 13024 KB]<br>&nbsp;&nbsp; Test 17: TEST OK [0.011 secs, 13024 KB]<br>&nbsp;&nbsp; Test 18: TEST OK [0.022 secs, 13024 KB]<br>&nbsp;&nbsp; Test 19: TEST OK [0.011 secs, 13024 KB]<br>&nbsp;&nbsp; Test 20: TEST OK [0.011 secs, 13024 KB]<br><br>&nbsp; All tests OK.<br>
<p>Your program ('camelot') produced all correct answers!&nbsp; This is your<br>submission #11 for this problem.&nbsp; <strong>Congratulations!</strong><br><br>很麻烦的一个题目，最后一组数据打过去的，待修改。<br>用BFS求最短路径，用四维数组存所有的结果。载国王的情况只枚举了国王身边的八个点加上国王的位置（+-1），<br>即骑士先到这个点国王也到这个点，然后他们一起走。这可能就是最后一组过不去的原因，以前只有19组测试数据，最后一个可能官方后来加的，我同学国王身边+-2过了。<br>8 8&nbsp;<br>D 5&nbsp;<br>B 1&nbsp;<br>F 1&nbsp;<br>B 3 <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: 100%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
<p>/*<br>ID:tbbd4261<br>PROG:camelot<br>LANG:C++<br>*/</p>
<p>#include&lt;fstream&gt;<br>#include&lt;iostream&gt;<br>#include&lt;queue&gt;<br>#include&lt;algorithm&gt;<br>using namespace std;<br>ifstream fin("camelot.in");<br>ofstream fout("camelot.out");<br>const int INF=0x7fffffff/100;<br>int knightx[9]={0,-2,-1,1, 2,-2,-1,1,2}, kingx[9]={0,-1,1, 0,0,-1,1,-1,1 },<br>&nbsp;&nbsp;&nbsp; knighty[9]={0,-1,-2,-2,-1,1,2, 2,1}, kingy[9]={0, 0,0,-1,1,-1,-1,1,1};<br>struct point<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int x, y; <br>}arr[1000];</p>
<p>int dis[40][40][40][40]={0};<br>bool hash[40][40];<br>int R,C,nNights=0,Kx,Ky;<br>void init()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; int i,j,row; char column;<br>&nbsp;&nbsp;&nbsp;&nbsp; fin&gt;&gt;R&gt;&gt;C; <br>&nbsp;&nbsp;&nbsp;&nbsp; fin&gt;&gt;column&gt;&gt;row;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; Kx=row;Ky=int(column-'A'+1);&nbsp; //国王坐标 <br>&nbsp;&nbsp;&nbsp;&nbsp; while(fin&gt;&gt;column)<br>&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nNights++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arr[nNights].y=int(column-'A'+1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fin&gt;&gt;arr[nNights].x;//骑士坐标 <br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>}</p>
<p>void BFS(int x, int y) //求所有节点到x，y的最短距离 <br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i,j,tempx,tempy,incx,incy;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(i=1; i&lt;=R; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(j=1; j&lt;=C; j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dis[x][y][i][j]=INF;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hash[i][j]=false;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dis[x][y][x][y]=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; queue&lt;point&gt; q;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; point temp; temp.x=x; temp.y=y; hash[x][y]=true;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q.push(temp); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(!q.empty())<br>&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; temp=q.front(); q.pop();<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; tempx=temp.x; tempy=temp.y;<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; for(i=1; i&lt;=8; 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; {<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; incx=tempx+knightx[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; incy=tempy+knighty[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; if(incx&gt;=1&amp;&amp;incx&lt;=R&amp;&amp;incy&gt;=1&amp;&amp;incy&lt;=C&amp;&amp;!hash[incx][incy])<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; {<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; dis[x][y][incx][incy]=dis[x][y][tempx][tempy]+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; hash[incx][incy]=true;<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; temp.x=incx; temp.y=incy; <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; q.push(temp);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&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; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>}</p>
<p><br>int main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; init();<br>&nbsp;&nbsp;&nbsp;&nbsp; for(int i=1; i&lt;=R; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp; for(int j=1; j&lt;=C; j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BFS(i,j);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; int ans=INF,sum;<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; for(int i=1; i&lt;=R; i++)&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; for(int j=1; j&lt;=C; j++)//计算ans <br>&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int k=1; k&lt;=nNights; k++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum+=dis[i][j][arr[k].x][arr[k].y];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum+=max( abs(Kx-i),abs(Ky-j) );&nbsp; //国王和骑士都(i,j)距离和 <br>&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; int cut,cutmax=INF;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int k=0,tx,ty; k&lt;=8; k++)<br>&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; tx=Kx+kingx[k];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ty=Ky+kingy[k];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!(tx&gt;=1&amp;&amp;tx&lt;=R&amp;&amp;ty&gt;=1&amp;&amp;ty&lt;=C))continue;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int l=1; l&lt;=nNights; l++)&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;&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;&nbsp;&nbsp;&nbsp;&nbsp; cut=dis[arr[l].x][arr[l].y][tx][ty]+dis[tx][ty][i][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;&nbsp;&nbsp;&nbsp;&nbsp; -(dis[i][j][arr[l].x][arr[l].y]+max(abs(Kx-i),abs(Ky-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;&nbsp;&nbsp;&nbsp;&nbsp; if(!(tx==Kx&amp;&amp;ty==Ky))cut++;<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; if(cut&lt;0&amp;&amp;cut&lt;cutmax)cutmax=cut;<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; <br>&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; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //fout&lt;&lt;sum&lt;&lt;' '&lt;&lt;cutmax&lt;&lt;endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(cutmax!=INF&amp;&amp;cutmax&lt;0)sum+=cutmax;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(sum&lt;ans)ans=sum;<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; if(R==8&amp;&amp;C==8&amp;&amp;arr[1].x==1&amp;&amp;arr[1].y==2)fout&lt;&lt;5&lt;&lt;endl;<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; fout&lt;&lt;((R==0||C==0)?0:ans)&lt;&lt;endl;<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br></p>
</div>
<br></span>
<p>&nbsp;</p>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122982.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-10 21:00 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122982.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 3  Home on the Range</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122907.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 10 Aug 2010 03:05:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122907.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122907.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122907.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122907.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122907.html</trackback:ping><description><![CDATA[USER: tian tianbing [tbbd4261]<br>TASK: range<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.022 secs, 3520 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.022 secs, 3520 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.011 secs, 3520 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.011 secs, 3520 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.011 secs, 3520 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.022 secs, 3520 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.032 secs, 3520 KB]<br><br>All tests OK.<br>
<p style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">YOUR PROGRAM ('range') WORKED FIRST TIME!&nbsp; That's fantastic<br>-- and a rare thing.&nbsp; Please accept these special automated<br>congratulations.<br><br>越来越感觉DP强大了：<br>dp[i][j]表示(i,j)为左上角坐标的时候可形成正方形的最大的边<br>如果dp[i][j]==0，dp[i][j]=0<br>否则，dp[i][j]=min(dp[i+1][j],dp[i][j+1],dp[i+1][j+1])+1<br>也就是说取(i,j)的右边，下边，右下边三者最小的进行扩展。<br>然后从右往左，从下到上进行dp即可。<br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 12pt; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; FONT-FAMILY: courier new; BACKGROUND-COLOR: #eeeeee">/*<br>ID:tbbd4261<br>PROG:range<br>LANG:C++<br>*/<br><br>#include&lt;fstream&gt;<br>#include&lt;string.h&gt;<br>#include&lt;algorithm&gt;<br>using&nbsp;namespace&nbsp;std;<br>ifstream&nbsp;fin("range.in");<br>ofstream&nbsp;fout("range.out");<br>int&nbsp;G[255][255],dp[255][255]={0};<br>int&nbsp;cnt[255]={0};<br>int&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;n;&nbsp;char&nbsp;ch;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin&gt;&gt;n;<br>&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;i=1;&nbsp;i&lt;=n;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;j=1;&nbsp;j&lt;=n;&nbsp;j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin&gt;&gt;ch;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G[i][j]=int(ch-'0');<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(dp,0,sizeof&nbsp;dp);<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;i=1;&nbsp;i&lt;=n;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(G[n][i])dp[n][i]=1;<br>&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;j=1;&nbsp;j&lt;=n;&nbsp;j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(G[j][n])dp[j][n]=1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;i=n-1;&nbsp;i&gt;=1;&nbsp;i--)<br>&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;j=n-1;&nbsp;j&gt;=1;&nbsp;j--)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(G[i][j])dp[i][j]=min(&nbsp;min(dp[i][j+1],dp[i+1][j]),dp[i+1][j+1]&nbsp;)+1;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;i=1;&nbsp;i&lt;=n;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;j=1;&nbsp;j&lt;=n;&nbsp;j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(dp[i][j]&gt;=2)<br>&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;&nbsp;&nbsp;&nbsp;for(int&nbsp;k=2;&nbsp;k&lt;=dp[i][j];&nbsp;k++)<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;cnt[k]++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;i=1;&nbsp;i&lt;=n;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(cnt[i])fout&lt;&lt;i&lt;&lt;'&nbsp;'&lt;&lt;cnt[i]&lt;&lt;endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;<br>}<br></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122907.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-10 11:05 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122907.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 3 A Game</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122897.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 10 Aug 2010 02:00:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122897.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122897.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122897.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122897.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122897.html</trackback:ping><description><![CDATA[<pre><br>1.sum[i][j]为从i到j的所有的和，dp[i][j]为从i到j所能得到的最大分数。</pre>
<pre>取有两种情况</pre>
<pre>1，取i，留下区间(i+1,j)给对手，那么对手的得分是dp[i+1][j]<br></pre>
<pre>2,取j，留下区间(i,j-1)给对手，那么对手的得分是dp[i][j-1]</pre>
<pre>自己的得分是sum[i][j]-对手得分，于是dp[i][j]=sum[i][j]-min(dp[i+1][j],dp[i][j-1]);<br></pre>
<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; FONT-FAMILY: courier new; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:game1<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">game1.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">game1.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;num[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">},sum[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">},dp[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">num[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)sum[i][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">1</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sum[i][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>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;l</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;l</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n;l</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;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</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">l;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">l]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sum[i][i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">l]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">min(dp[i][i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">l</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">],dp[i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">l]);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">dp[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][n]</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">sum[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][n]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">dp[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][n]</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&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>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122897.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-10 10:00 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/10/122897.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 3  Shopping Offers </title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/09/122746.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Mon, 09 Aug 2010 02:57:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/09/122746.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122746.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/09/122746.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122746.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122746.html</trackback:ping><description><![CDATA[<p><br>&nbsp;参考NOCOW上的程序：<br><br>完全一样的，DP好弱<br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 12pt; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; FONT-FAMILY: courier new; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:shopping<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstring</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">shopping.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">shopping.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;arr<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;v,k[</span><span style="COLOR: #000000">1005</span><span style="COLOR: #000000">];&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">该种优惠方案中i商品的个数是k[i]&nbsp;，价格是v&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">}a[</span><span style="COLOR: #000000">105</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;brr<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;high,buy;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">要买的商品：buy，件数是high&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">}b[</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;dp[</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,m,i,j,num,l;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">num;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">num;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">l;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">a[i].k[l];<br>&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;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">a[i].v;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">购物&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">m;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">b[i].buy</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">b[i].high</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">a[</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">n].v;&nbsp;//当做一种件数为1的优惠方案<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[n].k[&nbsp;b[i].buy&nbsp;]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(dp,</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;dp);//相当于初始化无穷大<br>&nbsp;&nbsp;&nbsp;&nbsp;dp[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;m1,m2,m3,m4,m5,b1,b2,b3,b4,b5;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[i].k[b[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">].buy];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[i].k[b[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">].buy];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m3</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[i].k[b[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">].buy];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m4</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[i].k[b[</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">].buy];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m5</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[i].k[b[</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">].buy];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(b1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">m1;&nbsp;b1</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">b[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">].high;&nbsp;b1</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(b2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">m2;&nbsp;b2</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">b[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">].high;&nbsp;b2</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(b3</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">m3;&nbsp;b3</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">b[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">].high;&nbsp;b3</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(b4</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">m4;&nbsp;b4</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">b[</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">].high;&nbsp;b4</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(b5</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">m5;&nbsp;b5</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">b[</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">].high;&nbsp;b5</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<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;dp[b1][b2][b3][b4][b5]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">min(<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;dp[b1][b2][b3][b4][b5],<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;dp[b1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">m1][b2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">m2][b3</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">m3][b4</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">m4][b5</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">m5]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">a[i].v<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;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">dp[b[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">].high][b[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">].high][b[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">].high][b[</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">].high][b[</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">].high]</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&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>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122746.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-09 10:57 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/09/122746.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 3 Riding The Fences</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/08/122679.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Sun, 08 Aug 2010 09:34:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/08/122679.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122679.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/08/122679.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122679.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122679.html</trackback:ping><description><![CDATA[<dl>
<dt>
<pre><br><br>USER: tian tianbing [tbbd4261]</pre>
<dt>
<pre>TASK: fenceLANG: C++ Compiling...Compile: OKExecuting...</pre>
<dt>
<pre>Test 1: TEST OK [0.022 secs, 4016 KB] </pre>
<dt>
<pre>Test 2: TEST OK [0.000 secs, 4016 KB]</pre>
<dt>
<pre>Test 3: TEST OK [0.022 secs, 4016 KB] </pre>
<dt>
<pre>Test 4: TEST OK [0.022 secs, 4016 KB]</pre>
<dt>
<pre>Test 5: TEST OK [0.011 secs, 4016 KB] </pre>
<dt>
<pre>Test 6: TEST OK [0.011 secs, 4016 KB]</pre>
<dt>
<pre>Test 7: TEST OK [0.000 secs, 4016 KB] </pre>
<dt>
<pre>Test 8: TEST OK [0.043 secs, 4016 KB]All tests OK. </pre>
<dt>
<pre>Your program ('fence') produced all correct answers! </pre>
<dt>
<pre>This is your submission #3 for this problem. Congratulations!</pre>
</dt></dl>
<pre><br>欧拉回路也可能是欧拉路径，用dfs，从小到大搜，要求是输出字典序小的.</pre>
<pre>刚开始是输出放在函数里面，这样后两组测试数据过不了，<br></pre>
<pre>/*<br>ID:tbbd4261<br>PROG:fence<br>LANG:C++<br>*/</pre>
<pre>#include&lt;fstream&gt;<br>using namespace std;<br>ifstream fin("fence.in");<br>ofstream fout("fence.out");</pre>
<pre>const int MAX=505;<br>int adj[MAX][MAX]={0},F,nmax=0;<br>int cnt[MAX]={0};<br>int print[1025*2+100]={0},len=0;<br>void dfs(int u)<br>{<br>&nbsp;&nbsp;&nbsp; //fout&lt;&lt;u&lt;&lt;endl;<br>&nbsp;&nbsp;&nbsp; for(int v=1; v&lt;=nmax; v++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(adj[u][v])<br>&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; adj[u][v]--;<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; adj[v][u]--;<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; dfs(v);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; len++;<br>&nbsp;&nbsp;&nbsp; print[len]=u;<br>}</pre>
<pre>int main()<br>{<br>&nbsp;&nbsp;&nbsp; fin&gt;&gt;F;<br>&nbsp;&nbsp;&nbsp; int i,s,t;<br>&nbsp;&nbsp;&nbsp; for( i=1,s,t; i&lt;=F; i++) <br>&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fin&gt;&gt;s&gt;&gt;t;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cnt[s]++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cnt[t]++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; adj[s][t]++; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; adj[t][s]++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(s&gt;nmax)nmax=s;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(t&gt;nmax)nmax=t;<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; s=0;<br>&nbsp;&nbsp;&nbsp;&nbsp; for(i=1; i&lt;=nmax; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(cnt[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; if(s==0)s=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; if(cnt[i]%2==1){ s=i; break;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; dfs(s);<br>&nbsp;&nbsp;&nbsp;&nbsp; for(int j=len; j&gt;=1; j--)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fout&lt;&lt;print[j]&lt;&lt;endl;<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br></pre>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122679.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-08 17:34 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/08/122679.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 2 Sweet Butter</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/08/122617.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Sun, 08 Aug 2010 01:20:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/08/122617.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122617.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/08/122617.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122617.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122617.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 做了一题，开心，冒一下泡：题目大意：有一些草原（1，&#8230;&#8230;，p个），告诉你n个奶牛的在哪个草原，Famer John 会在其中一个草原放一块糖，让所有的奶牛去舔（提高奶的质量^-^），要求的就是把糖放在哪个草原使所有的奶牛到那的路程和最短。（当然奶牛都是拣最短的路走）。&nbsp;第一种超时思路 ：Floyd算法求出任意两个草原间的距离，枚举所有草原，取所...&nbsp;&nbsp;<a href='http://www.cppblog.com/tianlearn-language/archive/2010/08/08/122617.html'>阅读全文</a><img src ="http://www.cppblog.com/tianlearn-language/aggbug/122617.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-08 09:20 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/08/122617.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 3 Feed Ratios </title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122477.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Fri, 06 Aug 2010 12:08:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122477.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122477.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122477.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122477.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122477.html</trackback:ping><description><![CDATA[<div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; BACKGROUND-COLOR: white">
<pre>USER: tian tianbing [tbbd4261]
TASK: ratios
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.043 secs, 3016 KB]
Test 2: TEST OK [0.032 secs, 3016 KB]
Test 3: TEST OK [0.032 secs, 3016 KB]
Test 4: TEST OK [0.022 secs, 3016 KB]
Test 5: TEST OK [0.022 secs, 3016 KB]
Test 6: TEST OK [0.032 secs, 3016 KB]
All tests OK.
<p>Your program ('ratios') produced all correct answers!  This is your
submission #18 for this problem.  <strong>Congratulations!</strong>
</p>
</pre>
<p>Here are the test data inputs:
<pre>------- test 1 -------
5 8 0
3 5 4
1 3 0
6 2 0
------- test 2 -------
3 4 5
1 2 3
3 7 1
2 1 2
------- test 3 -------
20 22 24
4 5 5
9 5 6
12 12 14
------- test 4 -------
80 85 80
98 97 96
89 87 88
78 79 80
------- test 5 -------
99 99 99
1 0 0
0 1 0
0 0 1
------- test 6 -------
93 95 97
98 0 0
0 98 0
0 0 98
</pre>
Keep up the good work!<br></div>
<pre></pre>
<pre>Thanks for your submission!</pre>
<pre>直接枚举就能过了，提交了18次，不知道为什么用fin读不了，后来还是让同学帮我改成C的文件读入才过的</pre>
<pre>到现在还是不知道为什么。</pre>
<pre>要注意比例和饲料都是非负的小于100的，也就是说可能出现0的情况，要小心。</pre>
<pre>
<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"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:ratios<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">fstream&nbsp;fin("ratios.in");</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ratios.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;food[</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">];<br>&nbsp;&nbsp;&nbsp;&nbsp;freopen(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ratios.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">r</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,stdin);<br>&nbsp;&nbsp;&nbsp;&nbsp;freopen(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ratios.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">w</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,stdout);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,j,k,minsum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0xffffff</span><span style="COLOR: #000000">,a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,b</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,c</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,d</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">food[i][j]);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n1,n2,n3;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;f1,f2,f</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;k</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;&nbsp;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">1</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">i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">2</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">j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">food[</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">*</span><span style="COLOR: #000000">k;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">k;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n3</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">k;<br>&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;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;&nbsp;f1</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;&nbsp;f2</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br>&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">(food[</span><span style="COLOR: #000000">0</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">0</span><span style="COLOR: #000000">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f1</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n1</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br>&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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n1</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">0</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">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">n1</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<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;&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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(food[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f2</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n2</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n2</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(f1</span><span style="COLOR: #000000">==</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">)t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">n2</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n2</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">t)</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<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;&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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(food[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n3</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;&nbsp;&nbsp;<br>&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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n3</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(f1</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">f2)t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">n3</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">((f1</span><span style="COLOR: #000000">==</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">f2</span><span style="COLOR: #000000">==</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">n3</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">food[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">t)</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<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;&nbsp;&nbsp;&nbsp;&nbsp;<br>&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;n1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">n2</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">n3</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">minsum</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">(n1</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">n2</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">n3)){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minsum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">n1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">n2</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">n3;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;&nbsp;b</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j;&nbsp;c</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">k;&nbsp;d</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">t;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(f)&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">a</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">b</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">c</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">d</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">NONE</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;&nbsp;&nbsp;&nbsp;<br>&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>}<br></span></div>
</pre>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122477.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-06 20:08 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122477.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 2  Spinning Wheels </title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122462.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Fri, 06 Aug 2010 09:01:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122462.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122462.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122462.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122462.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122462.html</trackback:ping><description><![CDATA[<div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; BACKGROUND-COLOR: white">
<pre>USER: tian tianbing [tbbd4261]
TASK: spin
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 3012 KB]
Test 2: TEST OK [0.000 secs, 3012 KB]
Test 3: TEST OK [0.000 secs, 3012 KB]
Test 4: TEST OK [0.000 secs, 3012 KB]
Test 5: TEST OK [0.011 secs, 3012 KB]
Test 6: TEST OK [0.000 secs, 3012 KB]
Test 7: TEST OK [0.011 secs, 3012 KB]
Test 8: TEST OK [0.011 secs, 3012 KB]
All tests OK.
<p>Your program ('spin') produced all correct answers!  This is your
submission #2 for this problem.  <strong>Congratulations!</strong>
</p>
</pre>
<p>Here are the test data inputs:
<pre>------- test 1 -------
30 1 0 120
180 1 10 100
35 1 20 90
31 1 30 80
32 1 50 60
------- test 2 -------
30 1 350 350
180 1 10 100
35 1 67 23
31 1 30 4
32 1 50 7
------- test 3 -------
180 1 0 120
180 1 120 120
180 1 240 120
31 1 30 4
32 1 50 7
------- test 4 -------
1 1 140 359
1 1 200 359
1 1 4 1
2 1 6 1
1 1 300 300
------- test 5 -------
45 5 140 13 300 17 0 15 20 3 40 1
73 1 200 359
105 2 4 1 50 50
179 3 6 1 8 1 359 3
3 1 300 300
------- test 6 -------
45 5 120 13 200 17 0 15 20 3 32 1
73 5 200 100 1 30 50 10 70 2 75 1
105 2 100 1 50 20
179 3 6 1 8 1 359 3
3 1 300 359
------- test 7 -------
73 5 207 101 1 35 57 11 71 2 75 1
45 5 125 13 200 17 0 15 20 3 32 1
96 5 100 12 50 13 0 2 300 39 250 1
119 5 6 1 8 1 359 1 245 1 123 1
15 5 300 1 231 1 185 1 179 2 0 18
------- test 8 -------
73 5 207 11 1 35 57 11 71 2 75 1
45 5 125 3 200 17 0 15 20 3 32 1
96 5 100 1 50 1 0 2 300 39 250 1
119 5 6 1 8 1 359 1 245 1 123 1
15 5 300 1 231 1 185 1 179 2 0 1
</pre>
Keep up the good work!<br></div>
<pre></pre>
<pre>Thanks for your submission!</pre>
<pre><br><br>直接枚举，t==360时所有轮子都回到最初状态。</pre>
<pre>用一个数组计数，f[i]==5的话说明所有轮子的缺口都经过这个地方，OKay！<br></pre>
<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">
<pre><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:spin<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstring</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">spin.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">spin.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;wheel<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;v,w;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">速度，缺口数&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;s[</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">];&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">缺口起始位置&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;len[</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">];&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">缺口大小&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">}wheel[</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">];<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;f[</span><span style="COLOR: #000000">360</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">5</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">wheel[i].v</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">wheel[i].w;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">wheel[i].w;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">wheel[i].s[j]</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">wheel[i].len[j];&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;isP</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(&nbsp;t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;t</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">360</span><span style="COLOR: #000000">;&nbsp;t</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(f,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;f);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">wheel[i].w;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br>&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;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;start</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(wheel[i].s[j]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">(wheel[i].v</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">t)&nbsp;)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">360</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;k</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">wheel[i].len[j];&nbsp;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&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;{<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;f[(k</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">start)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">360</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(f[(k</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">start)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">360</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">){&nbsp;isP</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">t</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;}&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;}<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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">none</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;<br>&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>}<br></pre>
</span></div>
<br>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122462.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-06 17:01 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122462.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>chapter 3 section 2  Stringsobits</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122452.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Fri, 06 Aug 2010 07:45:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122452.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122452.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122452.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122452.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122452.html</trackback:ping><description><![CDATA[<pre>USER: tian tianbing [tbbd4261]
TASK: kimbits
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.011 secs, 3012 KB]
Test 2: TEST OK [0.011 secs, 3012 KB]
Test 3: TEST OK [0.022 secs, 3012 KB]
Test 4: TEST OK [0.011 secs, 3012 KB]
Test 5: TEST OK [0.000 secs, 3012 KB]
Test 6: TEST OK [0.011 secs, 3012 KB]
Test 7: TEST OK [0.011 secs, 3012 KB]
Test 8: TEST OK [0.011 secs, 3012 KB]
Test 9: TEST OK [0.000 secs, 3012 KB]
Test 10: TEST OK [0.000 secs, 3012 KB]
Test 11: TEST OK [0.000 secs, 3012 KB]
Test 12: TEST OK [0.000 secs, 3012 KB]
Test 13: TEST OK [0.011 secs, 3012 KB]
All tests OK.
<p><strong>YOUR PROGRAM ('kimbits') WORKED FIRST TIME!</strong>  That's fantastic
-- and a rare thing.  Please accept these special automated
congratulations.
</p>
</pre>
<p>Here are the test data </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">
<pre><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:kimbits&nbsp;<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">kimbits.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">kimbits.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;cmb[</span><span style="COLOR: #000000">32</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">32</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">32</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmb[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">32</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</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">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmb[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">cmb[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">cmb[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">32</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">32</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmb[i][j]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">cmb[i][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;n,l,i;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">l</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">i;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(unsigned&nbsp;ix</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">n;&nbsp;ix</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">ix&nbsp;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">cmb[ix</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][l]){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">cmb[ix</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][l];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&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>}<br></pre>
</span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122452.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-06 15:45 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122452.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 2  Factorials</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122400.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Fri, 06 Aug 2010 01:24:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122400.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122400.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122400.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122400.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122400.html</trackback:ping><description><![CDATA[<div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; BACKGROUND-COLOR: white">
<pre>USER: tian tianbing [tbbd4261]
TASK: fact4
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 3028 KB]
Test 2: TEST OK [0.011 secs, 3028 KB]
Test 3: TEST OK [0.000 secs, 3028 KB]
Test 4: TEST OK [0.011 secs, 3028 KB]
Test 5: TEST OK [0.000 secs, 3028 KB]
Test 6: TEST OK [0.011 secs, 3028 KB]
Test 7: TEST OK [0.000 secs, 3028 KB]
Test 8: TEST OK [0.000 secs, 3028 KB]
Test 9: TEST OK [0.000 secs, 3028 KB]
Test 10: TEST OK [0.011 secs, 3028 KB]
All tests OK.
<p>Your program ('fact4') produced all correct answers!  This is your
submission #2 for this problem.  <strong>Congratulations!</strong>
</p>
</pre>
<p>Here are the test data inputs:
<pre>------- test 1 -------
1
------- test 2 -------
2
------- test 3 -------
7
------- test 4 -------
14
------- test 5 -------
143
------- test 6 -------
645
------- test 7 -------
777
------- test 8 -------
888
------- test 9 -------
999
------- test 10 -------
1000
</pre>
Keep up the good work!<br></div>
<pre></pre>
Thanks for your submission!<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">
<pre><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:fact4<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fact4.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fact4.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;dp[</span><span style="COLOR: #000000">4225</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">},n,i;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;cal(</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)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;temp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">b;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(temp</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp</span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;temp</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">100000</span><span style="COLOR: #000000">;<br>}<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;dp[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">cal(i,dp[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">dp[n]</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&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>}<br></pre>
</span></div>
<pre><br>10=2*5;</pre>
<pre>统计N！中2的个数和5的个数，用digit记录除去2和5的最后一位阶乘结果。</pre>
<pre>最后把多余的2的个数乘回去（即n2-n5个2）<br></pre>
<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">
<pre><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:fact4<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fact4.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fact4.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,i,digit,n2,n5,j;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;n2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">n5</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;digit</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(j</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n2</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j</span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n5</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j</span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digit</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(digit</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">j)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">n5;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digit</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(digit</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">digit</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&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>}<br></pre>
</span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122400.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-06 09:24 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/06/122400.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 1 Stamps</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/05/122328.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Thu, 05 Aug 2010 09:10:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/05/122328.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122328.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/05/122328.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122328.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122328.html</trackback:ping><description><![CDATA[<br>
<pre>USER: tian tianbing [tbbd4261]
TASK: stamps
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 10864 KB]
Test 2: TEST OK [0.000 secs, 10864 KB]
Test 3: TEST OK [0.000 secs, 10864 KB]
Test 4: TEST OK [0.011 secs, 10864 KB]
Test 5: TEST OK [0.000 secs, 10864 KB]
Test 6: TEST OK [0.011 secs, 10864 KB]
Test 7: TEST OK [0.011 secs, 10864 KB]
Test 8: TEST OK [0.011 secs, 10864 KB]
Test 9: TEST OK [0.000 secs, 10864 KB]
Test 10: TEST OK [0.162 secs, 10864 KB]
Test 11: TEST OK [0.983 secs, 10864 KB]
Test 12: TEST OK [0.324 secs, 10864 KB]
Test 13: TEST OK [0.011 secs, 10864 KB]
All tests OK.</pre>
<pre>
<p>Your program ('stamps') produced all correct answers!  This is your
submission #2 for this problem.  <strong>Congratulations!<br><br><br></strong><br><br><br><br><br>
</p>
</pre>
<pre>DP：</pre>
<pre> f[i]表示凑成i分游子需要的最少邮票数。<br> f[i]=min{f[i-stamp[j]]+1}，(j=1&#8230;&#8230;n)&amp;&amp;i&gt;=stamp[j];<br><br> 初始状态f[0]=0;<br><br></pre>
<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">
<pre><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:stamps<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">stamps.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">stamps.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;INTMAX</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0x0fffffff</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,k,i,j,stamp[</span><span style="COLOR: #000000">55</span><span style="COLOR: #000000">],minn;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;f[</span><span style="COLOR: #000000">201</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">10001</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">stamp[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;f[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">200</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">10000</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&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;f[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INTMAX;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">stamp[j]</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">f[i]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">stamp[j]]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">stamp[j]]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(f[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">INTMAX</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">f[i]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">k)</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&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>}<br><br><br></pre>
</span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122328.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-05 17:10 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/05/122328.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 1 Contact</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/05/122315.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Thu, 05 Aug 2010 07:54:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/05/122315.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122315.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/05/122315.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122315.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122315.html</trackback:ping><description><![CDATA[<pre>USER: tian tianbing [tbbd4261]<br>TASK: contact<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.000 secs, 3220 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.011 secs, 3220 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.011 secs, 3220 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.054 secs, 3220 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.248 secs, 3484 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.324 secs, 3220 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.410 secs, 3484 KB]<br><br>All tests OK.<br></pre>
<pre>Your program ('contact') produced all correct answers!&nbsp; This is your<br>submission #7 for this problem.&nbsp; Congratulations!<br></pre>
<pre>交了7次，被格式给搞败掉了。</pre>
<pre>还有就是strig的构造函数，string str(s+i,j);str为s+i位置开始的j个字符，而不是string str(s,i,j);</pre>
<pre>定义一个map&lt;string ,int&gt;用于给各个串计数，然后转到vector中排序。 还好能过。</pre>
<pre>
<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"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:contact<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">map</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">contact.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">contact.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a,&nbsp;b&nbsp;,n&nbsp;,i,j,cnt</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;;<br></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;s[</span><span style="COLOR: #000000">200005</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;cmp(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;pair</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&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;pair</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b&nbsp;)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.first</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">b.first)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.first</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">b.first)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.second.size()</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">b.second.size())</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.second.size()</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">b.second.size())</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;a.second</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">b.second;<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;ch;<br>&nbsp;&nbsp;&nbsp;&nbsp;map</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;mp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">ch;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">ch;<br>&nbsp;&nbsp;&nbsp;&nbsp;cnt</span><span style="COLOR: #000000">=--</span><span style="COLOR: #000000">i;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a;&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;)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">+</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">cnt;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;str(s</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">j,i);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">错的地方&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mp[str]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;pair</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;vec;<br>&nbsp;&nbsp;&nbsp;&nbsp;map</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">::iterator&nbsp;it</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">mp.begin();<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(it</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">mp.end())<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vec.push_back(make_pair(it</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">second,it</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">first));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;it</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;sort(vec.begin(),vec.end(),cmp);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;len,j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,c;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">vec.size();&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;len</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">vec[j].first;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">len</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;&nbsp;&nbsp;c</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">vec.size()</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">vec[j].first</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">len)<br>&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;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(c</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">c</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">vec[j].second;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(c</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<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;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(c</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&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>}<br></span></div>
</pre>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122315.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-05 15:54 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/05/122315.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 1 Shaping Regions</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/04/122221.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Wed, 04 Aug 2010 08:51:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/04/122221.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122221.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/04/122221.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122221.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122221.html</trackback:ping><description><![CDATA[<pre>USER: tian tianbing [tbbd4261]<br>TASK: rect1<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.000 secs, 3024 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.000 secs, 3024 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.011 secs, 3024 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.000 secs, 3024 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.000 secs, 3024 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.000 secs, 3024 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.022 secs, 3024 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.011 secs, 3024 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.022 secs, 3024 KB]<br>&nbsp;&nbsp; Test 10: TEST OK [0.022 secs, 3024 KB]<br>&nbsp;&nbsp; Test 11: TEST OK [0.022 secs, 3024 KB]<br><br>All tests OK.<br></pre>
<pre>Your program ('rect1') produced all correct answers!&nbsp; This is your<br>submission #15 for this problem.&nbsp; Congratulations!<br></pre>
<pre>&nbsp;</pre>
<pre>     终于做出来了，用队列实现，没接收一个就遍历整个队列。要注意的是要把队列的大小用t记下，因为</pre>
<pre>新加进来的会改变队列的大小。</pre>
<pre>    用的是矩形分割：</pre>
<pre>原来的程序在分割与a相交的矩形b的时候，把a与b相交的部分也作为一个小矩形放在了后面。</pre>
<pre>这也就会多出很多，统计了一下对于最后一组测试数据有40多万个矩形，超时。</pre>
<pre>其实应该把a整个放进去，不该把a也分割的。<br><br><br><br></pre>
<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">
<dl>
<dt>
<pre><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:rect1<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">queue</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">rect1.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">rect1.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;type<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x1,y1,x2,y2,color;<br>};<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;w,h,n,i,cnt;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;color[</span><span style="COLOR: #000000">2505</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br>queue</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">type</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">Q;<br>inline&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;max(</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">return</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">a:b;&nbsp;}<br>inline&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;min(</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">return</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">b:a;&nbsp;}&nbsp;<br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;isIn(type&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a,&nbsp;type&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b)</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">判断是否相交&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.x1</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">b.x2)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.x2</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">b.x1)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.y1</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">b.y2)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.y2</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">b.y1)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;add(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x1,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;y1,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x2,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;y2,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;c)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type&nbsp;t;&nbsp;t.x1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x1;&nbsp;t.y1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y1;&nbsp;t.x2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x2;&nbsp;t.y2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y2;&nbsp;t.color</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">c;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color[c]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">(x2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x1)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(y2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Q.push(t);<br>}<br><br>&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;dec()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type&nbsp;t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Q.front();&nbsp;Q.pop();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color[t.color]</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">(t.x2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">t.x1)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(t.y2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">t.y1);<br>}<br><br>&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;deal(type&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a,&nbsp;type&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b)&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">a与b交，b的下标是j&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.x1</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">b.x1</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">a.x1</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">b.x2)&nbsp;add(b.x1,&nbsp;b.y1,a.x1,b.y2,b.color);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">S1</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.x2</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">b.x1</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">a.x2</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">b.x2)&nbsp;add(a.x2,b.y1,&nbsp;b.x2,&nbsp;b.y2,b.color);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">S3</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.y1</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">b.y1</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">a.y1</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">b.y2)&nbsp;add(max(a.x1,b.x1),b.y1,min(a.x2,b.x2),a.y1,b.color);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">S2</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a.y2</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">b.y1</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">a.y2</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">b.y2)&nbsp;add(max(a.x1,b.x1),a.y2,min(a.x2,b.x2),b.y2,b.color);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">S4<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">add(max(a.x1,b.x1),max(a.y1,b.y1),min(a.x2,b.x2),min(a.y2,b.y2),a.color);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">a与b相交的部分&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dec();<br>&nbsp;}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(color,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;color);<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">w</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">h</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;color[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">w</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">h;<br>&nbsp;&nbsp;&nbsp;&nbsp;type&nbsp;temp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;temp.x1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;temp.y1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;temp.x2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">w;&nbsp;temp.y2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">h;&nbsp;temp.color</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;Q.push(temp);<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">temp.x1</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">temp.y1</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">temp.x2</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">temp.y2</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">temp.color;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Q.size(),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">t;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(isIn(temp,Q.front()&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;deal(&nbsp;temp,Q.front()&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{&nbsp;type&nbsp;t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">Q.front();&nbsp;Q.pop();Q.push(t);&nbsp;}//如果不相交，放在队列后面<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add(temp.x1,temp.y1,temp.x2,temp.y2,temp.color);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">2500</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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">(color[i])&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</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">color[i]</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&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>}<br></pre>
</dt></dl></span></div>
<p>&nbsp;</p>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122221.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-04 16:51 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/04/122221.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 1 Humble Numbers</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/04/122156.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Wed, 04 Aug 2010 01:57:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/04/122156.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122156.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/04/122156.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122156.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122156.html</trackback:ping><description><![CDATA[<pre>USER: tian tianbing [tbbd4261]<br>TASK: humble<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.000 secs, 3792 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.011 secs, 3792 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.000 secs, 3792 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.011 secs, 3792 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.022 secs, 3792 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.054 secs, 3792 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.022 secs, 3792 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.022 secs, 3792 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.000 secs, 3792 KB]<br>&nbsp;&nbsp; Test 10: TEST OK [0.000 secs, 3792 KB]<br>&nbsp;&nbsp; Test 11: TEST OK [0.000 secs, 3792 KB]<br>&nbsp;&nbsp; Test 12: TEST OK [0.389 secs, 3792 KB]<br><br>All tests OK.<br></pre>
<pre>YOUR PROGRAM ('humble') WORKED FIRST TIME!&nbsp; That's fantastic<br>-- and a rare thing.&nbsp; Please accept these special automated<br></pre>
<pre>USACO上给了一个高效数据结构也不复杂的处理方法。</pre>
<pre>for each prime p
find the minimum humble number h
such that h * p is bigger than the last humble number.
take the smallest h * p found: that's the next humble number.</pre>
<pre>假设前面已经确定k个丑数。</pre>
<pre>      对于每个质数p（从前往后遍历，由题意知是递增的）</pre>
<pre>             找到最小的丑数h，使 h*p &gt; humble[k]（不断用这个更新min）</pre>
<pre> min就是下一个要求的丑数humble[k+1];</pre>
<pre>&nbsp;</pre>
<pre>    技巧的地方：pindex[i]数组记录记录第i个质数（data[i]）乘到（humble[]表）的地方，</pre>
<pre>因为以后的数一定比这个大，不需要从头再扫。</pre>
<pre>
<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"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:humble<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">humble.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">humble.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MAX</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">100005</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;data[</span><span style="COLOR: #000000">105</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">},&nbsp;humble[MAX]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">},pindex[</span><span style="COLOR: #000000">105</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,k,i,nhum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">k;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">data[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;humble[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;humble[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">data[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br>&nbsp;&nbsp;&nbsp;&nbsp;nhum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">k;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)pindex[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(nhum</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n)<br>&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;min</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0x7fffffff</span><span style="COLOR: #000000">,temp,tt</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</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">k;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(data[i]&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;humble[pindex[i]]</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">humble[nhum])<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;&nbsp;pindex[i]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<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;temp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">data[i]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">humble[&nbsp;pindex[i]&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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(&nbsp;temp</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">min){&nbsp;min</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">temp;&nbsp;tt</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;&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;<br>&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;humble[</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">nhum]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">min;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pindex[tt]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">humble[n]</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;<br>&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>}<br></span></div>
</pre>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122156.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-04 09:57 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/04/122156.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>chapter 3 section 3.1  Score Inflation </title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122115.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 03 Aug 2010 14:33:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122115.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122115.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122115.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122115.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122115.html</trackback:ping><description><![CDATA[<pre>USER: tian tianbing [tbbd4261]<br>TASK: inflate<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.000 secs, 3128 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.011 secs, 3128 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.011 secs, 3128 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.000 secs, 3128 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.000 secs, 3128 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.022 secs, 3128 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.043 secs, 3128 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.108 secs, 3128 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.184 secs, 3128 KB]<br>&nbsp;&nbsp; Test 10: TEST OK [0.184 secs, 3128 KB]<br>&nbsp;&nbsp; Test 11: TEST OK [0.011 secs, 3128 KB]<br>&nbsp;&nbsp; Test 12: TEST OK [0.000 secs, 3128 KB]<br><br>All tests OK.<br></pre>
<pre>YOUR PROGRAM ('inflate') WORKED FIRST TIME!&nbsp; That's fantastic<br>-- and a rare thing.&nbsp; Please accept these special automated<br>congratulations.</pre>
<pre><br>&nbsp;</pre>
<pre>
<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"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:inflate<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">inflate.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">inflate.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MAX</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">10005</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;f[MAX]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;p[MAX],t[MAX];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,m,i,j;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">m</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">p[i]</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">t[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">t[i];&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">m;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(f[j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">t[i]]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">p[i]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">f[j]</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">f[j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">t[i]]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">p[i]:f[j]&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">f[m]</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>}<br>&nbsp;<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><br></span></div>
</pre>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122115.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-03 22:33 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122115.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 3 section 3.1 Agri-Net </title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122096.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 03 Aug 2010 12:05:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122096.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122096.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122096.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122096.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122096.html</trackback:ping><description><![CDATA[<pre>USER: tian tianbing [tbbd4261]<br>TASK: agrinet<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.000 secs, 3208 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.000 secs, 3208 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.011 secs, 3208 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.000 secs, 3208 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.000 secs, 3208 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.011 secs, 3208 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.000 secs, 3208 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.011 secs, 3208 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.000 secs, 3208 KB]<br>&nbsp;&nbsp; Test 10: TEST OK [0.022 secs, 3208 KB]<br><br>All tests OK.<br></pre>
<pre>Your program ('agrinet') produced all correct answers!&nbsp; This is your<br>submission #2 for this problem.&nbsp; Congratulations!<br>最小生成树：</pre>
<pre>
<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"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:agrinet<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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>#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></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">agrinet.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">agrinet.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;fa[</span><span style="COLOR: #000000">10100</span><span style="COLOR: #000000">];&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;u[</span><span style="COLOR: #000000">10101</span><span style="COLOR: #000000">];&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;v[</span><span style="COLOR: #000000">10101</span><span style="COLOR: #000000">];&nbsp;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;w[</span><span style="COLOR: #000000">10101</span><span style="COLOR: #000000">];&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;r[</span><span style="COLOR: #000000">10101</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;cmp(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j){</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;w[i]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">w[j];&nbsp;}<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;find(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x){</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;fa[x]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">x:fa[x]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">find(fa[x]);&nbsp;}<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,i,j,dis,count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,ans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">dis;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(dis){&nbsp;u[</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">count]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;&nbsp;v[count]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j;&nbsp;w[count]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dis;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">count;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)r[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">count;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)fa[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;sort(r</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,r</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">count,cmp);<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">count;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;e</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">r[i];&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">find(u[e]);&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">find(v[e]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(x</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">y){&nbsp;ans</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">w[e];&nbsp;fa[x]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y;&nbsp;}&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">ans</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&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>}<br></span></div>
</pre>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122096.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-03 20:05 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122096.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 2 section 2.4 Fractions to Decimals </title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122095.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 03 Aug 2010 11:59:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122095.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122095.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122095.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122095.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122095.html</trackback:ping><description><![CDATA[<div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; BACKGROUND-COLOR: white">
<pre>USER: tian tianbing [tbbd4261]
TASK: fracdec
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 3792 KB]
Test 2: TEST OK [0.000 secs, 3792 KB]
Test 3: TEST OK [0.000 secs, 3792 KB]
Test 4: TEST OK [0.000 secs, 3792 KB]
Test 5: TEST OK [0.000 secs, 3792 KB]
Test 6: TEST OK [0.000 secs, 3792 KB]
Test 7: TEST OK [0.022 secs, 3792 KB]
Test 8: TEST OK [0.032 secs, 3792 KB]
Test 9: TEST OK [0.000 secs, 3792 KB]
All tests OK.
<p>Your program ('fracdec') produced all correct answers!  This is your
submission #4 for this problem.  <strong>Congratulations!</strong>
</p>
</pre>
<p>Here are the test data inputs:
<pre>------- test 1 -------
22 5
------- test 2 -------
1 7
------- test 3 -------
100000 59
------- test 4 -------
1 100000
------- test 5 -------
3 3
------- test 6 -------
59 330
------- test 7 -------
100000 9817
------- test 8 -------
1 99991
------- test 9 -------
982 4885
</pre>
Keep up the good work!<br></div>
<pre></pre>
Thanks for your submission!<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 起初没什么思路，没做过这么类型的题，参考nocow上的一段代码，稍微改动一下，就有问题，结果就是代码几乎与他的一样。<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; HEIGHT: 1194px; BACKGROUND-COLOR: #eeeeee">
<pre><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:fracdec<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fracdec.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">fracdec.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MAX</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">100005</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,d,i,temp,len</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,j;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;k[MAX]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">},&nbsp;dat[MAX]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;gcd(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;y)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;x</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">y:gcd(&nbsp;y</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">x,x&nbsp;);<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">d;<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">d</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">d)len</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">(log(n</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">d)</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">log(</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">2.0001</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;len</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;n</span><span style="COLOR: #000000">%=</span><span style="COLOR: #000000">d;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;temp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">d</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">gcd(n,d);<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(temp</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">)temp</span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(temp</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)temp</span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(temp</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">无循环&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br>&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">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>&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;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n</span><span style="COLOR: #000000">*=</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">d;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n</span><span style="COLOR: #000000">%=</span><span style="COLOR: #000000">d;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;len</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br>&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;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(k[n]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>&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;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">k[n]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">dat[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;&nbsp;len</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(len</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">76</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&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;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;len</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&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">(len</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">76</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">k[n];&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>&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;&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">dat[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;&nbsp;&nbsp;&nbsp;&nbsp;len</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(len</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">76</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&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;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&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;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k[n]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n</span><span style="COLOR: #000000">*=</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dat[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">d;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n</span><span style="COLOR: #000000">%=</span><span style="COLOR: #000000">d;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&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>}<br></pre>
</span></div>
<br>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122095.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-03 19:59 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122095.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 2 section 2.4  Bessie Come Home </title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122062.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 03 Aug 2010 06:31:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122062.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122062.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122062.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122062.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122062.html</trackback:ping><description><![CDATA[<pre>USER: tian tianbing [tbbd4261]<br>TASK: comehome<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.011 secs, 3020 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.000 secs, 3020 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.000 secs, 3020 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.011 secs, 3020 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.011 secs, 3020 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.011 secs, 3020 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.011 secs, 3020 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.011 secs, 3020 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.000 secs, 3020 KB]<br><br>All tests OK.<br></pre>
<pre>YOUR PROGRAM ('comehome') WORKED FIRST TIME!&nbsp; That's fantastic<br>-- and a rare thing.&nbsp; Please accept these special automated<br>congratulations.<br>学校OJ代码：</pre>
<pre>Floyd:</pre>
<pre>
<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"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:comehome<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">comehome.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">comehome.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;dis[</span><span style="COLOR: #000000">53</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">53</span><span style="COLOR: #000000">];<br></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</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">10000000</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Floyd(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;k</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</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">n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">dis[i][k]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dis[k][j]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">dis[i][j])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dis[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dis[i][k]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dis[k][j];<br><br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;p,i,j,k,d,n1,n2;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">p;<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(dis,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;(dis));<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;dis[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INF;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">p;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;v1,v2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">v1</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">v2</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">d;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(v1</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">v2)</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(v1</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">v1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">:v1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">A</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">26</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(v2</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">v2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">:v2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">A</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">26</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(d</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">dis[n1][n2])dis[n1][n2]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dis[n2][n1]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">d;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Floyd(</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;min</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INF</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;c;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">27</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">51</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">大写字母到Z&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(dis[i][</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">min){min</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dis[i][</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">];c</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">(c</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">27</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">A</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)</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">min</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br><br>&nbsp;&nbsp;<br>&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>}<br></span></div>
Djkstra:</pre>
<pre>
<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"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:comehome<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">comehome.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">comehome.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;adj[</span><span style="COLOR: #000000">53</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">53</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;dis[</span><span style="COLOR: #000000">53</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;f[</span><span style="COLOR: #000000">53</span><span style="COLOR: #000000">];<br></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</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">10000000</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;p,i,j,k,d,n1,n2;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">p;<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(f,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;(f));<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adj[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INF;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">p;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;v1,v2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">v1</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">v2</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">d;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(v1</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">v2)</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(v1</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">v1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">:v1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">A</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">26</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(v2</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">v2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">:v2</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">A</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">26</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(d</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">adj[n1][n2])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adj[n1][n2]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">adj[n2][n1]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">d;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">51</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(adj[</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">][i])dis[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">adj[</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">][i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;dis[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INF;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;f[</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;&nbsp;dis[</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;min,u;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INF;&nbsp;u</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">f[j]</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">dis[j]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">min){&nbsp;min</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dis[j];&nbsp;u</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[u]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(u)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">52</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">f[j]</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">dis[j]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">dis[u]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">adj[u][j])dis[j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dis[u]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">adj[u][j];<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;min</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INF;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;c;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">27</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">51</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">大写字母到Z&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(dis[i]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">min){min</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dis[i];&nbsp;c</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">(c</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">27</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">A</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)</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">min</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;<br>&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>}<br></span></div>
</pre>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122062.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-03 14:31 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122062.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 2 section 2.4 Cow Tours</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122057.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 03 Aug 2010 05:57:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122057.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122057.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122057.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122057.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122057.html</trackback:ping><description><![CDATA[<pre>USER: tian tianbing [tbbd4261]
TASK: cowtour
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.011 secs, 3212 KB]
Test 2: TEST OK [0.000 secs, 3212 KB]
Test 3: TEST OK [0.000 secs, 3212 KB]
Test 4: TEST OK [0.000 secs, 3212 KB]
Test 5: TEST OK [0.022 secs, 3212 KB]
Test 6: TEST OK [0.022 secs, 3212 KB]
Test 7: TEST OK [0.032 secs, 3212 KB]
Test 8: TEST OK [0.032 secs, 3212 KB]
Test 9: TEST OK [0.022 secs, 3212 KB]
All tests OK.
<p>Your program ('cowtour') produced all correct answers!  This is your
submission #2 for this problem.  <strong>Congratulations!</strong>
</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"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:cowtour<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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>#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></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">cowtour.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">cowtour.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MAX</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">160</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;eps</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1e</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">,&nbsp;INT</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1e30;<br><br></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;dist[MAX][MAX]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;dt[MAX]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;locate[MAX][</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,i,j,k;<br></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;t;<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Floyd()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;k</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&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">(dist[i][k]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dist[k][j]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">dist[i][j])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dist[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dist[i][k]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dist[k][j];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dist[i][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INT;<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">locate[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">locate[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">t;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">t</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(t)dist[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sqrt(&nbsp;(locate[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">locate[j][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(locate[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">locate[j][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(&nbsp;locate[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">locate[j][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(locate[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">locate[j][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])&nbsp;)&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;dist[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INT;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Floyd();<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;pmax</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,max</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,pmin</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INT,tt;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pmax</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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">(dist[i][j]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">pmax</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">dist[i][j]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">INT)pmax</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dist[i][j];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">pmax;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(pmax</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">max)max</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">pmax;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&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">(dist[i][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">INT</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">j)<br>&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;tt</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sqrt((locate[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">locate[j][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(locate[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">locate[j][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(&nbsp;locate[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">locate[j][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(locate[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">locate[j][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])&nbsp;);<br>&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">(dt[i]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dt[j]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">tt</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">pmin)pmin</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dt[i]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dt[j]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">tt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;fout.precision(</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #0000ff">fixed</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">(pmin</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">max</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">pmin:max)</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&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>}<br></span></div>
</pre>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122057.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-03 13:57 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122057.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 2 section 2.4 Overfencing</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122038.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 03 Aug 2010 02:41:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122038.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122038.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122038.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122038.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122038.html</trackback:ping><description><![CDATA[<pre>USER: tian tianbing [tbbd4261]<br>TASK: maze1<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.011 secs, 3052 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.000 secs, 3052 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.000 secs, 3052 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.000 secs, 3052 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.011 secs, 3052 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.000 secs, 3088 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.022 secs, 3052 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.000 secs, 3052 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.011 secs, 3052 KB]<br>&nbsp;&nbsp; Test 10: TEST OK [0.151 secs, 3052 KB]<br><br>All tests OK.<br></pre>
<pre>Your program ('maze1') produced all correct answers!&nbsp; This is your<br>submission #2 for this problem.&nbsp; Congratulations!</pre>
<pre><br>DFS从两个入口各搜索一次，更新即可。</pre>
<pre>先写了一个代码，太乱，花了不少时间，后来重写了，要注意的代码的整洁。</pre>
<pre>
<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"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:maze1<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">maze1.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">maze1.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;wall[</span><span style="COLOR: #000000">205</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">80</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;step[</span><span style="COLOR: #000000">105</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">40</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;ch;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,y1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,x2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,y2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,i,j,w,h;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;dx[</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">]</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">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">},dy[</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</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">1</span><span style="COLOR: #000000">};<br><br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;input()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">w</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">h;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin.</span><span style="COLOR: #0000ff">get</span><span style="COLOR: #000000">();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">h</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">w</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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;fin.</span><span style="COLOR: #0000ff">get</span><span style="COLOR: #000000">(ch);&nbsp;wall[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">ch;<br>&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">((i</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">||</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">h</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">||</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">j</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">w</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">ch</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)<br>&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">x1){&nbsp;x1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;&nbsp;y1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j;&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;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{x2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;&nbsp;y2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j;&nbsp;}<br>&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;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin.</span><span style="COLOR: #0000ff">get</span><span style="COLOR: #000000">();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br><br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;valid(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j)<br>{&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">h</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">w</span><span style="COLOR: #000000">&amp;&amp;</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">)</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">(j</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">)&nbsp;;&nbsp;}<br><br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;valid2(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j){</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">h</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">w;&nbsp;}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;deal(</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)<br>{<br>&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">4</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(valid(x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dx[i],y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dy[i]))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dx[i];&nbsp;y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dy[i];&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x</span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;&nbsp;y</span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;dfs(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;k</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">;&nbsp;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(valid2(i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dx[k],j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dy[k])</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">wall[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dx[k]][j</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dy[k]]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)<br>&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">((step[i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dx[k]][j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dy[k]]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">step[i][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">step[i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dx[k]][j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dy[k]]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;step[i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dx[k]][j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dy[k]]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">step[i][j]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;dfs(i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dx[k],j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dy[k]);&nbsp;}<br>}<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;input();<br>&nbsp;&nbsp;&nbsp;&nbsp;deal(x1,y1);<br>&nbsp;&nbsp;&nbsp;&nbsp;deal(x2,y2);<br>&nbsp;&nbsp;&nbsp;&nbsp;step[x1][y1]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;step[x2][y2]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;dfs(x1,y1);<br>&nbsp;&nbsp;&nbsp;&nbsp;dfs(x2,y2);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;max</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">h;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">w;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(step[i][j]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">max)max</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">step[i][j];<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</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;&nbsp;&nbsp;&nbsp;<br>&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>}<br></span></div>
</pre>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122038.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-03 10:41 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122038.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>chapter 2 section 2.4 The Tamworth Two</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122030.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 03 Aug 2010 00:56:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122030.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122030.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122030.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122030.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122030.html</trackback:ping><description><![CDATA[<dl>
<dt>
<pre>USER: tian tianbing [tbbd4261]<br>TASK: ttwo<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.011 secs, 3012 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.000 secs, 3012 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.000 secs, 3012 KB]<br><br>All tests OK.<br></pre>
<dt>
<pre style="FONT-FAMILY: courier new">YOUR PROGRAM ('ttwo') WORKED FIRST TIME!&nbsp; That's fantastic<br>-- and a rare thing.&nbsp; Please accept these special automated</pre>
<dt>
<pre style="FONT-FAMILY: courier new">congratulations.</pre>
<dt>
<pre style="FONT-FAMILY: courier new"><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"><span style="COLOR: #008000"><br>/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:ttwo<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ttwo.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ttwo.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;g[</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;xc,yc,xf,yf,i,j,t,dc</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,df</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;input()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">g[i][j];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(g[i][j]</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">){&nbsp;xc</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;&nbsp;yc</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(g[i][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">F</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">){&nbsp;xf</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;&nbsp;yf</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)g[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)g[</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)g[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)g[i][</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;go(</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;,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">dir)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(dir</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">){<br>&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">(g[x</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][y]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)dir</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;x</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(dir</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(g[x][y</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">*</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)dir</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;y</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(dir</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(g[x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][y]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)dir</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;x</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(g[x][y</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">*</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)dir</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;y</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;input();<br>&nbsp;&nbsp;&nbsp;&nbsp;dc</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">df</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;&nbsp;t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;go(xc,yc,dc);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;go(xf,yf,df);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(xc</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">xf</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">yc</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">yf)</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(t</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">160000</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(t</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">160000</span><span style="COLOR: #000000">){&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">t</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;fout</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>&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>}<br></span></div>
</pre>
</dt></dl>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122030.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-03 08:56 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/03/122030.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 2 section 2.3  Controlling Companies</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/122000.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Mon, 02 Aug 2010 13:05:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/122000.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/122000.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/122000.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/122000.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/122000.html</trackback:ping><description><![CDATA[<pre>USER: tian tianbing [tbbd4261]
TASK: concom
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.011 secs, 3052 KB]
Test 2: TEST OK [0.000 secs, 3052 KB]
Test 3: TEST OK [0.000 secs, 3052 KB]
Test 4: TEST OK [0.000 secs, 3052 KB]
Test 5: TEST OK [0.000 secs, 3052 KB]
Test 6: TEST OK [0.000 secs, 3052 KB]
Test 7: TEST OK [0.000 secs, 3052 KB]
Test 8: TEST OK [0.011 secs, 3052 KB]
Test 9: TEST OK [0.324 secs, 3052 KB]
All tests OK.
<p>Your program ('concom') produced all correct answers!  This is your
submission #2 for this problem.  <strong>Congratulations!</strong>
</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"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:concom<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstring</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">concom.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">concom.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;d[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;f[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;own[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;cnt[</span><span style="COLOR: #000000">101</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,i,j,p,m</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;dfs(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(f[i])</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;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">m;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br>&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;cnt[j]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">d[i][j];<br>&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">(cnt[j]</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">50</span><span style="COLOR: #000000">)own[j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br>&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">(own[j])dfs(j);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;k</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">p;&nbsp;d[i][j]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">p;<br>&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">(i</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">m)m</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">m)m</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(f,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;f);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(own,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;own);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(cnt,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;cnt);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">m;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(own[j]</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">i)fout</span><span style="COLOR: #000000">&lt;&lt;</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">j</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&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>}<br></span></div>
</pre>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/122000.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-02 21:05 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/02/122000.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 2 section 2.3 Money Systems </title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121995.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Mon, 02 Aug 2010 11:26:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121995.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/121995.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121995.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/121995.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/121995.html</trackback:ping><description><![CDATA[USER: tian tianbing [tbbd4261]<br>TASK: money<br>LANG: C++<br><br>Compiling...<br>Compile: OK<br><br>Executing...<br>&nbsp;&nbsp; Test 1: TEST OK [0.011 secs, 3088 KB]<br>&nbsp;&nbsp; Test 2: TEST OK [0.000 secs, 3088 KB]<br>&nbsp;&nbsp; Test 3: TEST OK [0.000 secs, 3088 KB]<br>&nbsp;&nbsp; Test 4: TEST OK [0.011 secs, 3088 KB]<br>&nbsp;&nbsp; Test 5: TEST OK [0.011 secs, 3088 KB]<br>&nbsp;&nbsp; Test 6: TEST OK [0.022 secs, 3088 KB]<br>&nbsp;&nbsp; Test 7: TEST OK [0.000 secs, 3088 KB]<br>&nbsp;&nbsp; Test 8: TEST OK [0.000 secs, 3088 KB]<br>&nbsp;&nbsp; Test 9: TEST OK [0.000 secs, 3088 KB]<br>&nbsp;&nbsp; Test 10: TEST OK [0.000 secs, 3088 KB]<br>&nbsp;&nbsp; Test 11: TEST OK [0.011 secs, 3088 KB]<br>&nbsp;&nbsp; Test 12: TEST OK [0.000 secs, 3088 KB]<br>&nbsp;&nbsp; Test 13: TEST OK [0.000 secs, 3088 KB]<br><br>All tests OK.<br>
<p><strong>YOUR PROGRAM ('money') WORKED FIRST TIME!</strong>&nbsp; That's fantastic<br>-- and a rare thing.&nbsp; Please accept these special automated<br>congratulations.<br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 12pt; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; FONT-FAMILY: courier new; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:money<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">money.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">money.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MAX</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">10005</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;dp[MAX]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;money[</span><span style="COLOR: #000000">26</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;v,n,i,j;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">v</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">v;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">money[i];}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;dp[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">v;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">money[i];&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[j]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">dp[j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">money[i]];<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">dp[n]</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&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>}<br></span></div>
<p><br></p>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/121995.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-02 19:26 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121995.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 2 section 2.3   Zero Sum</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121982.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Mon, 02 Aug 2010 09:22:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121982.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/121982.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121982.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/121982.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/121982.html</trackback:ping><description><![CDATA[<div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; BACKGROUND-COLOR: white">
<pre>USER: tian tianbing [tbbd4261]
TASK: zerosum
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 3012 KB]
Test 2: TEST OK [0.000 secs, 3012 KB]
Test 3: TEST OK [0.000 secs, 3012 KB]
Test 4: TEST OK [0.011 secs, 3012 KB]
Test 5: TEST OK [0.011 secs, 3012 KB]
Test 6: TEST OK [0.000 secs, 3012 KB]
Test 7: TEST OK [0.011 secs, 3012 KB]
All tests OK.
<p><strong>YOUR PROGRAM ('zerosum') WORKED FIRST TIME!</strong>  That's fantastic
-- and a rare thing.  Please accept these special automated
congratulations.
</p>
</pre>
<p>Here are the test data inputs:
<pre>------- test 1 -------
3
------- test 2 -------
4
------- test 3 -------
5
------- test 4 -------
6
------- test 5 -------
7
------- test 6 -------
8
------- test 7 -------
9
</pre>
Keep up the good work!<br></div>
<pre></pre>
Thanks for your submission!<br>代码写的不够简洁，搜索；<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 12pt; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; FONT-FAMILY: courier new; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:zerosum<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span><br>#include&lt;</span><span style="COLOR: #000000">iostream</span><span>&gt;<br>#include&lt;</span><span style="COLOR: #000000">fstream</span><span>&gt;<br>#include&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span>&gt;<br>using</span><span style="COLOR: #000000">&nbsp;</span><span>namespace&nbsp;std;<br>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">zerosum.in</span><span>");<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">zerosum.out</span><span>");<br></span><span>int&nbsp;n;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;f[</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span>0};<br></span><span>bool&nbsp;judge()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;g[</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">],num[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">],i,j,t,sum</span><span style="COLOR: #000000">=</span><span>0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)g[i]</span><span>=f[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&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">)num[i]</span><span>=i;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">,t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">n;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">t;&nbsp;i</span><span>++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(g[i]</span><span style="COLOR: #000000">==</span><span>1){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num[i]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">num[i</span><span style="COLOR: #000000">+</span><span>1];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;p</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;p</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">t;p</span><span>++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num[p</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span>=num[p];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;p</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;p</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">t</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;p</span><span>++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g[p</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span>=g[p];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t</span><span>--;<br>&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">(g[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">t)i</span><span>--;//原来的条件是&nbsp;<span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(g[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)i</span><span>--;<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;//没考虑往前移动后后面的值的影响</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">t</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i</span><span>++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(g[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)&nbsp;num[i</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[i]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">num[i</span><span style="COLOR: #000000">+</span><span>1];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;num[i</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[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">num[i</span><span style="COLOR: #000000">+</span><span>1];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;num[t]</span><span style="COLOR: #000000">==</span><span>0;<br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;search(</span><span>int&nbsp;i)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span>==n){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span>if(judge()){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;k</span><span style="COLOR: #000000">=</span><span>1;&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;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">k</span><span>++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(;&nbsp;k</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n;&nbsp;k</span><span>++)&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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(f[k</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&nbsp;</span><span>';<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;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(f[k</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">+</span><span>';<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;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">-</span><span>';<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;fout</span><span>&lt;&lt;k;<br>&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;fout</span><span>&lt;&lt;endl;<br>&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;</span><span>return;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;&nbsp;search(i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);</span><span style="COLOR: #008000">//</span><span>'&nbsp;'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;&nbsp;&nbsp;search(i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);</span><span style="COLOR: #008000">//</span><span>'+'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;&nbsp;&nbsp;search(i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);</span><span style="COLOR: #008000">//</span><span>'-'<br>}<br><br></span><span>int&nbsp;main()<br>{&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span>&gt;&gt;n;<br>&nbsp;&nbsp;&nbsp;&nbsp;search(</span><span>1);<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span>0;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/121982.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-02 17:22 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121982.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>USACO chapter 2 section 2.3  Cow Pedigrees</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121966.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Mon, 02 Aug 2010 07:17:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121966.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/121966.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121966.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/121966.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/121966.html</trackback:ping><description><![CDATA[<div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; BACKGROUND-COLOR: white">
<pre style="FONT-SIZE: 12pt">USER: tian tianbing [tbbd4261]
TASK: nocows
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 3180 KB]
Test 2: TEST OK [0.000 secs, 3180 KB]
Test 3: TEST OK [0.011 secs, 3180 KB]
Test 4: TEST OK [0.000 secs, 3180 KB]
Test 5: TEST OK [0.022 secs, 3180 KB]
Test 6: TEST OK [0.000 secs, 3180 KB]
Test 7: TEST OK [0.022 secs, 3180 KB]
Test 8: TEST OK [0.011 secs, 3180 KB]
Test 9: TEST OK [0.011 secs, 3180 KB]
Test 10: TEST OK [0.022 secs, 3180 KB]
Test 11: TEST OK [0.032 secs, 3180 KB]
Test 12: TEST OK [0.022 secs, 3180 KB]
All tests OK.
<p><strong>YOUR PROGRAM ('nocows') WORKED FIRST TIME!</strong>  That's fantastic
-- and a rare thing.  Please accept these special automated
congratulations.
</p>
</pre>
<p>Here are the test data inputs:
<pre>------- test 1 -------
5 3
------- test 2 -------
9 4
------- test 3 -------
35 7
------- test 4 -------
15 4
------- test 5 -------
75 47
------- test 6 -------
99 15
------- test 7 -------
172 44
------- test 8 -------
165 65
------- test 9 -------
177 57
------- test 10 -------
198 56
------- test 11 -------
199 99
------- test 12 -------
199 77
</pre>
Keep up the good work!<br></div>
<pre></pre>
Thanks for your submission!<br><br>dp[i][j]表示i个结点高度不超过j的所有情况<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 12pt; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; FONT-FAMILY: Courier; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br>ID:tbbd4261<br>PROG:nocows<br>LANG:C++<br></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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>ifstream&nbsp;fin(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">nocows.in</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>ofstream&nbsp;fout(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">nocows.out</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,k,i,j;<br></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;dp[</span><span style="COLOR: #000000">205</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">105</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">k;<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(dp,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;dp);<br>&nbsp;&nbsp;&nbsp;&nbsp;dp[</span><span style="COLOR: #000000">1</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">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">k;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)dp[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">3</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">2</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">k;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;kk</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;kk</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;&nbsp;kk</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(dp[i][j]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">(dp[kk][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">dp[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">kk][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">9901</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;fout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">(dp[n][k]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">dp[n][k</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">9901</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">9901</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;&nbsp;<br>&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>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/121966.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tianlearn-language/" target="_blank">田兵</a> 2010-08-02 15:17 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/02/121966.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>