﻿<?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++博客-powerwater-文章分类-竞赛题解_POJ</title><link>http://www.cppblog.com/powerwater/category/17995.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 20 Jul 2016 17:58:29 GMT</lastBuildDate><pubDate>Wed, 20 Jul 2016 17:58:29 GMT</pubDate><ttl>60</ttl><item><title>POJ3020 Antenna Placement</title><link>http://www.cppblog.com/powerwater/articles/159175.html</link><dc:creator>龙在江湖</dc:creator><author>龙在江湖</author><pubDate>Wed, 26 Oct 2011 15:34:00 GMT</pubDate><guid>http://www.cppblog.com/powerwater/articles/159175.html</guid><wfw:comment>http://www.cppblog.com/powerwater/comments/159175.html</wfw:comment><comments>http://www.cppblog.com/powerwater/articles/159175.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/powerwater/comments/commentRss/159175.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/powerwater/services/trackbacks/159175.html</trackback:ping><description><![CDATA[<div lang="en-US" class="ptt">Antenna Placement</div>
<div class="plm">
<table align="center">
<tbody>
<tr>
<td><strong>Time Limit:</strong> 1000MS</td>
<td width="10"></td>
<td><strong>Memory Limit:</strong> 65536K</td></tr>
<tr>
<td><strong>Total Submissions:</strong> 3993</td>
<td width="10"></td>
<td><strong>Accepted:</strong> 1954</td></tr></tbody></table></div>
<p class="pst">Description</p>
<div lang="en-US" class="ptx">The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most striking reason why they got the job, is their discovery of a new, highly noise resistant, antenna. It is called 4DAir, and comes in four types. Each type can only transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and longitudinal grid, because of the interacting electromagnetic field of the earth. The four types correspond to antennas operating in the directions north, west, south, and east, respectively. Below is an example picture of places of interest, depicted by twelve small rings, and nine 4DAir antennas depicted by ellipses covering them. <br /><img src="http://poj.org/images/3020_1.jpg"  alt="" /> <br />Obviously, it is desirable to use as few antennas as possible, but still provide coverage for each place of interest. We model the problem as follows: Let A be a rectangular matrix describing the surface of Sweden, where an entry of A either is a point of interest, which must be covered by at least one antenna, or empty space. Antennas can only be positioned at an entry in A. When an antenna is placed at row r and column c, this entry is considered covered, but also one of the neighbouring entries (c+1,r),(c,r+1),(c-1,r), or (c,r-1), is covered depending on the type chosen for this particular antenna. What is the least number of antennas for which there exists a placement in A such that all points of interest are covered? <br /><br /></div>
<p class="pst">Input</p>
<div lang="en-US" class="ptx">On the first row of input is a single positive integer n, specifying the number of scenarios that follow. Each scenario begins with a row containing two positive integers h and w, with 1 &lt;= h &lt;= 40 and 0 &lt; w &lt;= 10. Thereafter is a matrix presented, describing the points of interest in Sweden in the form of h lines, each containing w characters from the set ['*','o']. A '*'-character symbolises a point of interest, whereas a 'o'-character represents open space. <br /><br /></div>
<p class="pst">Output</p>
<div lang="en-US" class="ptx">For each scenario, output the minimum number of antennas necessary to cover all '*'-entries in the scenario's matrix, on a row of its own.</div>
<p class="pst">Sample Input</p><pre class="sio">2
7 9
ooo**oooo
**oo*ooo*
o*oo**o**
ooooooooo
*******oo
o*o*oo*oo
*******oo
10 1
*
*
*
o
*
*
*
*
*
*
</pre>
<p class="pst">Sample Output</p><pre class="sio">17
5</pre>
<p class="pst">Source</p>
<div lang="en-US" class="ptx"><a href="http://poj.org/searchproblem?field=source&amp;key=Svenskt+M%C3%A4sterskap+i+Programmering%2FNorgesmesterskapet+2001">Svenskt M&#228;sterskap i Programmering/Norgesmesterskapet 2001</a></div><br />题目大意：给出一张图，图中元素为&#8217;*'或者&#8217;o'。其中，相连的两个&#8217;*&#8217;可以划入一个圈中。问至少需要几个圈将所有的&#8217;*'画起来。<br />输入<br />&nbsp; 第一行为数据组数n<br />&nbsp; 以下共有n组数据<br />&nbsp; 每组数据第一行为两个数 x，y<br />&nbsp; 表示 是x行y列 的矩阵<br />输出<br />&nbsp; 最少圈数<br /><br /> <img src ="http://www.cppblog.com/powerwater/aggbug/159175.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/powerwater/" target="_blank">龙在江湖</a> 2011-10-26 23:34 <a href="http://www.cppblog.com/powerwater/articles/159175.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ3041 Asteroids</title><link>http://www.cppblog.com/powerwater/articles/159168.html</link><dc:creator>龙在江湖</dc:creator><author>龙在江湖</author><pubDate>Wed, 26 Oct 2011 14:58:00 GMT</pubDate><guid>http://www.cppblog.com/powerwater/articles/159168.html</guid><wfw:comment>http://www.cppblog.com/powerwater/comments/159168.html</wfw:comment><comments>http://www.cppblog.com/powerwater/articles/159168.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/powerwater/comments/commentRss/159168.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/powerwater/services/trackbacks/159168.html</trackback:ping><description><![CDATA[<div lang="en-US" class="ptt">Asteroids</div>
<div class="plm">
<table align="center">
<tbody>
<tr>
<td><strong>Time Limit:</strong> 1000MS</td>
<td width="10"></td>
<td><strong>Memory Limit:</strong> 65536K</td></tr>
<tr>
<td><strong>Total Submissions:</strong> 8613</td>
<td width="10"></td>
<td><strong>Accepted:</strong> 4611</td></tr></tbody></table></div>
<p class="pst">Description</p>
<div lang="en-US" class="ptx">Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 &lt;= N &lt;= 500). The grid contains K asteroids (1 &lt;= K &lt;= 10,000), which are conveniently located at the lattice points of the grid. <br /><br />Fortunately, Bessie has a powerful weapon that can vaporize all the asteroids in any given row or column of the grid with a single shot.This weapon is quite expensive, so she wishes to use it sparingly.Given the location of all the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate all of the asteroids.</div>
<p class="pst">Input</p>
<div lang="en-US" class="ptx">* Line 1: Two integers N and K, separated by a single space. <br />* Lines 2..K+1: Each line contains two space-separated integers R and C (1 &lt;= R, C &lt;= N) denoting the row and column coordinates of an asteroid, respectively.</div>
<p class="pst">Output</p>
<div lang="en-US" class="ptx">* Line 1: The integer representing the minimum number of times Bessie must shoot.</div>
<p class="pst">Sample Input</p><pre class="sio">3 4
1 1
1 3
2 2
3 2
</pre>
<p class="pst">Sample Output</p><pre class="sio">2
</pre>
<p class="pst">Hint</p>
<div lang="en-US" class="ptx">INPUT DETAILS: <br />The following diagram represents the data, where "X" is an asteroid and "." is empty space: <br /><tt>X.X <br />.X. <br />.X.</tt> <br /><br />OUTPUT DETAILS: <br />Bessie may fire across row 1 to destroy the asteroids at (1,1) and (1,3), and then she may fire down column 2 to destroy the asteroids at (2,2) and (3,2).</div>
<p class="pst">Source</p>
<div lang="en-US" class="ptx"><a href="http://poj.org/searchproblem?field=source&amp;key=USACO+2005+November+Gold">USACO 2005 November Gold<br /><br />题目大意：在一个坐标系中有k个障碍物，每次可以消除一整行或一整列上所有障碍物，问最少几次清除干净。<br /><br /><span>【分析]：利用行列法构造二分图：每个障碍物的x与y连一条边，此时每一条边就代表一个障碍物，而每一个点就代表一行或一列，所求即转化成了用最小的点覆盖所有的边=最小点覆盖=最大匹配。匈牙利算法求解。</span></a></div>
<div lang="en-US" class="ptx">
<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-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img id="Code_Closed_Image_225215" onclick="this.style.display='none'; Code_Closed_Text_225215.style.display='none'; Code_Open_Image_225215.style.display='inline'; Code_Open_Text_225215.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" width="11" height="16"><img style="display: none" id="Code_Open_Image_225215" onclick="this.style.display='none'; Code_Open_Text_225215.style.display='none'; Code_Closed_Image_225215.style.display='inline'; Code_Closed_Text_225215.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" height="16"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Code_Closed_Text_225215">code</span><span style="display: none" id="Code_Open_Text_225215"><br /><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#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 />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</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;N(</span><span style="color: #000000">505</span><span style="color: #000000">);<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;adj[N][N],match[N];<br /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;used[N]</span><span style="color: #000000">=</span><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">};<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,k,matchn;<br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;init()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;r,c,i;<br />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n,</span><span style="color: #000000">&amp;</span><span style="color: #000000">k);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;adj[i][</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">k;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">r,</span><span style="color: #000000">&amp;</span><span style="color: #000000">c);&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">cin&gt;&gt;r&gt;&gt;c;</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adj[r][</span><span style="color: #000000">++</span><span style="color: #000000">adj[r][</span><span style="color: #000000">0</span><span style="color: #000000">]]</span><span style="color: #000000">=</span><span style="color: #000000">c;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;can(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k)<br />{<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">&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">adj[k][</span><span style="color: #000000">0</span><span style="color: #000000">];i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">adj[k][i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">!</span><span style="color: #000000">used[j])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;used[j]</span><span style="color: #000000">=</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">!</span><span style="color: #000000">match[j]</span><span style="color: #000000">||</span><span style="color: #000000">can(match[j]))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;match[j]</span><span style="color: #000000">=</span><span style="color: #000000">k;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br />}<br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;hungary()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;memset(match,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(match));<br />&nbsp;&nbsp;&nbsp;&nbsp;matchn</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">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;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;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(can(i))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matchn</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(used,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(used));<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;print()<br />{<br />&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">,matchn);&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">cout&lt;&lt;matchn&lt;&lt;endl;</span><span style="color: #008000"><br /></span><span style="color: #000000">}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;init();<br />&nbsp;&nbsp;&nbsp;&nbsp;hungary();<br />&nbsp;&nbsp;&nbsp;&nbsp;print();<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">system("pause");</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></span></div></div>
<div lang="en-US" class="ptx"><br /><br /></div><img src ="http://www.cppblog.com/powerwater/aggbug/159168.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/powerwater/" target="_blank">龙在江湖</a> 2011-10-26 22:58 <a href="http://www.cppblog.com/powerwater/articles/159168.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>P1088_1 滑雪</title><link>http://www.cppblog.com/powerwater/articles/159154.html</link><dc:creator>龙在江湖</dc:creator><author>龙在江湖</author><pubDate>Wed, 26 Oct 2011 13:22:00 GMT</pubDate><guid>http://www.cppblog.com/powerwater/articles/159154.html</guid><wfw:comment>http://www.cppblog.com/powerwater/comments/159154.html</wfw:comment><comments>http://www.cppblog.com/powerwater/articles/159154.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/powerwater/comments/commentRss/159154.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/powerwater/services/trackbacks/159154.html</trackback:ping><description><![CDATA[<div lang="en-US" class="ptt">滑雪</div>
<div class="plm">
<table align="center">
<tbody>
<tr>
<td><strong>Time Limit:</strong> 1000MS</td>
<td width="10"></td>
<td><strong>Memory Limit:</strong> 65536K</td></tr>
<tr>
<td><strong>Total Submissions:</strong> 51951</td>
<td width="10"></td>
<td><strong>Accepted:</strong> 18906</td></tr></tbody></table></div>
<p class="pst">Description</p>
<div lang="en-US" class="ptx">Michael喜欢滑雪百这并不奇怪， 因为滑雪的确很刺激。可是为了获得速度，滑的区域必须向下倾斜，而且当你滑到坡底，你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 <br /><pre> 1  2  3  4 5
<br />16 17 18 19 6
<br />15 24 25 20 7
<br />14 23 22 21 8
<br />13 12 11 10 9</pre><br />一个人可以从某个点滑向上下左右相邻四个点之一，当且仅当高度减小。在上面的例子中，一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上，这是最长的一条。</div>
<p class="pst">Input</p>
<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-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img id="Code_Closed_Image_212117" onclick="this.style.display='none'; Code_Closed_Text_212117.style.display='none'; Code_Open_Image_212117.style.display='inline'; Code_Open_Text_212117.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" width="11" height="16"><img style="display: none" id="Code_Open_Image_212117" onclick="this.style.display='none'; Code_Open_Text_212117.style.display='none'; Code_Closed_Image_212117.style.display='inline'; Code_Closed_Text_212117.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" height="16"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Code_Closed_Text_212117">code</span><span style="display: none" id="Code_Open_Text_212117"><br /><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</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 />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdlib</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;map[</span><span style="color: #000000">101</span><span style="color: #000000">][</span><span style="color: #000000">101</span><span style="color: #000000">],len[</span><span style="color: #000000">101</span><span style="color: #000000">][</span><span style="color: #000000">101</span><span style="color: #000000">],r,c;<br /><br /></span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;dp(</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;x1,</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;y1)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;i,x2,y2,max</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">long</span><span style="color: #000000">&nbsp;dir[</span><span style="color: #000000">4</span><span style="color: #000000">][</span><span style="color: #000000">2</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">{</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">1</span><span style="color: #000000">};<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(len[x1][y1])&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;len[x1][y1];&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">4</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x2</span><span style="color: #000000">=</span><span style="color: #000000">x1</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</span><span style="color: #000000">0</span><span style="color: #000000">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y2</span><span style="color: #000000">=</span><span style="color: #000000">y1</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</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">if</span><span style="color: #000000">&nbsp;(x2</span><span style="color: #000000">&lt;</span><span style="color: #000000">1</span><span style="color: #000000">||</span><span style="color: #000000">x2</span><span style="color: #000000">&gt;</span><span style="color: #000000">r</span><span style="color: #000000">||</span><span style="color: #000000">y2</span><span style="color: #000000">&lt;</span><span style="color: #000000">1</span><span style="color: #000000">||</span><span style="color: #000000">y2</span><span style="color: #000000">&gt;</span><span style="color: #000000">c)&nbsp;</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">if</span><span style="color: #000000">&nbsp;(map[x2][y2]</span><span style="color: #000000">&lt;</span><span style="color: #000000">map[x1][y1]&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;dp(x2,y2)</span><span style="color: #000000">&gt;</span><span style="color: #000000">max)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max</span><span style="color: #000000">=</span><span style="color: #000000">len[x2][y2];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;len[x1][y1]</span><span style="color: #000000">=</span><span style="color: #000000">max</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;(max</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">);<br />}&nbsp;&nbsp;&nbsp;<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">long</span><span style="color: #000000">&nbsp;i,j,k</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">,ans;<br />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%ld%ld</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">r,</span><span style="color: #000000">&amp;</span><span style="color: #000000">c);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">r;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">&nbsp;(j</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">c;j</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%ld</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">map[i][j]);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;memset(len,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(len));<br />&nbsp;&nbsp;&nbsp;&nbsp;ans</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&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">r;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">&nbsp;(j</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">c;j</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;dp(i,j);&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans</span><span style="color: #000000">=</span><span style="color: #000000">(len[i][j]</span><span style="color: #000000">&gt;</span><span style="color: #000000">ans</span><span style="color: #000000">?</span><span style="color: #000000">len[i][j]:ans);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%ld\n</span><span style="color: #000000">"</span><span style="color: #000000">,ans);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">system("pause");&nbsp;&nbsp;</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></span></div>
<p class="pst"></p>
<div lang="en-US" class="ptx">输入的第一行表示区域的行数R和列数C(1 &lt;= R,C &lt;= 100)。下面是R行，每行有C个整数，代表高度h，0&lt;=h&lt;=10000。</div>
<p class="pst">Output</p>
<div lang="en-US" class="ptx">输出最长区域的长度。</div>
<p class="pst">Sample Input</p><pre class="sio">5 5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
</pre>
<p class="pst">Sample Output</p><pre class="sio">25</pre>
<p class="pst">Source</p>
<div lang="en-US" class="ptx"><a href="http://poj.org/searchproblem?field=source&amp;key=SHTSC+2002">SHTSC 2002</a><br /><br /></div><img src ="http://www.cppblog.com/powerwater/aggbug/159154.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/powerwater/" target="_blank">龙在江湖</a> 2011-10-26 21:22 <a href="http://www.cppblog.com/powerwater/articles/159154.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ1088 滑雪</title><link>http://www.cppblog.com/powerwater/articles/159153.html</link><dc:creator>龙在江湖</dc:creator><author>龙在江湖</author><pubDate>Wed, 26 Oct 2011 13:11:00 GMT</pubDate><guid>http://www.cppblog.com/powerwater/articles/159153.html</guid><wfw:comment>http://www.cppblog.com/powerwater/comments/159153.html</wfw:comment><comments>http://www.cppblog.com/powerwater/articles/159153.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/powerwater/comments/commentRss/159153.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/powerwater/services/trackbacks/159153.html</trackback:ping><description><![CDATA[<div lang="en-US" class="ptt">滑雪</div>
<div class="plm">
<table align="center">
<tbody>
<tr>
<td><strong>Time Limit:</strong> 1000MS</td>
<td width="10"></td>
<td><strong>Memory Limit:</strong> 65536K</td></tr>
<tr>
<td><strong>Total Submissions:</strong> 51950</td>
<td width="10"></td>
<td><strong>Accepted:</strong> 18905</td></tr></tbody></table></div>
<p class="pst">Description</p>
<div lang="en-US" class="ptx">Michael喜欢滑雪百这并不奇怪， 因为滑雪的确很刺激。可是为了获得速度，滑的区域必须向下倾斜，而且当你滑到坡底，你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 <br /><pre> 1  2  3  4 5
<br />16 17 18 19 6
<br />15 24 25 20 7
<br />14 23 22 21 8
<br />13 12 11 10 9</pre><br />一个人可以从某个点滑向上下左右相邻四个点之一，当且仅当高度减小。在上面的例子中，一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上，这是最长的一条。</div>
<p class="pst">Input</p>
<div lang="en-US" class="ptx">输入的第一行表示区域的行数R和列数C(1 &lt;= R,C &lt;= 100)。下面是R行，每行有C个整数，代表高度h，0&lt;=h&lt;=10000。</div>
<p class="pst">Output</p>
<div lang="en-US" class="ptx">输出最长区域的长度。</div>
<p class="pst">Sample Input</p><pre class="sio">5 5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
</pre>
<p class="pst">Sample Output</p><pre class="sio">25</pre>
<p class="pst">Source</p>
<div lang="en-US" class="ptx"><a href="http://poj.org/searchproblem?field=source&amp;key=SHTSC+2002">SHTSC 2002</a><br />&nbsp;
<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-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img id="Code_Closed_Image_211057" onclick="this.style.display='none'; Code_Closed_Text_211057.style.display='none'; Code_Open_Image_211057.style.display='inline'; Code_Open_Text_211057.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" width="11" height="16"><img style="display: none" id="Code_Open_Image_211057" onclick="this.style.display='none'; Code_Open_Text_211057.style.display='none'; Code_Closed_Image_211057.style.display='inline'; Code_Closed_Text_211057.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" height="16"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Code_Closed_Text_211057">code:</span><span style="display: none" id="Code_Open_Text_211057"><br /><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">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 /></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;area<br />{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;h,x,y;<br />};<br />area&nbsp;info[</span><span style="color: #000000">10001</span><span style="color: #000000">];<br /></span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;map[</span><span style="color: #000000">101</span><span style="color: #000000">][</span><span style="color: #000000">101</span><span style="color: #000000">],len[</span><span style="color: #000000">101</span><span style="color: #000000">][</span><span style="color: #000000">101</span><span style="color: #000000">],r,c;<br /><br /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;comp(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;area&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">x,</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;area&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">y)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;x.h</span><span style="color: #000000">&lt;</span><span style="color: #000000">y.h;<br />}<br /><br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;value(</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;k)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">long</span><span style="color: #000000">&nbsp;i,x1,y1,x2,y2,max</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">long</span><span style="color: #000000">&nbsp;dir[</span><span style="color: #000000">4</span><span style="color: #000000">][</span><span style="color: #000000">2</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">{</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">1</span><span style="color: #000000">};<br />&nbsp;&nbsp;&nbsp;&nbsp;x1</span><span style="color: #000000">=</span><span style="color: #000000">info[k].x;<br />&nbsp;&nbsp;&nbsp;&nbsp;y1</span><span style="color: #000000">=</span><span style="color: #000000">info[k].y;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">4</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x2</span><span style="color: #000000">=</span><span style="color: #000000">x1</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</span><span style="color: #000000">0</span><span style="color: #000000">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y2</span><span style="color: #000000">=</span><span style="color: #000000">y1</span><span style="color: #000000">+</span><span style="color: #000000">dir[i][</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">if</span><span style="color: #000000">&nbsp;(x2</span><span style="color: #000000">&lt;</span><span style="color: #000000">1</span><span style="color: #000000">||</span><span style="color: #000000">x2</span><span style="color: #000000">&gt;</span><span style="color: #000000">r</span><span style="color: #000000">||</span><span style="color: #000000">y2</span><span style="color: #000000">&lt;</span><span style="color: #000000">1</span><span style="color: #000000">||</span><span style="color: #000000">y2</span><span style="color: #000000">&gt;</span><span style="color: #000000">c)&nbsp;</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">if</span><span style="color: #000000">&nbsp;(map[x2][y2]</span><span style="color: #000000">&lt;</span><span style="color: #000000">map[x1][y1]</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">len[x2][y2]</span><span style="color: #000000">&gt;</span><span style="color: #000000">max)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max</span><span style="color: #000000">=</span><span style="color: #000000">len[x2][y2];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;len[x1][y1]</span><span style="color: #000000">=</span><span style="color: #000000">max</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">;<br />}&nbsp;&nbsp;&nbsp;<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">long</span><span style="color: #000000">&nbsp;i,j,k</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">,ans;<br />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%ld%ld</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">r,</span><span style="color: #000000">&amp;</span><span style="color: #000000">c);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">r;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">&nbsp;(j</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">c;j</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;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%ld</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">map[i][j]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;info[</span><span style="color: #000000">++</span><span style="color: #000000">k].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;info[k].y</span><span style="color: #000000">=</span><span style="color: #000000">j;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;info[k].h</span><span style="color: #000000">=</span><span style="color: #000000">map[i][j];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;memset(len,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(len));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;sort(info</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">,info</span><span style="color: #000000">+</span><span style="color: #000000">k</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">,comp);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">k;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;value(i);<br />&nbsp;&nbsp;&nbsp;&nbsp;ans</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&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">r;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">&nbsp;(j</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">c;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ans</span><span style="color: #000000">=</span><span style="color: #000000">(len[i][j]</span><span style="color: #000000">&gt;</span><span style="color: #000000">ans</span><span style="color: #000000">?</span><span style="color: #000000">len[i][j]:ans);<br />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%ld\n</span><span style="color: #000000">"</span><span style="color: #000000">,ans);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">system("pause");</span><span style="color: #008000"><br /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}&nbsp;</span></span></div><br /></div> <img src ="http://www.cppblog.com/powerwater/aggbug/159153.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/powerwater/" target="_blank">龙在江湖</a> 2011-10-26 21:11 <a href="http://www.cppblog.com/powerwater/articles/159153.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ2446 棋盘覆盖</title><link>http://www.cppblog.com/powerwater/articles/159136.html</link><dc:creator>龙在江湖</dc:creator><author>龙在江湖</author><pubDate>Wed, 26 Oct 2011 09:06:00 GMT</pubDate><guid>http://www.cppblog.com/powerwater/articles/159136.html</guid><wfw:comment>http://www.cppblog.com/powerwater/comments/159136.html</wfw:comment><comments>http://www.cppblog.com/powerwater/articles/159136.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/powerwater/comments/commentRss/159136.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/powerwater/services/trackbacks/159136.html</trackback:ping><description><![CDATA[<div lang="en-US" class="ptt">source: <a href="http://poj.org/problem?id=2446">http://poj.org/problem?id=2446</a><br />Chessboard</div>
<div class="plm">
<table align="center">
<tbody>
<tr>
<td><strong>Time Limit:</strong> 2000MS</td>
<td width="10"></td>
<td><strong>Memory Limit:</strong> 65536K</td></tr>
<tr>
<td><strong>Total Submissions:</strong> 8985</td>
<td width="10"></td>
<td><strong>Accepted:</strong> 2740</td></tr></tbody></table></div>
<p class="pst">Description</p>
<div lang="en-US" class="ptx">Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of cards with size 1 * 2 to cover the board. However, she thinks it too easy to bob, so she makes some holes on the board (as shown in the figure below). <br />
<center><img alt="" src="http://poj.org/images/2446_1.jpg" /></center><br />We call a grid, which doesn&#8217;t contain a hole, a normal grid. Bob has to follow the rules below: <br />1. Any normal grid should be covered with exactly one card. <br />2. One card should cover exactly 2 normal adjacent grids. <br /><br />Some examples are given in the figures below: <br />
<center><img alt="" src="http://poj.org/images/2446_2.jpg" /> <br />A VALID solution.</center><br />
<center><img alt="" src="http://poj.org/images/2446_3.jpg" /> <br />An invalid solution, because the hole of red color is covered with a card.</center><br />
<center><img alt="" src="http://poj.org/images/2446_4.jpg" /> <br />An invalid solution, because there exists a grid, which is not covered.</center><br />Your task is to help Bob to decide whether or not the chessboard can be covered according to the rules above.</div>
<p class="pst">Input</p>
<div lang="en-US" class="ptx">There are 3 integers in the first line: m, n, k (0 &lt; m, n &lt;= 32, 0 &lt;= K &lt; m * n), the number of rows, column and holes. In the next k lines, there is a pair of integers (x, y) in each line, which represents a hole in the y-th row, the x-th column.</div>
<p class="pst">Output</p>
<div lang="en-US" class="ptx">If the board can be covered, output "YES". Otherwise, output "NO".</div>
<p class="pst">Sample Input</p><pre class="sio">4 3 2
2 1
3 3
</pre>
<p class="pst">Sample Output</p><pre class="sio">YES</pre>
<p class="pst">Hint</p>
<div lang="en-US" class="ptx"><img alt="" src="http://poj.org/images/2446_5.jpg" /> <br />A possible solution for the sample input 
<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-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img id="Code_Closed_Image_171040" onclick="this.style.display='none'; Code_Closed_Text_171040.style.display='none'; Code_Open_Image_171040.style.display='inline'; Code_Open_Text_171040.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" width="11" height="16"><img style="display: none" id="Code_Open_Image_171040" onclick="this.style.display='none'; Code_Open_Text_171040.style.display='none'; Code_Closed_Image_171040.style.display='inline'; Code_Closed_Text_171040.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" height="16"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Code_Closed_Text_171040">参考程序</span><span style="display: none" id="Code_Open_Text_171040"><br /><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><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">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">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 /></span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;N&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">35</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;dx[]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;{</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dy[]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;{&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">};<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;m,n,k,oddn,even,match[N</span><span style="color: #000000">*</span><span style="color: #000000">N</span><span style="color: #000000">/</span><span style="color: #000000">2</span><span style="color: #000000">],number[N][N];<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;adj[N</span><span style="color: #000000">*</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">5</span><span style="color: #000000">];<br /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;used[N</span><span style="color: #000000">*</span><span style="color: #000000">N],ishole[N][N];&nbsp;&nbsp;<br />&nbsp;&nbsp;<br /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;init(){<br />&nbsp;&nbsp;&nbsp;&nbsp;memset(match,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(match));<br />&nbsp;&nbsp;&nbsp;&nbsp;memset(used,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(used));<br />&nbsp;&nbsp;&nbsp;&nbsp;memset(ishole,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(ishole));<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">(adj));<br />&nbsp;&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">m</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">n</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">k;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;((m</span><span style="color: #000000">*</span><span style="color: #000000">n</span><span style="color: #000000">-</span><span style="color: #000000">k)</span><span style="color: #000000">%</span><span style="color: #000000">2</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">,x,y;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">k;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">y</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">x;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ishole[x][y]</span><span style="color: #000000">=</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;oddn</span><span style="color: #000000">=</span><span style="color: #000000">even</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">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">m;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">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;j</span><span style="color: #000000">++</span><span style="color: #000000">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(ishole[i][j])&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;((i</span><span style="color: #000000">+</span><span style="color: #000000">j)</span><span style="color: #000000">%</span><span style="color: #000000">2</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;number[i][j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">oddn;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;number[i][j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">even;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x1,y1;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;x</span><span style="color: #000000">&lt;=</span><span style="color: #000000">m;x</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;y</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;y</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">!</span><span style="color: #000000">ishole[x][y]&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;(x</span><span style="color: #000000">+</span><span style="color: #000000">y)</span><span style="color: #000000">%</span><span style="color: #000000">2</span><span style="color: #000000">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">4</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;x</span><span style="color: #000000">+</span><span style="color: #000000">dx[i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;y</span><span style="color: #000000">+</span><span style="color: #000000">dy[i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(x1</span><span style="color: #000000">&lt;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;x1</span><span style="color: #000000">&gt;</span><span style="color: #000000">m&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;y1</span><span style="color: #000000">&lt;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;y1</span><span style="color: #000000">&gt;</span><span style="color: #000000">n)&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(ishole[x1][y1])&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adj[number[x][y]][</span><span style="color: #000000">++</span><span style="color: #000000">adj[number[x][y]][</span><span style="color: #000000">0</span><span style="color: #000000">]]</span><span style="color: #000000">=</span><span style="color: #000000">number[x1][y1];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(oddn</span><span style="color: #000000">!=</span><span style="color: #000000">even)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br />}<br />&nbsp;&nbsp;<br /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;can(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;k){<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">adj[k][</span><span style="color: #000000">0</span><span style="color: #000000">];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">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">adj[k][i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">!</span><span style="color: #000000">used[j])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;used[j]</span><span style="color: #000000">=</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">!</span><span style="color: #000000">match[j]</span><span style="color: #000000">||</span><span style="color: #000000">can(match[j]))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;match[j]</span><span style="color: #000000">=</span><span style="color: #000000">k;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br />}<br />&nbsp;&nbsp;<br /></span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;covered(){<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;matchn</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">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">oddn;i</span><span style="color: #000000">++</span><span style="color: #000000">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(can(i))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matchn</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(used,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(used));<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(matchn</span><span style="color: #000000">*</span><span style="color: #000000">2</span><span style="color: #000000">==</span><span style="color: #000000">m</span><span style="color: #000000">*</span><span style="color: #000000">n</span><span style="color: #000000">-</span><span style="color: #000000">k)&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 />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;<br />}<br />&nbsp;&nbsp;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main(){<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(init())<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(covered())&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">YES\n</span><span style="color: #000000">"</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;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">NO\n</span><span style="color: #000000">"</span><span style="color: #000000">;<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">"</span><span style="color: #000000">NO\n</span><span style="color: #000000">"</span><span style="color: #000000">;<br />}</span></span></div>.<br /><br /></div><img src ="http://www.cppblog.com/powerwater/aggbug/159136.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/powerwater/" target="_blank">龙在江湖</a> 2011-10-26 17:06 <a href="http://www.cppblog.com/powerwater/articles/159136.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>