﻿<?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-随笔分类-URAL</title><link>http://www.cppblog.com/tianlearn-language/category/14031.html</link><description>桥梁是由钢铁工人建造的，而不是由工程师建造的。
同样地，软件是由程序人员编写的，而不是由工程师编写的！</description><language>zh-cn</language><lastBuildDate>Fri, 13 Aug 2010 13:15:49 GMT</lastBuildDate><pubDate>Fri, 13 Aug 2010 13:15:49 GMT</pubDate><ttl>60</ttl><item><title>Ural 1028 stars</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123249.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Thu, 12 Aug 2010 13:33:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123249.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/123249.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123249.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/123249.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/123249.html</trackback:ping><description><![CDATA[<p style="FONT-FAMILY: Georgia"><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: #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">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: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;MAX_X</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">32001</span><span style="COLOR: #000000">,MAX_N</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">15000</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;c[MAX_X</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">0</span><span style="COLOR: #000000">},sum[MAX_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">{</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;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;lowbit(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x){&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;x</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x);&nbsp;}<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;inc(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(x</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">MAX_X)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c[x]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">lowbit(x);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;Sum(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x)<br>{<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">while</span><span style="COLOR: #000000">(x</span><span style="COLOR: #000000">&gt;=</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;&nbsp;&nbsp;&nbsp;ans</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">c[x];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">lowbit(x);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;ans;<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;x,y,i;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</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;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">y;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x</span><span style="COLOR: #000000">++</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;sum[Sum(x)]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inc(x);<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">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;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,sum[i]);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">cout&lt;&lt;sum[i]&lt;&lt;endl;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br><br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/123249.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 21:33 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/08/12/123249.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1060  Flip Game</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/07/31/121812.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Sat, 31 Jul 2010 13:44:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/07/31/121812.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/121812.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/07/31/121812.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/121812.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/121812.html</trackback:ping><description><![CDATA[<table class=status cellSpacing=0 cellPadding=0>
    <tbody>
        <tr class=odd>
            <td class=language>C++</td>
            <td class=verdict_ac>Accepted</td>
            <td class=test><br></td>
            <td class=runtime>0.031</td>
            <td class=memory>197 KB</td>
        </tr>
    </tbody>
</table>
<br><br>
<h2 class=problem_title>1060. Flip Game</h2>
<div class=problem_limits>Time Limit: 2.0 second<br>Memory Limit: 16 MB<br></div>
<div id=problem_text>
<div class=problem_par>
<div class=problem_par_normal>Flip game is played on a rectangular 4&#215;4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the other one is black and each piece is lying either it's black or white side up. Each round you flip 3 to 5 pieces, thus changing the color of their upper side from black to white and vice versa. The pieces to be flipped are chosen every round according to the following rules:
<ol>
    <li>Choose any one of the 16 pieces.
    <li>Flip the chosen piece and also all adjacent pieces to the left, to the right, to the top, and to the bottom of the chosen piece (if there are any). </li>
</ol>
</div>
</div>
<img class=problem_raimage border=0 alt="Problem illustration" align=right src="http://acm.timus.ru/image/get.aspx/5bde394b-6b46-4281-bb0e-1fe3433809e2">
<div class=problem_par>
<div class=problem_par_normal>Consider the following position as an example: </div>
</div>
<div class=problem_par_pre>
<table border=0 cellSpacing=0 cellPadding=0 align=center>
    <tbody>
        <tr>
            <td>
            <pre class=intable>bwbw
            wwww
            bbwb
            bwwb
            </pre>
            </td>
        </tr>
    </tbody>
</table>
</div>
<div class=problem_par>
<div class=problem_par_normal>Here "b" denotes pieces lying their black side up and "w" denotes pieces lying their white side up. If we choose to flip the 1st piece from the 3rd row (this choice is shown at the picture), then the field will become:</div>
</div>
<div class=problem_par_pre>
<table border=0 cellSpacing=0 cellPadding=0 align=center>
    <tbody>
        <tr>
            <td>
            <pre class=intable>bwbw
            bwww
            wwwb
            wwwb
            </pre>
            </td>
        </tr>
    </tbody>
</table>
</div>
<div class=problem_par>
<div class=problem_par_normal>The goal of the game is to flip either all pieces white side up or all pieces black side up. You are to write a program that will search for the minimum number of rounds needed to achieve this goal.</div>
</div>
<h3 class=problem_subtitle>Input</h3>
<div class=problem_par>
<div class=problem_par_normal>The input consists of 4 lines with 4 characters "w" or "b" each that denote game field position. </div>
</div>
<h3 class=problem_subtitle>Output</h3>
<div class=problem_par>
<div class=problem_par_normal>Write to the output a single integer number&nbsp;— the minimum number of rounds needed to achieve the goal of the game from the given position. If the goal is initially achieved, then write 0. If it's impossible to achieve the goal, then write the word "Impossible" (without quotes). </div>
</div>
<h3 class=problem_subtitle>Sample</h3>
<table class=sample>
    <colgroup>
    <col width=350>
    <col width=350>
    <tbody>
        <tr>
            <th>input</th>
            <th>output</th>
        </tr>
        <tr>
            <td>
            <pre class=intable>bwbw
            wwww
            bbwb
            bwwb
            </pre>
            </td>
            <td>
            <pre class=intable>Impossible
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<div class=problem_source><strong>Problem Source: </strong>2000-2001 ACM Northeastern European Regional Programming Contest </div>
</div>
<br>wa了几次<br>原因：1是cnt只增没减<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2是search的推出条件写成if(m==16){ &#8230;&#8230;}，这种情况下对于只改变最后一个即可得情况没有判定。改成m&gt;16 <br><br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: Verdana; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;status[</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></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">0x7fffffff</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;cnt</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,cntMin</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">MAX;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;check()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;f</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">status[</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;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,j;<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">4</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">4</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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(f</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">status[i][j])</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;<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;turn(</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;status[i][j]</span><span style="COLOR: #000000">=!</span><span style="COLOR: #000000">status[i][j];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status[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">status[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status[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">status[i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status[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">status[i][j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status[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">status[i][j</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;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;ch;<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">4</span><span style="COLOR: #000000">;&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">4</span><span style="COLOR: #000000">;&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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">ch;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(ch</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;:&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}&nbsp;<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;search(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;m)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(m</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">16</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">(&nbsp;check()&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;(cnt</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cntMin)&nbsp;)cntMin</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">cnt;&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">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">int</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(m</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">4</span><span style="COLOR: #000000">;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">m</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">4</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">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;turn(i,j);&nbsp;cnt</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;search(m</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;turn(i,j);cnt</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;search(m</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);&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;input();&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;search(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(cntMin</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">MAX)cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Impossible</span><span style="COLOR: #000000">"</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;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">cntMin</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/121812.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-07-31 21:44 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/07/31/121812.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1080  Map Colouring</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/07/31/121796.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Sat, 31 Jul 2010 09:17:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/07/31/121796.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/121796.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/07/31/121796.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/121796.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/121796.html</trackback:ping><description><![CDATA[<table cellSpacing=0 cellPadding=0 align=center>
    <colgroup>
    <col width=800>
    <tbody>
        <tr>
            <td style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">
            <h2 class=problem_title>1080. Map Colouring</h2>
            <div class=problem_limits style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">Time Limit: 1.0 second<br>Memory Limit: 16 MB<br></div>
            <div id=problem_text style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">
            <div class=problem_par style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">
            <div class=problem_par_normal style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">We consider a geographical map with <em>N</em> countries numbered from 1 to <em>N</em> (0&nbsp;&lt;&nbsp;<em>N</em>&nbsp;&lt;&nbsp;99). For every country we know the numbers of other countries which are connected with its border. From every country we can reach to any other one, eventually crossing some borders. Write a program which determines whether it is possible to colour the map only in two colours&nbsp;— red and blue in such a way that if two countries are connected their colours are different. The colour of the first country is red. Your program must output one possible colouring for the other countries, or show, that such colouring is impossible.</div>
            </div>
            <h3 class=problem_subtitle>Input</h3>
            <div class=problem_par style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">
            <div class=problem_par_normal style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">On the first line is written the number <em>N</em>. On the following <em>N</em> lines, the <em>i</em>-th line contains the countries to which the <em>i</em>-th country is connected. Every integer on this line is bigger than <em>i</em>, except the last one which is 0 and marks that no more countries are listed for country <em>i</em>. If a line contains 0, that means that the <em>i</em>-th country is not connected to any other country, which number is larger than <em>i</em>.</div>
            </div>
            <h3 class=problem_subtitle>Output</h3>
            <div class=problem_par style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">
            <div class=problem_par_normal style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">The output contains exactly one line. If the colouring is possible, this line must contain a list of zeros and ones, without any separators between them. The <em>i</em>-th digit in this sequence is the colour of the <em>i</em>-th country. 0 corresponds to red colour, and one&nbsp;— to blue colour. If a colouring is not possible, output the integer &#8722;1.</div>
            </div>
            <h3 class=problem_subtitle>Sample</h3>
            <table class=sample>
                <colgroup>
                <col width=350>
                <col width=350>
                <tbody>
                    <tr>
                        <th>input</th>
                        <th>output</th>
                    </tr>
                    <tr>
                        <td style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">
                        <pre class=intable>3
                        2 0
                        3 0
                        0
                        </pre>
                        </td>
                        <td style="FONT-SIZE: 12pt; FONT-FAMILY: courier new">
                        <pre class=intable>010
                        </pre>
                        </td>
                    </tr>
                </tbody>
            </table>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<pre><br>DFS:或BFS，或者并查集（不会用）</pre>
<pre>这里用的DFS，用一个标记数组，没进入一个联通分图后，标记为0（表示一种颜色）与它相连的标记为1（另一种颜色），</pre>
<pre>然后与1相连的在标记为0。 这里的标记都是对没有标记过的进行的，如果是标记过的，就要检查他们的标记是否相同</pre>
<pre>如果相同则说明，他们同色。<br></pre>
<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">ural&nbsp;1080</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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></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">100</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;adj[MAX][MAX];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;flg[MAX];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n;<br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;isPossible</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</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;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;temp;<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;{<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">(cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">temp,temp</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;{<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;adj[i][temp]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">adj[temp][i]</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;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br></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;i)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(isPossible</span><span style="COLOR: #000000">==</span><span style="COLOR: #0000ff">false</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">if</span><span style="COLOR: #000000">(flg[i]</span><span style="COLOR: #000000">==-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)flg[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</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;{<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">(adj[i][j])<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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flg[j]</span><span style="COLOR: #000000">==-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">){&nbsp;flg[j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">flg[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;&nbsp;dfs(j);&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;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flg[j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">flg[i])isPossible</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;&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;}<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;memset(adj,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">&nbsp;adj);<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;input();<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">)&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flg[i]</span><span style="COLOR: #000000">=-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;flg[</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;</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;dfs(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(isPossible</span><span style="COLOR: #000000">==</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">)cout</span><span style="COLOR: #000000">&lt;&lt;-</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">else</span><span style="COLOR: #000000">&nbsp;{&nbsp;<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;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;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">flg[k];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</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;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/121796.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-07-31 17:17 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/07/31/121796.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1008 Image encoding</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/26/118798.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Sat, 26 Jun 2010 14:38:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/26/118798.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118798.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/26/118798.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118798.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118798.html</trackback:ping><description><![CDATA[<br>
<h2 class=problem_title>1008. Image encoding</h2>
<div class=problem_limits>Time Limit: 2.0 second<br>Memory Limit: 16 MB<br></div>
<div id=problem_text><img class=problem_raimage border=0 alt="Problem illustration" align=right src="http://acm.timus.ru/image/get.aspx/12e825a7-e4fd-4257-90c4-be3e50526011">
<div class=problem_par>
<div class=problem_par_normal>There are several ways to encode an image. In this problem we will consider two representations of an image. We assume that the image consists of black and white pixels. There is at least one black pixel and all black pixels are connected with their sides. Coordinates of black pixels are not less than 1 and not greater than 10. An example of such an image is at the figure.</div>
</div>
<div class=problem_par>
<div class=problem_par_normal>Both representations describe arrangement of black pixels only.</div>
</div>
<div class=problem_par>
<div class=problem_par_normal>At the first representation we specify in the first line number of black pixels and coordinates of each black pixel in the following lines. Pixels are listed in order of increasing X. In case of equality of X they are listed in order of increasing Y. Image at the figure is encoded as follows:</div>
</div>
<div class=problem_par>
<div class=problem_par_normal><strong>6<br>2 3<br>2 4<br>3 3<br>3 4<br>4 2<br>4 3<br></strong></div>
</div>
<div class=problem_par>
<div class=problem_par_normal>At the second representation we specify in the first line coordinates of the lowest left black pixel. Each of the following lines contains a description of neighbors for one of the pixels. At first, neighbors of the lowest left pixel are specified, then neighbors of its first neighbor (if it exists) are specified, then neighbors of its second neighbor (if it also exists) follow. When all its neighbors are described the description of the neighbors of its first neighbor follows. The description of the neighbors of its second neighbor follows then and so on. </div>
</div>
<div class=problem_par>
<div class=problem_par_normal>Each descriptive line contains at most one letter for each neighbor: R for the right, T for the top, L for the left, B for the bottom. If the neighbor was already specified it is not included into the descriptive line and vice-versa. Also there is only one descriptive line for each pixel. Neighbors are listed counter-clockwise starting with the right. Each descriptive line except the last ends with a comma. The last line ends with a full stop. Image at the figure is encoded as follows:</div>
</div>
<div class=problem_par>
<div class=problem_par_normal><strong>2 3<br>RT,<br>RT,<br>,<br>B,<br>,<br>.<br></strong></div>
</div>
<div class=problem_par>
<div class=problem_par_normal>There are no leading or tailing spaces in any representation. There is exactly one space between X and Y coordinates.</div>
</div>
<h3 class=problem_subtitle>Input</h3>
<div class=problem_par>
<div class=problem_par_normal>One representation of the image will be given to your program in the input.</div>
</div>
<h3 class=problem_subtitle>Output</h3>
<div class=problem_par>
<div class=problem_par_normal>Your program has to write other representation of the image to the output.</div>
</div>
<h3 class=problem_subtitle>Sample</h3>
<table class=sample>
    <colgroup>
    <col width=350>
    <col width=350>
    <tbody>
        <tr>
            <th>input</th>
            <th>output</th>
        </tr>
        <tr>
            <td>
            <pre class=intable>6
            2 3
            2 4
            3 3
            3 4
            4 2
            4 3
            </pre>
            </td>
            <td>
            <pre class=intable>2 3
            RT,
            RT,
            ,
            B,
            ,
            .
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<div class=problem_source><strong>Problem Source: </strong>Third Open USTU Collegiate Programming Contest (PhysTech Cup), March 18, 2000<br></div>
</div>
<br>这题花了不少时间，题目没看清，只看示例以为只要从第一种方案转换成第二种，没想到还有从第二种转换成第一种<br>BFS：
<table class=status cellSpacing=0 cellPadding=0>
    <tbody>
        <tr class=even>
            <td class=verdict_ac>Accepted</td>
            <td class=test>&nbsp;&nbsp;&nbsp;&nbsp; <br></td>
            <td class=runtime>0.015&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
            <td class=memory>217 KB</td>
        </tr>
    </tbody>
</table>
<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #ffff99; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: Verdana; COLOR: #003366; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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>#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;&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<br><br>typedef&nbsp;</span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;point<br>{</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x,y;&nbsp;}&nbsp;point;<br><br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;graph[</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">bool</span><span style="COLOR: #000000">&nbsp;f[</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">bool</span><span style="COLOR: #000000">&nbsp;print[</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><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;lbx</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">,lby</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;<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;input()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x,y;<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;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">y;&nbsp;graph[x][y]</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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(x</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">lbx){&nbsp;lbx</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x;&nbsp;lby</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y;&nbsp;}<br>&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">(x</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">lbx</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">y</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">lby)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lby</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;BFS1()&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">{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queue</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">point</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;q;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;point&nbsp;temp;&nbsp;temp.x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">lbx;&nbsp;temp.y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">lby;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">lbx</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">lby</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q.push(temp);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x,y;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;cnt</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print[lbx][lby]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(q.size())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&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">q.front();&nbsp;q.pop();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">temp.x;&nbsp;y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">temp.y;<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">(f[x][y]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</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;f[x][y]</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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(graph[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">1</span><span style="COLOR: #000000">&amp;&amp;!</span><span style="COLOR: #000000">f[x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][y])<br>{</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">print[x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][y])&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">R</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;&nbsp;print[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">1</span><span style="COLOR: #000000">;&nbsp;temp.x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;temp.y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y;&nbsp;q.push(temp);}<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">(graph[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">1</span><span style="COLOR: #000000">&amp;&amp;!</span><span style="COLOR: #000000">f[x][y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])<br>{</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">print[x][y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">T</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;&nbsp;print[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">1</span><span style="COLOR: #000000">;&nbsp;temp.x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x;temp.y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;q.push(temp);}<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">(graph[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">1</span><span style="COLOR: #000000">&amp;&amp;!</span><span style="COLOR: #000000">f[x</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][y])<br>{</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">print[x</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][y])&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">L</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;&nbsp;print[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">1</span><span style="COLOR: #000000">;&nbsp;temp.x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;temp.y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y;&nbsp;q.push(temp);}<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">(graph[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">1</span><span style="COLOR: #000000">&amp;&amp;!</span><span style="COLOR: #000000">f[x][y</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])<br>{</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">print[x][y</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">B</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;&nbsp;print[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">1</span><span style="COLOR: #000000">;&nbsp;temp.x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x;temp.y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;q.push(temp);}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">cnt;<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">(cnt</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">n)&nbsp;cout</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;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;&nbsp;cout&nbsp;</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;}<br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;BFS2()&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;从R T L B描述转换成坐标</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lbx</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">n;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">lby;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queue</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">point</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">q;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;point&nbsp;temp;&nbsp;temp.x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">lbx;&nbsp;temp.y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">lby;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q.push(temp);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;str;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x,y;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;graph[lbx][lby]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(q.size())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">q.front();&nbsp;q.pop();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">temp.x;&nbsp;y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">temp.y;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(f[x][y])</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[x][y]</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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">str;<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;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">str.size()</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;&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">(str[i]</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">)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{graph[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">1</span><span style="COLOR: #000000">;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">f[x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][y]){&nbsp;temp.x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;temp.y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y;&nbsp;q.push(temp);}&nbsp;}<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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(str[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">T</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">){graph[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">1</span><span style="COLOR: #000000">;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">f[x][y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]){&nbsp;temp.x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x;&nbsp;temp.y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;q.push(temp);}&nbsp;}<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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(str[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">L</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">){graph[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">1</span><span style="COLOR: #000000">;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">f[x</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][y]){&nbsp;temp.x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;temp.y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y;&nbsp;q.push(temp);}&nbsp;}<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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(str[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">B</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">){graph[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">1</span><span style="COLOR: #000000">;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">f[x][y</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]){&nbsp;temp.x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x;&nbsp;temp.y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;q.push(temp);}&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(str[str.size()</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">)</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;cnt</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</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">10</span><span style="COLOR: #000000">;&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">10</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(graph[i][j])cnt</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">cnt</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<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">10</span><span style="COLOR: #000000">;&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">10</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(graph[i][j])cout</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;&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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(getchar()</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\n</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;input();&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;BFS1();<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;BFS2();<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/118798.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-06-26 22:38 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/26/118798.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1048  Superlong sums</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/25/118695.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Fri, 25 Jun 2010 03:31:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/25/118695.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118695.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/25/118695.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118695.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118695.html</trackback:ping><description><![CDATA[<br>
<h2 class=problem_title>1048. Superlong sums</h2>
<div class=problem_limits>Time Limit: 2.0 second<br>Memory Limit: 16 MB<br></div>
<div id=problem_text>
<div class=problem_par>
<div class=problem_par_normal>The creators of a new programming language D++ have found out that whatever limit for SuperLongInt type they make, sometimes programmers need to operate even larger numbers. A limit of 1000 digits is so small&#8230; You have to find the sum of two numbers with maximal size of 1&nbsp;000&nbsp;000 digits.</div>
</div>
<h3 class=problem_subtitle>Input</h3>
<div class=problem_par>
<div class=problem_par_normal>The first line contains a single number N (1&nbsp;&#8804;&nbsp;N&nbsp;&#8804;&nbsp;1&nbsp;000&nbsp;000)&nbsp;— the length of the integers (in order to make their lengths equal, some leading zeroes can be added). It is followed by these integers written in columns. That is, the next N lines contain two digits each, divided by a space. Each of the two given integers is not less than 1, and the length of their sum does not exceed N.</div>
</div>
<h3 class=problem_subtitle>Output</h3>
<div class=problem_par>
<div class=problem_par_normal>Output exactly N digits in a single line representing the sum of these two integers.</div>
</div>
<h3 class=problem_subtitle>Sample</h3>
<table class=sample>
    <colgroup>
    <col width=350>
    <col width=350>
    <tbody>
        <tr>
            <th>input</th>
            <th>output</th>
        </tr>
        <tr>
            <td>
            <pre class=intable>4
            0 4
            4 2
            6 8
            3 7
            </pre>
            </td>
            <td>
            <pre class=intable>4750</pre>
            </td>
        </tr>
    </tbody>
</table>
<div class=problem_source>Problem Author: Stanislav Vasilyev and Alexander Klepinin<br>Problem Source: Ural State University collegiate programming contest (25.03.2000)<br></div>
</div>
<br>简单大数加法<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px">#include&lt;iostream&gt;<br>using&nbsp;namespace&nbsp;std;<br>int&nbsp;a[1000005]={0};<br>int&nbsp;b[1000005]={0};<br>int&nbsp;ans[1000005]={0};<br>int&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;N,i,c=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin&gt;&gt;N;<br>&nbsp;&nbsp;&nbsp;&nbsp;for(i=1;&nbsp;i&lt;=N;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&gt;&gt;a[i]&gt;&gt;b[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;for(i=N;&nbsp;i&gt;=1;&nbsp;i--)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans[i]=(a[i]+b[i]+c)%10;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c=(a[i]+b[i]+c)/10;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(i=1&nbsp;&nbsp;;&nbsp;i&lt;=N;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;ans[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system("pause");<br>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;<br>}<br></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/118695.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-06-25 11:31 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/25/118695.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1047  Simple calculations</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/24/118673.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Thu, 24 Jun 2010 15:09:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/24/118673.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118673.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/24/118673.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118673.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118673.html</trackback:ping><description><![CDATA[<table cellSpacing=0 cellPadding=0 align=center>
    <colgroup>
    <col width=800>
    <tbody>
        <tr>
            <td>
            <h2 class=problem_title>1047. Simple calculations</h2>
            <div class=problem_limits>Time Limit: 1.0 second<br>Memory Limit: 16 MB<br></div>
            <div id=problem_text>
            <div class=problem_par>
            <div class=problem_par_normal>There is a sequence of <em>N</em>&nbsp;+&nbsp;2 elements <em>a</em><sub>0</sub>, <em>a</em><sub>1</sub>, &#8230;, <em>a</em><sub><em>N</em>+1</sub> (1&nbsp;&#8804;&nbsp;<em>N</em>&nbsp;&#8804;&nbsp;3000, &#8722;2000&nbsp;&#8804;&nbsp;<em>a</em><sub><em>i</em></sub>&nbsp;&#8804;&nbsp;2000). It is known that </div>
            </div>
            <div class=problem_par>
            <div class=problem_par_center><em>a</em><sub><em>i</em></sub>&nbsp;=&nbsp;(<em>a</em><sub><em>i</em>&#8722;1</sub>&nbsp;+&nbsp;<em>a</em><sub><em>i</em>+1</sub>)/2&nbsp;&#8722;&nbsp;<em>c</em><sub><em>i</em></sub></div>
            </div>
            <div class=problem_par>
            <div class=problem_par_normal>for each <em>i</em>&nbsp;=&nbsp;1, 2, &#8230;, <em>N</em>.</div>
            </div>
            <div class=problem_par>
            <div class=problem_par_normal>You are given <em>a</em><sub>0</sub>, <em>a</em><sub><em>N</em>+1</sub>, <em>c</em><sub>1</sub>, &#8230;, <em>c</em><sub><em>N</em></sub>. Write a program which calculates <em>a</em><sub>1</sub>.</div>
            </div>
            <h3 class=problem_subtitle>Input</h3>
            <div class=problem_par>
            <div class=problem_par_normal>The first line contains an integer <em>N</em>. The next two lines consist of numbers <em>a</em><sub>0</sub> and <em>a</em><sub><em>N</em>+1</sub> each having two digits after decimal point, and the next <em>N</em> lines contain numbers <em>c</em><sub><em>i</em></sub> (also with two digits after decimal point), one number per line.</div>
            </div>
            <h3 class=problem_subtitle>Output</h3>
            <div class=problem_par>
            <div class=problem_par_normal>Output <em>a</em><sub>1</sub> in the same format as <em>a</em><sub>0</sub> and <em>a</em><sub><em>N</em>+1</sub>.</div>
            </div>
            <h3 class=problem_subtitle>Sample</h3>
            <table class=sample>
                <colgroup>
                <col width=350>
                <col width=350>
                <tbody>
                    <tr>
                        <th>input</th>
                        <th>output</th>
                    </tr>
                    <tr>
                        <td>
                        <pre class=intable>1
                        50.50
                        25.50
                        10.15
                        </pre>
                        </td>
                        <td>
                        <pre class=intable>27.85
                        </pre>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div class=problem_source><strong>Problem Author: </strong>Dmitry Filimonenkov<br><strong>Problem Source: </strong>Ural State University collegiate programming contest (25.03.2000)<br></div>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<br>&nbsp;&nbsp; 用数学方法推出公式即可：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #ffff99; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: Verdana; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">ural1047<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">a1=(&nbsp;aN_1&nbsp;+N*a0&nbsp;-2*(&nbsp;(c1+&#8230;&#8230;cN)+&nbsp;(c1+&#8230;&#8230;cN-1&nbsp;)&nbsp;+&#8230;&#8230;(c1+c2)+(c1)&nbsp;))/(N+1)</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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: #0000ff">double</span><span style="COLOR: #000000">&nbsp;ci[</span><span style="COLOR: #000000">3010</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;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">ci[i]=c1+c2+&#8230;&#8230;ci</span><span style="COLOR: #008000"><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;N,i;<br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;a0,aN_1,temp,sum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">N</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">a0</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">aN_1;<br>&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;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">temp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ci[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">ci[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">temp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">ci[i];<br>&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;sum</span><span style="COLOR: #000000">*=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br><br>&nbsp;&nbsp;&nbsp;cout.precision(</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;cout</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">(&nbsp;aN_1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;N</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">a0&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">sum)</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">(N</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br><br>&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/118673.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-06-24 23:09 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/24/118673.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1033  Labyrinth</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/24/118672.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Thu, 24 Jun 2010 15:02:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/24/118672.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118672.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/24/118672.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118672.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118672.html</trackback:ping><description><![CDATA[<table class=status cellSpacing=0 cellPadding=0>
    <tbody>
        <tr class=even>
            <td class=verdict_ac>Accepted</td>
            <td class=test><br></td>
            <td class=runtime>0.015</td>
            <td class=memory>217 KB</td>
        </tr>
    </tbody>
</table>
<br>
<h2 class=problem_title>1033. Labyrinth</h2>
<div class=problem_limits>Time Limit: 1.0 second<br>Memory Limit: 16 MB<br></div>
<div id=problem_text>
<div class=problem_par>
<div class=problem_par_normal>Administration of the labyrinth has decided to start a new season with new wallpapers. For this purpose they need a program to calculate the square of the walls inside the labyrinth. This job is just for you!</div>
</div>
<div class=problem_par>
<div class=problem_par_normal>The labyrinth is represented by a matrix <em>N</em>&#215;<em>N</em> (3 &#8804; <em>N</em> &#8804; 33, you see, &#8216;3&#8217; is a magic digit!). Some matrix cells contain a dot character (&#8216;.&#8217;) that denotes an empty square. Other cells contain a diesis character (&#8216;#&#8217;) that denotes a square filled by monolith block of stone wall. All squares are of the same size 3&#215;3 meters.</div>
</div>
<div class=problem_par>
<div class=problem_par_normal>The walls are constructed around the labyrinth (except for the upper left and lower right corners, which are used as entrances) and on the cells with a diesis character. No other walls are constructed. There always will be a dot character at the upper left and lower right corner cells of the input matrix.</div>
</div>
<div class=problem_centered_picture><img border=0 alt="Problem illustration" src="http://acm.timus.ru/image/get.aspx/44cfda11-2c7f-4893-ba9e-2b37ede7c423"></div>
<div class=problem_par>
<div class=problem_par_normal>Your task is to calculate the square of visible part of the walls inside the labyrinth. In other words, the square of the walls' surface visible to a visitor of the labyrinth. Note that there's no holes to look or to move through between any two adjacent blocks of the wall. The blocks are considered to be adjacent if they touch each other in any corner. See picture for an example: visible walls inside the labyrinth are drawn with bold lines. The height of all the walls is 3 meters.</div>
</div>
<h3 class=problem_subtitle>Input</h3>
<div class=problem_par>
<div class=problem_par_normal>The first line of the input contains the single number <em>N</em>. The next <em>N</em> lines contain <em>N</em> characters each. Each line describes one row of the labyrinth matrix. In each line only dot and diesis characters will be used and each line will be finished with a new line character. There will be no spaces in the input.</div>
</div>
<h3 class=problem_subtitle>Output</h3>
<div class=problem_par>
<div style="FONT-FAMILY: courier new; FONT-SIZE: 14pt" class=problem_par_normal>Your program should print to the output a single integer — the exact value of the square of the wallpaper needed.</div>
</div>
<h3 class=problem_subtitle>Sample</h3>
<table class=sample>
    <colgroup>
    <col width=350>
    <col width=350>
    <tbody>
        <tr>
            <th>input</th>
            <th>output</th>
        </tr>
        <tr>
            <td>
            <pre class=intable>5
            .....
            ...##
            ..#..
            ..###
            .....
            </pre>
            </td>
            <td>
            <pre class=intable>198
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<br>搜索题：注意的要从两个入口处搜索，防止中间断开了<br>wa了两次 找不出错误，search(i+1，j)写成search(i+1,j+1)；<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #ff9900; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;maxSize</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">35</span><span style="COLOR: #000000">;<br><br></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;ural1033<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;ural1033(){&nbsp;size</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&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);&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;input();<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;print();<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;search(</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;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;size;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;getn(){</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;N;}<br></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;a[maxSize][maxSize];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;f[maxSize][maxSize];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;N;<br>};<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;ural1033::input()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">N;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,j;<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;</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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">a[i][j];<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</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">)a[</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">2</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">)a[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">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">)a[N</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">'</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">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">)a[i][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">'</span><span style="COLOR: #000000">#</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br><br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;ural1033::&nbsp;search(</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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">N</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">N</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">a[i][j]</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">f[i][j]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;f[i][j]</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">if</span><span style="COLOR: #000000">(a[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">'</span><span style="COLOR: #000000">#</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)size</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;search(i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,j);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a[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">'</span><span style="COLOR: #000000">#</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)size</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;search(i,j</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">if</span><span style="COLOR: #000000">(a[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">'</span><span style="COLOR: #000000">#</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)size</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;search(i,j</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">if</span><span style="COLOR: #000000">(a[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">'</span><span style="COLOR: #000000">#</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)size</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;search(i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,j);<br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;ural1033::print()<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;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">N</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">,cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl)<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">0</span><span style="COLOR: #000000">;&nbsp;j</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;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">a[i][j]</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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">0</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">,cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl)<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">0</span><span style="COLOR: #000000">;&nbsp;j</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;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">f[i][j]</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;ural1033&nbsp;ural;<br>&nbsp;&nbsp;&nbsp;&nbsp;ural.input();<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;ural.search(</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;ural.search(ural.getn(),ural.getn());<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">ural.size</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<br></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/118672.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-06-24 23:02 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/24/118672.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1044  Lucky tickets. Easy!</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/23/118594.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Wed, 23 Jun 2010 15:36:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/23/118594.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118594.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/23/118594.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118594.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118594.html</trackback:ping><description><![CDATA[注意的是这里的n位数可以以0打头<br><br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: Arial; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;f2()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</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;i1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i1</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i1</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;i2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i2</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i2</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">(i1</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">i2)count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;f4()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</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;i1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i1</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i1</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;i2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i2</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i2</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;i3</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i3</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i3</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;i4</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i4</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i4</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">(i1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i2</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">i3</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i4)count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;f6()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</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;i1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i1</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i1</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;i2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i2</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i2</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;i3</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i3</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i3</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;i4</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i4</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i4</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;i5</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i5</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i5</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;i6</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i6</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i6</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">(i1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i2</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i3</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">i5</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i4</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i6)count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;f8()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</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;i1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i1</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i1</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;i2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i2</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i2</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;i3</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i3</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i3</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;i4</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i4</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i4</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;i5</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i5</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i5</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;i6</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i6</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i6</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;i7</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i7</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i7</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;i8</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i8</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">;&nbsp;i8</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">(i1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i2</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i3</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i4</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">i5</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i7</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i6</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i8)count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">count</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<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;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&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">2</span><span style="COLOR: #000000">)f2();<br>&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">(n</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">)f4();<br>&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">(n</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">)f6();<br>&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">(n</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">)f8();<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/118594.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-06-23 23:36 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/23/118594.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1010  Discrete Function</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/23/118589.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Wed, 23 Jun 2010 15:09:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/23/118589.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118589.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/23/118589.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118589.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118589.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><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></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;a[</span><span style="COLOR: #000000">100005</span><span style="COLOR: #000000">];<br><br></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;abs(</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;a)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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">0</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">a:</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">a;<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,x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;xl;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">a[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xl</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">abs(a[</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">a[</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">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">)<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">(abs(a[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">a[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">xl)<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;x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xl</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">abs(a[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">a[i</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;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</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">x</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<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/118589.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-06-23 23:09 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/23/118589.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 题目分类 【转】</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118504.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 22 Jun 2010 14:14:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118504.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118504.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118504.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118504.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118504.html</trackback:ping><description><![CDATA[<p style="FONT-SIZE: 12pt; FONT-FAMILY: Verdana">题号&nbsp;&nbsp; 标题&nbsp;&nbsp;&nbsp; 难度系数&nbsp;&nbsp;&nbsp; 算法 <br>1000 A+B Problem 10% 直接加 <br>1002 Phone Numbers 50% 动态规划或最短路 <br>1003 Parity 70% 区间减法 <br>1004 Sightseeing trip 60% 最短路 <br>1005 Stone Pile 30% 动态规划或搜索 <br>1006 Square Frames 35% 模拟 <br>1007 Code Words 30% 模拟 <br>1008 Image encoding 30% 广度优先搜索 <br>1009 K-Based Numbers 20% 递推或枚举（数据规模小） <br>1010 Discrete Function 40% 贪心 <br>1011 Conductors 25% 搜索 <br>1012 K-Based Numbers 30% 递推 <br>1013 K-Based Numbers 33% 递推 <br>1014 The Product of Digits 30% 贪心 <br>1015 Test the differences 35% 模拟 <br>1016 A cube on the walk 50% 搜索或者最短路 <br>1017 The Staircases 30% 递推（母函数） <br>1018 The Binary Apple Tree 50% 动态规划 <br>1019 A Line painting 40% 离散化处理 <br>1020 Rope 45% 一般的计算几何问题 <br>1021 Sacrament of the sum 40% 动态规划 <br>1022 Genealogical Tree 30% 拓补排序 <br>1023 Buttons 50% 动态规划 <br>1024 Permutations 25% 置换（和题目名字一样） <br>1025 Democracy in Danger 20% 贪心 <br>1026 Questions and Answers 40% 快速排序 <br>1027 D++ again 40% 字符串处理 <br>1028 Stars 75% 线段树 <br>1029 Ministry 55% 动态规划（注意优化） <br>1030 Titanic 60% 计算几何（注意精度！） <br>1031 Railway Tickets 45% 动态规划 <br>1032 Find a mutilple 55% 同余问题 <br>1033 Labyrinth 30% 搜索、遍历 <br>1034 Queens in peaceful positions 35% 搜索 <br>1035 Cross-sitich 60% 欧拉路径问题 <br>1036 Lucky tickets 50% 递推 <br>1037 Memory Management 55% 模拟（注意优化） <br>1038 Spell Checker 45% 字符串的操作及统计 <br>1039 Anniversary party 40% 树的动态规划 <br>1040 Airline company 55% 搜索 <br>1041 Nikifor 85% 线性代数问题<br>（过了，但怀疑算法不对） <br>1042 Central Heating 50% 解线性同余方程组 <br>1043 Cover an Arc. 58% 计算几何 <br>1044 Lucky tickets 40% 递推 <br>1045 A funny game 55% 搜索 <br>1046 Geometrical dreams 88% 很复杂的计算几何 <br>1047 Simple calculations 30% 数学题，解方程吧！ <br>1048 Superlong Sums 48% 高精度加法 <br>1049 Brave ballonists 30% 模拟 <br>1050 Preparing an article 63% 比较麻烦的字符串处理 <br>1051 A simple game on a grid 60% 数学杂题 <br>1052 Rabbit Hunt 28% 简单的计算几何 <br>1053 Pinocchio 32% 求最大公约数（题目意思不明） <br>1054 Hanoi Tower 50% 数学问题 <br>1055 Combinations 40% 数学问题 <br>1056 Computer net 55% 动态规划 <br>1057 Amount of dergess 53% 数学问题 <br>1058 Chocolate 85% 复杂的计算几何问题 <br>1059 Expression 20% 简单的打印问题 <br>1060 Flip game 35% 我搜索，过了 <br>1061 Buffer Manager 45% 模拟 <br>1062 Triathlon 83% 复杂的不等式问题 <br>1064 Binary Search 48% 搜索 <br>1065 Frontier 75% 动态规划 <br>1066 Garland 40% 数学问题 <br>1067 Disk Tree 45% 模拟或排序 <br>1068 Sum 20% 简单的加法题 <br>1069 The prufer code 50% 构造 <br>1070 A local time 60% 考虑要周全 <br>1071 Nikifor - 2 45% 搜索 <br>1072 Routing 40% 最短路问题 <br>1073 A square problem 50% 动态规划 <br>1074 A very short problem 58% 模拟、判断 <br>1075 A thread in the space 65% 麻烦的计算几何 <br>1076 Trash 50% 二分图的最大权匹配 <br>1077 Travelling Tours 60% 图的遍历 <br>1078 Segments 40% 动态规划 <br>1079 Maxium 50% 数学问题 <br>1080 Map coloring 35% 深度优先搜索 <br>1081 Binary Lexicographic Sequence 40% 数学问题 <br>1082 Gaby Ivanushka 15% 没有算法，直接输出答案 <br>1083 Factorials!!! 25% 简单的数学计算 <br>1084 A goat in a kitchen garden 35% 简单的计算几何 <br>1085 Meeting 55% 最短路 <br>1086 Cryptography 45% 数学问题 <br>1087 The time to take stones 48% 递推 <br>1088 Ilya Murumetz 33% 二叉树的性质 <br>1089 verification with a vocabulary 50% 字符串处理 <br>1090 In the army now 60% 平衡二叉树 <br>1091 Tmutarakan exams 57% 运用容斥原理 <br>1092 Transversal 75% 贪心 <br>1093 Darts 65% 立体解析几何 <br>1094 E-screen 40% 字符串处理 <br>1095 Nikifor - 3 45% 同余问题 <br>1096 Get the right route plate! 40% 广度优先搜索 <br>1097 Square country - 2 63% 离散化处理 <br>1098 Questions 48% 字符串处理 <br>1099 Work scheduling 60% 图的最大基数匹配</p>
<p style="FONT-SIZE: 12pt; FONT-FAMILY: Verdana">本文来自CSDN博客，转载请标明出处：<a href="http://blog.csdn.net/nash635/archive/2010/03/22/5402820.aspx">http://blog.csdn.net/nash635/archive/2010/03/22/5402820.aspx</a></p>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/118504.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-06-22 22:14 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118504.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1026  Questions and answers</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118500.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 22 Jun 2010 13:40:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118500.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118500.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118500.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118500.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118500.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><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">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><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a[</span><span style="COLOR: #000000">100005</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,k,i;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">a[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;sort(a</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,a</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">n);<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;getchar();getchar();getchar();getchar();<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">k;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;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">k;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">temp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">a[temp]</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/118500.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-06-22 21:40 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118500.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1025  Democracy in danger</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118492.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 22 Jun 2010 13:08:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118492.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118492.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118492.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118492.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118492.html</trackback:ping><description><![CDATA[<p style="FONT-SIZE: 12pt">&nbsp;</p>
有K组，取人数较小的(k+1)/2组即可，每组取(人数+1)/2，排下序就可以了<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: Verdana; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#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: #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></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;k,i,sum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,temp;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">k;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">vec;<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">k;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">temp;vec.push_back(temp);&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;sort(vec.begin(),vec.end());<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">k</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">(vec[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">2</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/118492.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-06-22 21:08 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118492.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1022  Genealogical tree</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118490.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 22 Jun 2010 12:37:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118490.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118490.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118490.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118490.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118490.html</trackback:ping><description><![CDATA[拓扑排序：<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px">//Ural&nbsp;1022<br>#include&lt;iostream&gt;<br>#include&lt;vector&gt;<br>using&nbsp;namespace&nbsp;std;<br>int&nbsp;a[101][101]={0};<br>vector&lt;int&gt;vec;<br>&nbsp;int&nbsp;n,i,j;<br>bool&nbsp;f[101]={0};<br>void&nbsp;input()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;cin&gt;&gt;n;<br>&nbsp;&nbsp;&nbsp;&nbsp;for(i=1;&nbsp;i&lt;=n;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j=1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(cin&gt;&gt;a[i][j],a[i][j]!=0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j++;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br>void&nbsp;dfs(int&nbsp;i)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(f[i])return&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;j=1;&nbsp;a[i][j]!=0;&nbsp;j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dfs(a[i][j]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[i]=1;&nbsp;vec.push_back(i);<br>}<br><br>void&nbsp;topo()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;i=1;&nbsp;i&lt;=n;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!f[i])dfs(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;vec[vec.size()-1];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;i=vec.size()-2;&nbsp;i&gt;=0;&nbsp;i--)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;'&nbsp;'&lt;&lt;vec[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;endl;<br>}<br><br>int&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;input();<br>&nbsp;&nbsp;&nbsp;topo();<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;system("pause");<br>&nbsp;&nbsp;&nbsp;return&nbsp;0;<br>}<br></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/118490.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-06-22 20:37 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118490.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1020 Rope</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118476.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Tue, 22 Jun 2010 09:05:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118476.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118476.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118476.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118476.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118476.html</trackback:ping><description><![CDATA[<table cellSpacing=0 cellPadding=0 align=center>
    <colgroup>
    <col width=800>
    <tbody>
        <tr>
            <td>
            <h2 class=problem_title>1020. Rope</h2>
            <div class=problem_limits>Time Limit: 1.0 second<br>Memory Limit: 16 MB<br></div>
            <div id=problem_text>
            <div class=problem_par>
            <div class=problem_par_normal>Plotters have barbarously hammered <em>N</em> nails into an innocent plane shape, so that one can see now only heads. Moreover, pursuing their mean object, they have hammered all the nails into the vertices of a convex polygon. After that they&#8230;it is awful&#8230; have roped off the nails, so that the shape felt upset (the rope was very thin). They&#8217;ve done it as it is shown in the figure.</div>
            </div>
            <div class=problem_centered_picture><img border=0 alt="Problem illustration" src="http://acm.timus.ru/image/get.aspx/5efad458-3218-423f-b3f6-685fc554139f"></div>
            <div class=problem_par>
            <div class=problem_par_normal>Your task is to find out a length of the rope.</div>
            </div>
            <h3 class=problem_subtitle>Input</h3>
            <div class=problem_par>
            <div class=problem_par_normal>There two numbers in the first line of the standard input: <em>N</em> — a number of nails (1 &#8804; <em>N</em> &#8804; 100), and a real number <em>R</em> — a radius of heads of nails. All the heads have the same radius. Further there are <em>N</em> lines, each of them contains a pair of real coordinates (separated by a space) of centers of nails. An absolute value of the coordinates doesn&#8217;t exceed 100. The nails are described either in a clockwise or in a counterclockwise order starting from an arbitrary nail. Heads of different nails don&#8217;t adjoin.</div>
            </div>
            <h3 class=problem_subtitle>Output</h3>
            <div class=problem_par>
            <div class=problem_par_normal>Output a real number with two digits precision (after a decimal point) — a length of the rope.</div>
            </div>
            <h3 class=problem_subtitle>Sample</h3>
            <table class=sample>
                <colgroup>
                <col width=350>
                <col width=350>
                <tbody>
                    <tr>
                        <th>input</th>
                        <th>output</th>
                    </tr>
                    <tr>
                        <td>
                        <pre class=intable>4 1
                        0.0 0.0
                        2.0 0.0
                        2.0 2.0
                        0.0 2.0
                        </pre>
                        </td>
                        <td>
                        <pre class=intable>14.28
                        </pre>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div class=problem_source><strong>Problem Author: </strong>Alexander Petrov &amp; Nikita Shamgunov<br><strong>Problem Source: </strong>Ural State University Internal Contest October'2000 Junior Session<br></div>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<br>结果就是各线段长度的和加上半径为R的周长，n=1时 需额外考虑下<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</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>#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></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;&nbsp;pi</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">acos(</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1.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</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,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">double</span><span style="COLOR: #000000">&nbsp;sum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,r</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,x0,y0,x1,y1,x,y;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">r;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">x</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">y;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;保存第一个点&nbsp;&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;x0</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x;&nbsp;y0</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y;<br>&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">pi</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">r;<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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">x1</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">y1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">sqrt(&nbsp;(x1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x0)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(x1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x0)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;(y1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y0)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(y1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y0)&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x0</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">x1;&nbsp;y0</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y1;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&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">1</span><span style="COLOR: #000000">)&nbsp;sum</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">sqrt(&nbsp;(x1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(x1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;(y1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(y1</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y)&nbsp;);<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%.2lf\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,sum);<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/118476.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-06-22 17:05 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/22/118476.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1017  The Staircases</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/20/118320.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Sun, 20 Jun 2010 13:43:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/20/118320.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/118320.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/20/118320.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/118320.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/118320.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 101.27%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; HEIGHT: 415px; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008000">DP&nbsp; 状态转移方程：f[i][j]=f[i-1][j]+f[i-1][j-i]<br>//</span><span style="COLOR: #008000">Ural&nbsp;1017</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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: #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">505</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;f[MAX][MAX]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};&nbsp;<br>&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">f[i][j]表示最后一个阶梯的高度不超过i，使用j个bricks的方案&nbsp;&nbsp;f[i][j]=f[i-1][j]+f[i-1][j-i]&nbsp;</span><span style="COLOR: #008000"><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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&nbsp;&nbsp;&nbsp;&nbsp;f[</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">;<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;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">n;&nbsp;j</span><span style="COLOR: #000000">&gt;=</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;f[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">f[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">f[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">i];<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">0</span><span style="COLOR: #000000">;&nbsp;j</span><span style="COLOR: #000000">&lt;=</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">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">f[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][j];<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">f[n][n]</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;<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">}<br><br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/118320.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-06-20 21:43 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/20/118320.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1014 The Product of Digits</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/14/117871.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Mon, 14 Jun 2010 06:25:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/14/117871.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/117871.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/14/117871.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/117871.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/117871.html</trackback:ping><description><![CDATA[这题想错了，就是把N分解了，如果素因子有大于等于10的就不行了，想复杂了<br><br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a[</span><span style="COLOR: #000000">10</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,i;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br>&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">){cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;</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;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(n</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">){cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">1</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">;}<br>&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">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">9</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(p</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">){a[i]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;&nbsp;p</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">else</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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(p</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">){&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;-</span><span style="COLOR: #000000">1</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;}<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">9</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">(</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">a[i];&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">i;<br>&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/117871.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-06-14 14:25 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/14/117871.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1021 Sacrament of the sum</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/14/117862.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Mon, 14 Jun 2010 04:11:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/14/117862.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/117862.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/14/117862.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/117862.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/117862.html</trackback:ping><description><![CDATA[题目意思就是判断两堆数里面能不能从两堆里各找一个数使它们的和是10000<br>
<table class=status cellSpacing=0 cellPadding=0>
    <tbody>
        <tr class=odd>
            <td class=verdict_ac>Accepted</td>
            <td class=test><br></td>
            <td class=runtime>0.062</td>
            <td class=memory>&nbsp; 1 241 KB</td>
        </tr>
    </tbody>
</table>
<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></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: #0000ff">int</span><span style="COLOR: #000000">&nbsp;p1[</span><span style="COLOR: #000000">100000</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">},p2[</span><span style="COLOR: #000000">100000</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;ne1[</span><span style="COLOR: #000000">100000</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">},ne2[</span><span style="COLOR: #000000">100000</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;n1,n2,i,t;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n1;<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">n1;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">t;<br>&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">0</span><span style="COLOR: #000000">)p1[t]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;ne1[</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">t]</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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n2;<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;&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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">t;<br>&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">0</span><span style="COLOR: #000000">)p2[t]</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;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;ne2[</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">t]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;flag</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">100000</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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(p1[i])<br>&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">&lt;=</span><span style="COLOR: #000000">10000</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">(p2[</span><span style="COLOR: #000000">10000</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">i]){flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</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;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(ne2[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">10000</span><span style="COLOR: #000000">]){flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flag</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>&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">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">100000</span><span style="COLOR: #000000">;&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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(p2[i])<br>&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">&lt;=</span><span style="COLOR: #000000">10000</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">(p1[</span><span style="COLOR: #000000">10000</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">i]){flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;}&nbsp;}<br>&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">(ne1[i</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">10000</span><span style="COLOR: #000000">]){flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flag)cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">YES</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;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">NO</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;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></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/117862.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-06-14 12:11 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/14/117862.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1001 Reverse root</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117815.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Sun, 13 Jun 2010 12:22:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117815.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/117815.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117815.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/117815.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/117815.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">//只是开方<br>//
<table class=status cellSpacing=0 cellPadding=0>
    <tbody>
        <tr class=even>
            <td class=verdict_ac>Accepted</td>
            <td class=test><br></td>
            <td class=runtime>0.25</td>
            <td class=memory>1 237 KB</td>
        </tr>
    </tbody>
</table>
<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></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;a[</span><span style="COLOR: #000000">300000</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">long</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;i,j</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">(cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">i)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sqrt(</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">(i));&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">j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%.4lf\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,a[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/117815.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-06-13 20:22 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117815.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1052 Rabbit hunt</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117813.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Sun, 13 Jun 2010 12:10:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117813.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/117813.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117813.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/117813.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/117813.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">//取两点确定一条直线，计算在上面的点，纪录最大点数<br>//
<table class=status cellSpacing=0 cellPadding=0>
    <tbody>
        <tr class=even>
            <td class=verdict_ac>Accepted</td>
            <td class=test><br></td>
            <td class=runtime>0.031</td>
            <td class=memory>201 KB</td>
        </tr>
    </tbody>
</table>
<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></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x[</span><span style="COLOR: #000000">200</span><span style="COLOR: #000000">],y[</span><span style="COLOR: #000000">200</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;ex</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1e</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">12</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,cnt,max</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,j;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</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">0</span><span style="COLOR: #000000">;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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">x[i]</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">y[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">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&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;cnt</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">y[j]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y[i],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b</span><span style="COLOR: #000000">=-</span><span style="COLOR: #000000">(x[j]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x[i]),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="COLOR: #000000">=-</span><span style="COLOR: #000000">(y[j]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">y[i])</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">x[i]&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;y[i]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(x[j]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">x[i]);<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">n;&nbsp;k</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">(k</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">i)</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br>&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">(a</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">x[k]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">b</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">y[k]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">c</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)cnt</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">(cnt</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">max)max</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">cnt;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">max</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/117813.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-06-13 20:10 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117813.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1086 Cryptography</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117810.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Sun, 13 Jun 2010 11:46:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117810.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/117810.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117810.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/117810.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/117810.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">//题目要求第K个素数；k&lt;=15000；把前15000个素数存起来即可，每次输出a[k]&nbsp;<br>
<table class=status cellSpacing=0 cellPadding=0>
    <tbody>
        <tr class=even>
            <td class=verdict_ac>//Accepted</td>
            <td class=test><br></td>
            <td class=runtime>0.062</td>
            <td class=memory>277 KB</td>
        </tr>
    </tbody>
</table>
<br>1</span>&nbsp;<span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span>&nbsp;<span style="COLOR: #000000">#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: #008080">&nbsp;3</span>&nbsp;<span style="COLOR: #000000"></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: #008080">&nbsp;4</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;cnt</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">15000</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;5</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a[cnt</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">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">&nbsp;6</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;isprime(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n)<br></span><span style="COLOR: #008080">&nbsp;7</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;8</span>&nbsp;<span style="COLOR: #000000">&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">2</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;9</span>&nbsp;<span style="COLOR: #000000">&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">2</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">10</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;t</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sqrt(n</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">1.0</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">11</span>&nbsp;<span style="COLOR: #000000">&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">3</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">t;&nbsp;i</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">12</span>&nbsp;<span style="COLOR: #000000">&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">i</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;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">13</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span>&nbsp;<span style="COLOR: #000000">}<br></span><span style="COLOR: #008080">15</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">16</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">17</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">18</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n,i,k,count</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">19</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">n;<br></span><span style="COLOR: #008080">20</span>&nbsp;<span style="COLOR: #000000">&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;count</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">cnt;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">21</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">22</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(isprime(i))a[</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">count]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br></span><span style="COLOR: #008080">23</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">24</span>&nbsp;<span style="COLOR: #000000">&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></span><span style="COLOR: #008080">25</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">k;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">a[k]</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;}<br></span><span style="COLOR: #008080">26</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">27</span>&nbsp;<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></span><span style="COLOR: #008080">28</span>&nbsp;<span style="COLOR: #000000">}<br></span><span style="COLOR: #008080">29</span>&nbsp;<span style="COLOR: #000000"></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/117810.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-06-13 19:46 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117810.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1084 Goat in the Garden</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117808.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Sun, 13 Jun 2010 11:32:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117808.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/117808.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117808.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/117808.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/117808.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 12pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">//简单数学题&nbsp; <br>/*
<table class=status cellSpacing=0 cellPadding=0>
    <tbody>
        <tr class=odd>
            <td class=verdict_ac>Accepted</td>
            <td class=test><br></td>
            <td class=runtime>0.031</td>
            <td class=memory>233 KB</td>
        </tr>
    </tbody>
</table>
*/<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></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">&nbsp;p2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sqrt(</span><span style="COLOR: #000000">2.0</span><span style="COLOR: #000000">),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pi</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">acos(</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1.0</span><span style="COLOR: #000000">),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tri,</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;area</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;l,r;<br>&nbsp;&nbsp;&nbsp;&nbsp;cout.precision(</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</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">r;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(r</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">l</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">1.0</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)cout</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">pi</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">r</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">r</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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(r</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">l</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">1.0</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p2</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)cout</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">(</span><span style="COLOR: #0000ff">double</span><span style="COLOR: #000000">)l</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">l</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;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tri</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">acos(l</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">1.0</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">r));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;area</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">(l</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">1.0</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">r</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">sin(tri)</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;area</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">(pi</span><span style="COLOR: #000000">/</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">tri)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">r</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">r</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;area</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;cout</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">area</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<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></span></div>
<img src ="http://www.cppblog.com/tianlearn-language/aggbug/117808.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-06-13 19:32 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117808.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ural 1005  Stone pile</title><link>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117799.html</link><dc:creator>田兵</dc:creator><author>田兵</author><pubDate>Sun, 13 Jun 2010 08:32:00 GMT</pubDate><guid>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117799.html</guid><wfw:comment>http://www.cppblog.com/tianlearn-language/comments/117799.html</wfw:comment><comments>http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117799.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tianlearn-language/comments/commentRss/117799.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tianlearn-language/services/trackbacks/117799.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 14pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">//搜索，O(2^n)<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: #008000">//</span><span style="COLOR: #008000">#include&lt;limit.h&gt;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">#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></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;w[</span><span style="COLOR: #000000">21</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,total</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">INT_MAX;<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;search(</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;now)<br>{<br>&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">n)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(ans</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">abs(total</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">now))ans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">abs(total</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">now);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;search(i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,now</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">w[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;search(i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,now);<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;cin</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">;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;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">w[i];total</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">w[i];}<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;search(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;cout</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;<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>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: Verdana; FONT-SIZE: 14pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">DP：01背包 往容量为total/2的包里装石头，价值与重量相等<br>//
<table class=status cellSpacing=0 cellPadding=0>
    <tbody>
        <tr class=even>
            <td class=verdict_ac>Accepted</td>
            <td class=test><br></td>
            <td class=runtime>0.031</td>
            <td class=memory>&nbsp;&nbsp;&nbsp; 3933 KB</td>
        </tr>
    </tbody>
</table>
<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></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;SIZE</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">21</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;w[SIZE]</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;dp[SIZE</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">100000</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">5</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,i,total,v,j;<br>&nbsp;&nbsp;&nbsp;&nbsp;cin</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">,total</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">n&nbsp;;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;cin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">w[i];&nbsp;total</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">w[i];&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;v</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">total</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br>&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">v;&nbsp;j</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">w[i];&nbsp;j</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(dp[j]</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">dp[j</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">w[i]]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">w[i])<br>&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">w[i]]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">w[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">total</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">dp[v]</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/117799.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-06-13 16:32 <a href="http://www.cppblog.com/tianlearn-language/archive/2010/06/13/117799.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>