﻿<?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++博客-ACM博客_kuangbin</title><link>http://www.cppblog.com/kuangbin/</link><description>http://www.cnblogs.com/kuangbin/
</description><language>zh-cn</language><lastBuildDate>Tue, 14 Apr 2026 23:06:36 GMT</lastBuildDate><pubDate>Tue, 14 Apr 2026 23:06:36 GMT</pubDate><ttl>60</ttl><item><title>[导入]VK Cup 2012 Qualification Round 1    E. Phone Talks</title><link>http://www.cppblog.com/kuangbin/archive/2012/03/05/167571.html</link><dc:creator>kuangbin</dc:creator><author>kuangbin</author><pubDate>Mon, 05 Mar 2012 08:31:00 GMT</pubDate><guid>http://www.cppblog.com/kuangbin/archive/2012/03/05/167571.html</guid><wfw:comment>http://www.cppblog.com/kuangbin/comments/167571.html</wfw:comment><comments>http://www.cppblog.com/kuangbin/archive/2012/03/05/167571.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kuangbin/comments/commentRss/167571.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kuangbin/services/trackbacks/167571.html</trackback:ping><description><![CDATA[<div class="ttypography">
<div class="problem-statement">
<div class="header">
<div class="title">E. Phone Talks</div>
<div class="time-limit">
<div class="property-title">time limit per test</div>
3 seconds</div>
<div class="memory-limit">
<div class="property-title">memory limit per test</div>
256 megabytes</div>
<div class="input-file">
<div class="property-title">input</div>
standard input</div>
<div class="output-file">
<div class="property-title">output</div>
standard output</div>
</div>
<div>
<p>Cool J has recently become a businessman Mr. Jackson, and he has to make a lot of phone calls now. Today he has <span class="tex-span"><em>n</em></span> calls planned. For each call we know the moment <span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub></span> (in seconds since the start of the day) when it is scheduled to start and its duration <span class="tex-span"><em>d</em><sub class="lower-index"><em>i</em></sub></span> (in seconds). All <span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub></span> are different. Mr. Jackson is a very important person, so he never dials anybody himself, all calls will be incoming.</p>
<p>Mr. Jackson isn't Caesar and he can't do several things at once. If somebody calls him while he hasn't finished the previous conversation, Mr. Jackson puts the new call on hold in the queue. In this case immediately after the end of the current call Mr. Jackson takes the earliest incoming call from the queue and starts the conversation. If Mr. Jackson started the call at the second <span class="tex-span"><em>t</em></span>, and the call continues for <span class="tex-span"><em>d</em></span> seconds, then Mr. Jackson is busy at seconds <span class="tex-span"><em>t</em>,&thinsp;<em>t</em>&thinsp;+&thinsp;1,&thinsp;...,&thinsp;<em>t</em>&thinsp;+&thinsp;<em>d</em>&thinsp;-&thinsp;1</span>, and he can start a new call at second <span class="tex-span"><em>t</em>&thinsp;+&thinsp;<em>d</em></span>. Note that if Mr. Jackson is not busy talking when somebody calls, he can't put this call on hold.</p>
<p>Mr. Jackson isn't Napoleon either, he likes to sleep. So sometimes he allows himself the luxury of ignoring a call, as if it never was scheduled. He can ignore at most <span class="tex-span"><em>k</em></span> calls. Note that a call which comes while he is busy talking can be ignored as well.</p>
<p>What is the maximum number of seconds Mr. Jackson can sleep today, assuming that he can choose an arbitrary continuous time segment from the current day (that is, with seconds from the 1-st to the 86400-th, inclusive) when he is not busy talking?</p>
<p>Note that some calls can be continued or postponed to the next day or even later. However, the interval for sleep should be completely within the current day.</p>
</div>
<div class="input-specification">
<div class="section-title">Input</div>
<p>The first input line contains a pair of integers <span class="tex-span"><em>n</em></span>, <span class="tex-span"><em>k</em></span> (<span class="tex-span">0&thinsp;&le;&thinsp;<em>k</em>&thinsp;&le;&thinsp;<em>n</em>&thinsp;&le;&thinsp;4000</span>) separated by a space. Following <span class="tex-span"><em>n</em></span> lines contain the description of calls for today. The description of each call is located on the single line and consists of two space-separated integers <span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub></span> and <span class="tex-span"><em>d</em><sub class="lower-index"><em>i</em></sub></span>, (<span class="tex-span">1&thinsp;&le;&thinsp;<em>t</em><sub class="lower-index"><em>i</em></sub>,&thinsp;<em>d</em><sub class="lower-index"><em>i</em></sub>&thinsp;&le;&thinsp;86400</span>). All <span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub></span> are distinct, the calls are given in the order of strict increasing <span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub></span>.</p>
<p>Scheduled times of calls [<span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub></span>, <span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub>&thinsp;+&thinsp;<em>d</em><sub class="lower-index"><em>i</em></sub>&thinsp;-&thinsp;1</span>] can arbitrarily intersect.</p>
</div>
<div class="output-specification">
<div class="section-title">Output</div>
<p>Print a number from 0 to 86400, inclusive &mdash; the maximally possible number of seconds for Mr. Jackson to sleep today.</p>
</div>
<div class="sample-tests">
<div class="section-title">Sample test(s)</div>
<div class="sample-test">
<div class="input">
<div class="title">Input</div>
<pre>3 2<br />30000 15000<br />40000 15000<br />50000 15000</pre>
</div>
<div class="output">
<div class="title">Output</div>
<pre>49999</pre>
</div>
<div class="input">
<div class="title">Input</div>
<pre>5 1<br />1 20000<br />10000 10000<br />20000 20000<br />25000 10000<br />80000 60000</pre>
</div>
<div class="output">
<div class="title">Output</div>
<pre>39999</pre>
</div>
</div>
</div>
<div class="note">
<div class="section-title">Note</div>
<p>In the first sample the most convenient way is to ignore the first two calls.</p>
<p>In the second sample it is best to ignore the third call. In this case Mr. Jackson will have been speaking:</p>
<ul>
<li>first call: from 1-st to 20000-th second,</li>
<li>second call: from 20001-st to 30000-th second,</li>
<li>fourth call: from 30001-st to 40000-th second (the third call is ignored),</li>
<li>fifth call: from 80000-th to 139999-th second.</li>
</ul>
<p>&nbsp;</p>
<p>Thus, the longest period of free time is from the 40001-th to the 79999-th second.</p>
</div>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>DP；；；</p>
<div class="cnblogs_code">
<pre>#include&lt;stdio.h&gt;<br />#include&lt;iostream&gt;<br />#include&lt;<span style="color: #0000ff;">string</span>&gt;<br />#include&lt;<span style="color: #0000ff;">string</span>.h&gt;<br /><span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std;<br /><span style="color: #0000ff;">int</span> dp[<span style="color: #800080;">4005</span>][<span style="color: #800080;">4005</span>];<br /><span style="color: #0000ff;">struct</span> node<br />{<br />    <span style="color: #0000ff;">int</span> s,d;<br />};<br />node a[<span style="color: #800080;">4005</span>];<br /><span style="color: #0000ff;">int</span> main()<br />{<br />    <span style="color: #0000ff;">int</span> i,j,n,k,ans;<br />    <span style="color: #0000ff;">while</span>(scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d%d</span><span style="color: #800000;">"</span>,&amp;n,&amp;k)!=EOF)<br />    {<br />    <span style="color: #0000ff;">for</span>(i=<span style="color: #800080;">0</span>;i&lt;n;++i)<br />    {<br />        scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d%d</span><span style="color: #800000;">"</span>,&amp;a[i].s,&amp;a[i].d);<br />    }<br />     <br />     <br />     <br />    ans=<span style="color: #800080;">0</span>;<br />    <span style="color: #0000ff;">for</span>(i=<span style="color: #800080;">0</span>;i&lt;=n;++i)<br />    {<br />        <br />        <span style="color: #0000ff;">for</span>(j=<span style="color: #800080;">0</span>;j&lt;=k;++j)<br />        {<br />            dp[i][j]=<span style="color: #800080;">86401</span>;<br />        }<br />    }<br />    <br />    <br />    dp[<span style="color: #800080;">0</span>][<span style="color: #800080;">0</span>]=<span style="color: #800080;">1</span>;<br />    <span style="color: #0000ff;">for</span>(i=<span style="color: #800080;">0</span>;i&lt;n;++i)<br />    {<br />        <span style="color: #0000ff;">for</span>(j=<span style="color: #800080;">0</span>;j&lt;=k;++j)<br />        {<br />            <span style="color: #0000ff;">if</span>(j!=k)<br />                dp[i+<span style="color: #800080;">1</span>][j+<span style="color: #800080;">1</span>]=min(dp[i+<span style="color: #800080;">1</span>][j+<span style="color: #800080;">1</span>],dp[i][j]);<br />            <span style="color: #0000ff;">if</span>(dp[i][j]&lt;a[i].s)<br />            {<br />                ans=max(ans,a[i].s-dp[i][j]);<br />                dp[i+<span style="color: #800080;">1</span>][j]=min(dp[i+<span style="color: #800080;">1</span>][j],a[i].s+a[i].d);<br />            }<br />            <span style="color: #0000ff;">else</span><br />            {<br />                dp[i+<span style="color: #800080;">1</span>][j]=min(dp[i+<span style="color: #800080;">1</span>][j],dp[i][j]+a[i].d);<br />            }<br />        }<br />    }<br />    <br />    <br />    <br />    <span style="color: #0000ff;">for</span>(j=<span style="color: #800080;">0</span>;j&lt;=k;++j)<br />    {<br />        ans=max(ans,<span style="color: #800080;">86401</span>-dp[n][j]);<br />    }<br />    printf(<span style="color: #800000;">"</span><span style="color: #800000;">%d\n</span><span style="color: #800000;">"</span>,ans);<br />    }<br />    <br />    <span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span>;    <br />    <br />    <br />}</pre>
</div>
<p>&nbsp;</p>
</div><br>文章来源:<a href='http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380629.html'>http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380629.html</a><img src ="http://www.cppblog.com/kuangbin/aggbug/167571.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kuangbin/" target="_blank">kuangbin</a> 2012-03-05 16:31 <a href="http://www.cppblog.com/kuangbin/archive/2012/03/05/167571.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[导入]VK Cup 2012 Qualification Round 1   D. Ice Sculptures</title><link>http://www.cppblog.com/kuangbin/archive/2012/03/05/167572.html</link><dc:creator>kuangbin</dc:creator><author>kuangbin</author><pubDate>Mon, 05 Mar 2012 08:30:00 GMT</pubDate><guid>http://www.cppblog.com/kuangbin/archive/2012/03/05/167572.html</guid><wfw:comment>http://www.cppblog.com/kuangbin/comments/167572.html</wfw:comment><comments>http://www.cppblog.com/kuangbin/archive/2012/03/05/167572.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kuangbin/comments/commentRss/167572.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kuangbin/services/trackbacks/167572.html</trackback:ping><description><![CDATA[<div class="ttypography">
<div class="problem-statement">
<div class="header">
<div class="title">D. Ice Sculptures</div>
<div class="time-limit">
<div class="property-title">time limit per test</div>
3 seconds</div>
<div class="memory-limit">
<div class="property-title">memory limit per test</div>
256 megabytes</div>
<div class="input-file">
<div class="property-title">input</div>
standard input</div>
<div class="output-file">
<div class="property-title">output</div>
standard output</div>
</div>
<div>
<p>The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus <span class="tex-span"><em>n</em></span> ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular <span class="tex-span"><em>n</em></span>-gon. They are numbered in clockwise order with numbers from 1 to <span class="tex-span"><em>n</em></span>.</p>
<p>The site of the University has already conducted a voting that estimated each sculpture's characteristic of <span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub></span> &mdash; the degree of the sculpture's attractiveness. The values of <span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub></span> can be positive, negative or zero.</p>
<p>When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:</p>
<ul>
<li>the remaining sculptures form a regular polygon (the number of vertices should be between 3 and <span class="tex-span"><em>n</em></span>),</li>
<li>the sum of the <span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub></span> values of the remaining sculptures is maximized.</li>
</ul>
<p>&nbsp;</p>
<p>Help the Vice Rector to analyze the criticism &mdash; find the maximum value of <span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub></span> sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.</p>
</div>
<div class="input-specification">
<div class="section-title">Input</div>
<p>The first input line contains an integer <span class="tex-span"><em>n</em></span> (<span class="tex-span">3&thinsp;&le;&thinsp;<em>n</em>&thinsp;&le;&thinsp;20000</span>) &mdash; the initial number of sculptures. The second line contains a sequence of integers <span class="tex-span"><em>t</em><sub class="lower-index">1</sub>,&thinsp;<em>t</em><sub class="lower-index">2</sub>,&thinsp;...,&thinsp;<em>t</em><sub class="lower-index"><em>n</em></sub></span>, <span class="tex-span"><em>t</em><sub class="lower-index"><em>i</em></sub></span> &mdash; the degree of the <span class="tex-span"><em>i</em></span>-th sculpture's attractiveness (<span class="tex-span">&thinsp;-&thinsp;1000&thinsp;&le;&thinsp;<em>t</em><sub class="lower-index"><em>i</em></sub>&thinsp;&le;&thinsp;1000</span>). The numbers on the line are separated by spaces.</p>
</div>
<div class="output-specification">
<div class="section-title">Output</div>
<p>Print the required maximum sum of the sculptures' attractiveness.</p>
</div>
<div class="sample-tests">
<div class="section-title">Sample test(s)</div>
<div class="sample-test">
<div class="input">
<div class="title">Input</div>
<pre>8<br />1 2 -3 4 -5 5 2 3</pre>
</div>
<div class="output">
<div class="title">Output</div>
<pre>14</pre>
</div>
<div class="input">
<div class="title">Input</div>
<pre>6<br />1 -2 3 -4 5 -6</pre>
</div>
<div class="output">
<div class="title">Output</div>
<pre>9</pre>
</div>
<div class="input">
<div class="title">Input</div>
<pre>6<br />1 2 3 4 5 6</pre>
</div>
<div class="output">
<div class="title">Output</div>
<pre>21</pre>
</div>
</div>
</div>
<div class="note">
<div class="section-title">Note</div>
<p>In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.</p>
</div>
</div>
<p>&nbsp;暴力求解的。。。</p>
<p>就是等间隔取数，求其和最大值！！！</p>
<div class="cnblogs_code">
<pre>#include&lt;stdio.h&gt;<br /><span style="color: #0000ff;">int</span> aa[<span style="color: #800080;">20110</span>];<br /><br /><br /><span style="color: #0000ff;">int</span> main()<br />{<br />    <br />    <br />    <span style="color: #0000ff;">int</span> n;<br />    <span style="color: #0000ff;">int</span> res;<br />    <span style="color: #0000ff;">int</span> sum;<br />    <span style="color: #0000ff;">while</span>(scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d</span><span style="color: #800000;">"</span>,&amp;n)!=EOF)<br />    {<br />        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">1</span>;i&lt;=n;i++)<br />          scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d</span><span style="color: #800000;">"</span>,&amp;aa[i]);<br />        res=-<span style="color: #800080;">200000000</span>;<br />        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">1</span>;i&lt;=n/<span style="color: #800080;">3</span>;i++)<br />        {<br />            <span style="color: #0000ff;">if</span>(n%i!=<span style="color: #800080;">0</span>)<span style="color: #0000ff;">continue</span>;<br />            <span style="color: #0000ff;">if</span>(n/i&lt;<span style="color: #800080;">3</span>)<span style="color: #0000ff;">continue</span>;<br />            <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> j=<span style="color: #800080;">1</span>;j&lt;=i;j++)<br />            {<br />                sum=<span style="color: #800080;">0</span>;<br />                <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> k=j;k&lt;=n;k+=i)<br />                  sum+=aa[k];<br />                <span style="color: #0000ff;">if</span>(sum&gt;res) res=sum;<br />            }    <br />        }    <br />        <br />        <br />        printf(<span style="color: #800000;">"</span><span style="color: #800000;">%d\n</span><span style="color: #800000;">"</span>,res);<br />        <br />        <br />    }   <br />    <span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span>;<br />}    </pre>
</div>
<p>&nbsp;</p>
</div><br>文章来源:<a href='http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380627.html'>http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380627.html</a><img src ="http://www.cppblog.com/kuangbin/aggbug/167572.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kuangbin/" target="_blank">kuangbin</a> 2012-03-05 16:30 <a href="http://www.cppblog.com/kuangbin/archive/2012/03/05/167572.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[导入]VK Cup 2012 Qualification Round 1    B. Taxi</title><link>http://www.cppblog.com/kuangbin/archive/2012/03/05/167573.html</link><dc:creator>kuangbin</dc:creator><author>kuangbin</author><pubDate>Mon, 05 Mar 2012 08:28:00 GMT</pubDate><guid>http://www.cppblog.com/kuangbin/archive/2012/03/05/167573.html</guid><wfw:comment>http://www.cppblog.com/kuangbin/comments/167573.html</wfw:comment><comments>http://www.cppblog.com/kuangbin/archive/2012/03/05/167573.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kuangbin/comments/commentRss/167573.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kuangbin/services/trackbacks/167573.html</trackback:ping><description><![CDATA[<div class="ttypography">
<div class="problem-statement">
<div class="header">
<div class="title">B. Taxi</div>
<div class="time-limit">
<div class="property-title">time limit per test</div>
3 seconds</div>
<div class="memory-limit">
<div class="property-title">memory limit per test</div>
256 megabytes</div>
<div class="input-file">
<div class="property-title">input</div>
standard input</div>
<div class="output-file">
<div class="property-title">output</div>
standard output</div>
</div>
<div>
<p>After the lessons <span class="tex-span"><em>n</em></span> groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the <span class="tex-span"><em>i</em></span>-th group consists of <span class="tex-span"><em>s</em><sub class="lower-index"><em>i</em></sub></span> friends (<span class="tex-span">1&thinsp;&le;&thinsp;<em>s</em><sub class="lower-index"><em>i</em></sub>&thinsp;&le;&thinsp;4</span>), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?</p>
</div>
<div class="input-specification">
<div class="section-title">Input</div>
<p>The first line contains integer <span class="tex-span"><em>n</em></span> (<span class="tex-span">1&thinsp;&le;&thinsp;<em>n</em>&thinsp;&le;&thinsp;10<sup class="upper-index">5</sup></span>) &mdash; the number of groups of schoolchildren. The second line contains a sequence of integers <span class="tex-span"><em>s</em><sub class="lower-index">1</sub>,&thinsp;<em>s</em><sub class="lower-index">2</sub>,&thinsp;...,&thinsp;<em>s</em><sub class="lower-index"><em>n</em></sub></span> (<span class="tex-span">1&thinsp;&le;&thinsp;<em>s</em><sub class="lower-index"><em>i</em></sub>&thinsp;&le;&thinsp;4</span>). The integers are separated by a space, <span class="tex-span"><em>s</em><sub class="lower-index"><em>i</em></sub></span> is the number of children in the <span class="tex-span"><em>i</em></span>-th group.</p>
</div>
<div class="output-specification">
<div class="section-title">Output</div>
<p>Print the single number &mdash; the minimum number of taxis necessary to drive all children to Polycarpus.</p>
</div>
<div class="sample-tests">
<div class="section-title">Sample test(s)</div>
<div class="sample-test">
<div class="input">
<div class="title">Input</div>
<pre>5<br />1 2 4 3 3</pre>
</div>
<div class="output">
<div class="title">Output</div>
<pre>4</pre>
</div>
<div class="input">
<div class="title">Input</div>
<pre>8<br />2 3 4 4 2 1 3 1</pre>
</div>
<div class="output">
<div class="title">Output</div>
<pre>5</pre>
</div>
</div>
</div>
<div class="note">
<div class="section-title">Note</div>
<p>In the first test we can sort the children into four cars like this:</p>
<ul>
<li>the third group (consisting of four children),</li>
<li>the fourth group (consisting of three children),</li>
<li>the fifth group (consisting of three children),</li>
<li>the first and the second group (consisting of one and two children, correspondingly).</li>
</ul>
<p>&nbsp;</p>
<p>There are other ways to sort the groups into four cars.</p>
</div>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>水题，4个人的单独。</p>
<p>3和1搭配，</p>
<p>2和2搭配。</p>
<p>3有多的话只能单独了。</p>
<p>2可以加入1个的</p>
<div class="cnblogs_code">
<pre>#include&lt;stdio.h&gt;<br /><span style="color: #0000ff;">int</span> aa[<span style="color: #800080;">5</span>];<br /><br /><br /><br /><span style="color: #0000ff;">int</span> main()<br />{<br />    <br />    <br />    <br />    <span style="color: #0000ff;">int</span> n;<br />    <span style="color: #0000ff;">int</span> t;<br />    <span style="color: #0000ff;">while</span>(scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d</span><span style="color: #800000;">"</span>,&amp;n)!=EOF)<br />    {<br />        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">0</span>;i&lt;<span style="color: #800080;">5</span>;i++)aa[i]=<span style="color: #800080;">0</span>;<br />        <span style="color: #0000ff;">while</span>(n--)<br />        {<br />            scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d</span><span style="color: #800000;">"</span>,&amp;t);<br />            aa[t]++;<br />        }    <br />        <span style="color: #0000ff;">int</span> res=<span style="color: #800080;">0</span>;<br />        res+=aa[<span style="color: #800080;">4</span>];<br />        <span style="color: #0000ff;">if</span>(aa[<span style="color: #800080;">1</span>]==aa[<span style="color: #800080;">3</span>])<br />        {<br />            res+=aa[<span style="color: #800080;">1</span>];<br />            aa[<span style="color: #800080;">1</span>]=<span style="color: #800080;">0</span>;<br />            aa[<span style="color: #800080;">3</span>]=<span style="color: #800080;">0</span>;<br />            <span style="color: #0000ff;">if</span>(aa[<span style="color: #800080;">2</span>]%<span style="color: #800080;">2</span>==<span style="color: #800080;">0</span>)<br />            {<br />                res+=aa[<span style="color: #800080;">2</span>]/<span style="color: #800080;">2</span>;<br />            }    <br />            <span style="color: #0000ff;">else</span><br />            {<br />                res=res+aa[<span style="color: #800080;">2</span>]/<span style="color: #800080;">2</span>+<span style="color: #800080;">1</span>;<br />            }    <br />        }    <br />        <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span>(aa[<span style="color: #800080;">1</span>]&lt;aa[<span style="color: #800080;">3</span>])<br />        {<br />            res+=aa[<span style="color: #800080;">1</span>];<br />            aa[<span style="color: #800080;">3</span>]-=aa[<span style="color: #800080;">1</span>];<br />            aa[<span style="color: #800080;">1</span>]=<span style="color: #800080;">0</span>;<br />            <br />            res+=aa[<span style="color: #800080;">3</span>];<br />            <br />            <span style="color: #0000ff;">if</span>(aa[<span style="color: #800080;">2</span>]%<span style="color: #800080;">2</span>==<span style="color: #800080;">0</span>)<br />            {<br />                res+=aa[<span style="color: #800080;">2</span>]/<span style="color: #800080;">2</span>;<br />            }    <br />            <span style="color: #0000ff;">else</span><br />            {<br />                res=res+aa[<span style="color: #800080;">2</span>]/<span style="color: #800080;">2</span>+<span style="color: #800080;">1</span>;<br />            }  <br />        }    <br />        <span style="color: #0000ff;">else</span><br />        {<br />            res+=aa[<span style="color: #800080;">3</span>];<br />            aa[<span style="color: #800080;">1</span>]-=aa[<span style="color: #800080;">3</span>];<br />            aa[<span style="color: #800080;">3</span>]=<span style="color: #800080;">0</span>;<br />            <br />            <span style="color: #0000ff;">if</span>(aa[<span style="color: #800080;">2</span>]%<span style="color: #800080;">2</span>==<span style="color: #800080;">0</span>)<br />            {<br />                res+=aa[<span style="color: #800080;">2</span>]/<span style="color: #800080;">2</span>;<br />            }    <br />            <span style="color: #0000ff;">else</span><br />            {<br />                res=res+aa[<span style="color: #800080;">2</span>]/<span style="color: #800080;">2</span>+<span style="color: #800080;">1</span>;<br />                aa[<span style="color: #800080;">1</span>]-=<span style="color: #800080;">2</span>;<br />            }  <br />            <br />            <span style="color: #0000ff;">if</span>(aa[<span style="color: #800080;">1</span>]&gt;=<span style="color: #800080;">1</span>)<br />            {<br />                <span style="color: #0000ff;">if</span>(aa[<span style="color: #800080;">1</span>]%<span style="color: #800080;">4</span>==<span style="color: #800080;">0</span>) res+=aa[<span style="color: #800080;">1</span>]/<span style="color: #800080;">4</span>;<br />                <span style="color: #0000ff;">else</span><br />                res=res+aa[<span style="color: #800080;">1</span>]/<span style="color: #800080;">4</span>+<span style="color: #800080;">1</span>;<br />            }    <br />        }    <br />        <br />        <br />        <br />        printf(<span style="color: #800000;">"</span><span style="color: #800000;">%d\n</span><span style="color: #800000;">"</span>,res);<br />    }    <br />    <br />    <br />    <br />    <span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span>;<br />}    </pre>
</div>
<p>&nbsp;</p>
</div><br>文章来源:<a href='http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380624.html'>http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380624.html</a><img src ="http://www.cppblog.com/kuangbin/aggbug/167573.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kuangbin/" target="_blank">kuangbin</a> 2012-03-05 16:28 <a href="http://www.cppblog.com/kuangbin/archive/2012/03/05/167573.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[导入]VK Cup 2012 Qualification Round 1     A. Next Round</title><link>http://www.cppblog.com/kuangbin/archive/2012/03/05/167574.html</link><dc:creator>kuangbin</dc:creator><author>kuangbin</author><pubDate>Mon, 05 Mar 2012 08:26:00 GMT</pubDate><guid>http://www.cppblog.com/kuangbin/archive/2012/03/05/167574.html</guid><wfw:comment>http://www.cppblog.com/kuangbin/comments/167574.html</wfw:comment><comments>http://www.cppblog.com/kuangbin/archive/2012/03/05/167574.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kuangbin/comments/commentRss/167574.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kuangbin/services/trackbacks/167574.html</trackback:ping><description><![CDATA[<div class="ttypography">
<div class="problem-statement">
<div class="header">
<div class="title">A. Next Round</div>
<div class="time-limit">
<div class="property-title">time limit per test</div>
3 seconds</div>
<div class="memory-limit">
<div class="property-title">memory limit per test</div>
256 megabytes</div>
<div class="input-file">
<div class="property-title">input</div>
standard input</div>
<div class="output-file">
<div class="property-title">output</div>
standard output</div>
</div>
<div>
<p>"Contestant who earns a score equal to or greater than the <span class="tex-span"><em>k</em></span>-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." &mdash; an excerpt from contest rules.</p>
<p>A total of <span class="tex-span"><em>n</em></span> participants took part in the contest (<span class="tex-span"><em>n</em>&thinsp;&ge;&thinsp;<em>k</em></span>), and you already know their scores. Calculate how many participants will advance to the next round.</p>
</div>
<div class="input-specification">
<div class="section-title">Input</div>
<p>The first line of the input contains two integers <span class="tex-span"><em>n</em></span> and <span class="tex-span"><em>k</em></span> (<span class="tex-span">1&thinsp;&le;&thinsp;<em>k</em>&thinsp;&le;&thinsp;<em>n</em>&thinsp;&le;&thinsp;50</span>) separated by a single space.</p>
<p>The second line contains <span class="tex-span"><em>n</em></span> space-separated integers <span class="tex-span"><em>a</em><sub class="lower-index">1</sub>,&thinsp;<em>a</em><sub class="lower-index">2</sub>,&thinsp;...,&thinsp;<em>a</em><sub class="lower-index"><em>n</em></sub></span> (<span class="tex-span">0&thinsp;&le;&thinsp;<em>a</em><sub class="lower-index"><em>i</em></sub>&thinsp;&le;&thinsp;100</span>), where <span class="tex-span"><em>a</em><sub class="lower-index"><em>i</em></sub></span> is the score earned by the participant who got the <span class="tex-span"><em>i</em></span>-th place. The given sequence is non-increasing (that is, for all <span class="tex-span"><em>i</em></span> from <span class="tex-span">1</span> to <span class="tex-span"><em>n</em>&thinsp;-&thinsp;1</span> the following condition is fulfilled: <span class="tex-span"><em>a</em><sub class="lower-index"><em>i</em></sub>&thinsp;&ge;&thinsp;<em>a</em><sub class="lower-index"><em>i</em>&thinsp;+&thinsp;1</sub></span>).</p>
</div>
<div class="output-specification">
<div class="section-title">Output</div>
<p>Output the number of participants who advance to the next round.</p>
</div>
<div class="sample-tests">
<div class="section-title">Sample test(s)</div>
<div class="sample-test">
<div class="input">
<div class="title">Input</div>
<pre>8 5<br />10 9 8 7 7 7 5 5</pre>
</div>
<div class="output">
<div class="title">Output</div>
<pre>6</pre>
</div>
<div class="input">
<div class="title">Input</div>
<pre>4 2<br />0 0 0 0</pre>
</div>
<div class="output">
<div class="title">Output</div>
<pre>0</pre>
</div>
</div>
</div>
<div class="note">
<div class="section-title">Note</div>
<p>In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.</p>
<p>In the second example nobody got a positive score.</p>
</div>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>很简单的题目~~~~~</p>
<div class="cnblogs_code">
<pre>#include&lt;stdio.h&gt;<br /><span style="color: #0000ff;">int</span> mm[<span style="color: #800080;">120</span>];<br /><span style="color: #0000ff;">int</span> main()<br />{<br />    <br />    <br />    <span style="color: #0000ff;">int</span> n,k;<br />    <br />    <br />    <span style="color: #0000ff;">while</span>(scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d%d</span><span style="color: #800000;">"</span>,&amp;n,&amp;k)!=EOF)<br />    {<br />        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">1</span>;i&lt;=n;i++)<br />          scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d</span><span style="color: #800000;">"</span>,&amp;mm[i]);<br />        <span style="color: #0000ff;">int</span> res=k;<br />        <span style="color: #0000ff;">if</span>(mm[k]&gt;<span style="color: #800080;">0</span>)<br />        {<br />            <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=k+<span style="color: #800080;">1</span>;i&lt;=n;i++)<br />            {<br />                <span style="color: #0000ff;">if</span>(mm[i]&lt;mm[k])<span style="color: #0000ff;">break</span>;<br />                res++;<br />            }    <br />        }  <br />        <span style="color: #0000ff;">else</span><br />        {<br />            res--;<br />            <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=k-<span style="color: #800080;">1</span>;i&gt;=<span style="color: #800080;">1</span>;i--)<br />            {<br />                <span style="color: #0000ff;">if</span>(mm[i]&gt;<span style="color: #800080;">0</span>) <span style="color: #0000ff;">break</span>;<br />                res--;<br />            }    <br />        } <br />        <br />        printf(<span style="color: #800000;">"</span><span style="color: #800000;">%d\n</span><span style="color: #800000;">"</span>,res);     <br />    }    <br />    <br />    <br />    <span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span>;<br />}    </pre>
</div>
<p>&nbsp;</p>
</div><br>文章来源:<a href='http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380621.html'>http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380621.html</a><img src ="http://www.cppblog.com/kuangbin/aggbug/167574.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kuangbin/" target="_blank">kuangbin</a> 2012-03-05 16:26 <a href="http://www.cppblog.com/kuangbin/archive/2012/03/05/167574.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[导入]迎接2012新赛季——HDOJ系列热身赛（2）  Problem E  HDU4165 Pills</title><link>http://www.cppblog.com/kuangbin/archive/2012/03/03/167575.html</link><dc:creator>kuangbin</dc:creator><author>kuangbin</author><pubDate>Sat, 03 Mar 2012 05:25:00 GMT</pubDate><guid>http://www.cppblog.com/kuangbin/archive/2012/03/03/167575.html</guid><wfw:comment>http://www.cppblog.com/kuangbin/comments/167575.html</wfw:comment><comments>http://www.cppblog.com/kuangbin/archive/2012/03/03/167575.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kuangbin/comments/commentRss/167575.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kuangbin/services/trackbacks/167575.html</trackback:ping><description><![CDATA[<p>&nbsp;</p>
<h1 style="margin-top: 20px; color: #1a5cc8;">Problem E</h1>
<p><span style="font-family: Arial;"><strong><span style="color: green; font-size: 12px;">Time Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)<br />Total Submission(s): 0&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 0<br /></span></strong></span><br /><br /></p>
<div class="panel_title" align="left">Problem Description</div>
<div class="panel_content">
<div style="width: 940px; font-family: Courier New,Courier,monospace; word-wrap: break-word; white-space: pre-wrap;">Aunt Lizzie takes half a pill of a certain medicine every day. She starts with a bottle that contains N pills.<br /><br />On the first day, she removes a random pill, breaks it in two halves, takes one half and puts the other half back into the bottle.<br /><br />On subsequent days, she removes a random piece (which can be either a whole pill or half a pill) from the bottle. If it is half a pill, she takes it. If it is a whole pill, she takes one half and puts the other half back into the bottle.<br /><br />In how many ways can she empty the bottle? We represent the sequence of pills removed from the bottle in the course of 2N days as a string, where the i-th character is W if a whole pill was chosen on the i-th day, and H if a half pill was chosen (0 &lt;= i &lt; 2N). How many different valid strings are there that empty the bottle?</div>
</div>
<div class="panel_bottom">&nbsp;</div>
<p>&nbsp;</p>
<div class="panel_title" align="left">Input</div>
<div class="panel_content">
<div style="width: 940px; font-family: Courier New,Courier,monospace; word-wrap: break-word; white-space: pre-wrap;">The input will contain data for at most 1000 problem instances. For each problem instance there will be one line of input: a positive integer N &lt;= 30, the number of pills initially in the bottle. End of input will be indicated by 0.</div>
</div>
<div class="panel_bottom">&nbsp;</div>
<p>&nbsp;</p>
<div class="panel_title" align="left">Output</div>
<div class="panel_content">
<div style="width: 940px; font-family: Courier New,Courier,monospace; word-wrap: break-word; white-space: pre-wrap;">For each problem instance, the output will be a single number, displayed at the beginning of a new line. It will be the number of different ways the bottle can be emptied.</div>
</div>
<div class="panel_bottom">&nbsp;</div>
<p>&nbsp;</p>
<div class="panel_title" align="left">Sample Input</div>
<div class="panel_content">
<div style="width: 940px; font-family: Courier New,Courier,monospace; word-wrap: break-word; white-space: pre-wrap;">6 1 4 2 3 30 0</div>
</div>
<div class="panel_bottom">&nbsp;</div>
<p>&nbsp;</p>
<div class="panel_title" align="left">Sample Output</div>
<div class="panel_content">
<div style="width: 940px; font-family: Courier New,Courier,monospace; word-wrap: break-word; white-space: pre-wrap;">132 1 14 2 5 3814986502092304</div>
</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom">相当于求N个W，和N个H的排列数，而且要求前面任意个中必需H的个数不大于W的个数~~~~</div>
<div class="panel_bottom">不知道哪些大神是怎么样做出来的，好快的速度就做出来了~~~~</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom">我想了好久都没有想到DP的方法，</div>
<div class="panel_bottom">最后想出来了，感觉方法比较笨~~~~</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom"><img src="http://pic002.cnblogs.com/images/2012/303230/2012030313202091.png" alt="" /></div>
<div class="panel_bottom">转化成了图，W表示往下走，H表是往右走，</div>
<div class="panel_bottom">则必须在左下角中。</div>
<div class="panel_bottom">N个W和H的时候就是到N-1行的路径数</div>
<div class="panel_bottom">如N=1时，为dp[0,0]</div>
<div class="panel_bottom">N=2时为dp[1,0]+dp[1,1]</div>
<div class="panel_bottom">N=3时为dp[2,0]+dp[2,1]+dp[2,2]</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom">应该会有更好的方法的~~~~~</div>
<div class="panel_bottom">我的思路有点蹉了~~~~但幸好做出来了！</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom">代码如下：</div>
<div class="panel_bottom">
<div class="cnblogs_code">
<pre>#include&lt;stdio.h&gt;<br /><span style="color: #0000ff;">long</span> <span style="color: #0000ff;">long</span> dp[<span style="color: #800080;">31</span>][<span style="color: #800080;">31</span>];<br /><span style="color: #0000ff;">void</span> init()<br />{<br />    dp[<span style="color: #800080;">0</span>][<span style="color: #800080;">0</span>]=<span style="color: #800080;">1</span>;<br />    <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">1</span>;i&lt;<span style="color: #800080;">31</span>;i++)<br />    {<br />        dp[i][<span style="color: #800080;">0</span>]=<span style="color: #800080;">1</span>;<br />        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> j=<span style="color: #800080;">1</span>;j&lt;i;j++)<br />          dp[i][j]=dp[i-<span style="color: #800080;">1</span>][j]+dp[i][j-<span style="color: #800080;">1</span>];<br />        dp[i][i]=dp[i][i-<span style="color: #800080;">1</span>];<br />    }   <br />} <br /><span style="color: #0000ff;">int</span> main()<br />{<br />    <span style="color: #0000ff;">int</span> N;<br />    init();<br />    <span style="color: #0000ff;">while</span>(scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d</span><span style="color: #800000;">"</span>,&amp;N),N)<br />    {<br />        printf(<span style="color: #800000;">"</span><span style="color: #800000;">%I64d\n</span><span style="color: #800000;">"</span>,dp[N][N]);<br />    }    <br />    <span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span>;<br />}       </pre>
</div>
要求的其实就是从（0，0）到(N,N)的路径数，只能往下或者往右走，而且不能走到右上部分去。</div><br>文章来源:<a href='http://www.cnblogs.com/kuangbin/archive/2012/03/03/2378248.html'>http://www.cnblogs.com/kuangbin/archive/2012/03/03/2378248.html</a><img src ="http://www.cppblog.com/kuangbin/aggbug/167575.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kuangbin/" target="_blank">kuangbin</a> 2012-03-03 13:25 <a href="http://www.cppblog.com/kuangbin/archive/2012/03/03/167575.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[导入]迎接2012新赛季——HDOJ系列热身赛（2） Problem A HDU 4161  Iterated Difference</title><link>http://www.cppblog.com/kuangbin/archive/2012/03/03/167576.html</link><dc:creator>kuangbin</dc:creator><author>kuangbin</author><pubDate>Sat, 03 Mar 2012 05:11:00 GMT</pubDate><guid>http://www.cppblog.com/kuangbin/archive/2012/03/03/167576.html</guid><wfw:comment>http://www.cppblog.com/kuangbin/comments/167576.html</wfw:comment><comments>http://www.cppblog.com/kuangbin/archive/2012/03/03/167576.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kuangbin/comments/commentRss/167576.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kuangbin/services/trackbacks/167576.html</trackback:ping><description><![CDATA[<h1 style="margin-top: 20px; color: #1a5cc8;">Problem A</h1>
<p><span style="font-family: Arial;"><strong><span style="color: green; font-size: 12px;">Time Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)<br />Total Submission(s): 0&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 0<br /></span></strong></span><br /><br /></p>
<div class="panel_title" align="left">Problem Description</div>
<div class="panel_content">
<div style="width: 940px; font-family: Courier New,Courier,monospace; word-wrap: break-word; white-space: pre-wrap;">You are given a list of N non-negative integers a(1), a(2), ... , a(N). You replace the given list by a new list: the k-th entry of the new list is the absolute value of a(k) - a(k+1), wrapping around at the end of the list (the k-th entry of the new list is the absolute value of a(N) - a(1)). How many iterations of this replacement are needed to arrive at a list in which every entry is the same integer?<br /><br />For example, let N = 4 and start with the list (0 2 5 11). The successive iterations are:<br /><br />2 3 6 11<br />1 3 5 9<br />2 2 4 8<br />0 2 4 6<br />2 2 2 6<br />0 0 4 4<br />0 4 0 4<br />4 4 4 4<br />Thus, 8 iterations are needed in this example.</div>
</div>
<div class="panel_bottom">&nbsp;</div>
<p>&nbsp;</p>
<div class="panel_title" align="left">Input</div>
<div class="panel_content">
<div style="width: 940px; font-family: Courier New,Courier,monospace; word-wrap: break-word; white-space: pre-wrap;">The input will contain data for a number of test cases. For each case, there will be two lines of input. The first line will contain the integer N (2 &lt;= N &lt;= 20), the number of entries in the list. The second line will contain the list of integers, separated by one blank space. End of input will be indicated by N = 0.</div>
</div>
<div class="panel_bottom">&nbsp;</div>
<p>&nbsp;</p>
<div class="panel_title" align="left">Output</div>
<div class="panel_content">
<div style="width: 940px; font-family: Courier New,Courier,monospace; word-wrap: break-word; white-space: pre-wrap;">For each case, there will be one line of output, specifying the case number and the number of iterations, in the format shown in the sample output. If the list does not attain the desired form after 1000 iterations, print 'not attained'.</div>
</div>
<div class="panel_bottom">&nbsp;</div>
<p>&nbsp;</p>
<div class="panel_title" align="left">Sample Input</div>
<div class="panel_content">
<div style="width: 940px; font-family: Courier New,Courier,monospace; word-wrap: break-word; white-space: pre-wrap;">4 0 2 5 11 5 0 2 5 11 3 4 300 8600 9000 4000 16 12 20 3 7 8 10 44 50 12 200 300 7 8 10 44 50 3 1 1 1 4 0 4 0 4 0</div>
</div>
<div class="panel_bottom">&nbsp;</div>
<p>&nbsp;</p>
<div class="panel_title" align="left">Sample Output</div>
<div class="panel_content">
<div style="width: 940px; font-family: Courier New,Courier,monospace; word-wrap: break-word; white-space: pre-wrap;">Case 1: 8 iterations Case 2: not attained Case 3: 3 iterations Case 4: 50 iterations Case 5: 0 iterations Case 6: 1 iterations</div>
</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_bottom">水题~~~~~</div>
<div class="panel_bottom">迭代就可以了！</div>
<div class="panel_bottom">
<div class="cnblogs_code">
<pre>#include&lt;stdio.h&gt;<br />#include&lt;math.h&gt;<br />#include&lt;iostream&gt;<br /><span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std;<br /><span style="color: #0000ff;">int</span> a[<span style="color: #800080;">50</span>];<br /><span style="color: #0000ff;">int</span> main()<br />{<br />    <span style="color: #0000ff;">int</span> N,res,j;<br />    <span style="color: #0000ff;">int</span> iCase=<span style="color: #800080;">0</span>;<br />    <span style="color: #0000ff;">while</span>(scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d</span><span style="color: #800000;">"</span>,&amp;N),N)<br />    {<br />        iCase++;<br />        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">0</span>;i&lt;N;i++)<br />        {<br />            scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d</span><span style="color: #800000;">"</span>,&amp;a[i]);<br />        }   <br />       <span style="color: #0000ff;">for</span>(j=<span style="color: #800080;">0</span>;j&lt;N-<span style="color: #800080;">1</span>;j++)<br />            {<br />                <span style="color: #0000ff;">if</span>(a[j]!=a[j+<span style="color: #800080;">1</span>])<span style="color: #0000ff;">break</span>;<br />            }  <br />       <span style="color: #0000ff;">if</span>(j&gt;=N-<span style="color: #800080;">1</span>)<br />       {<br />           printf(<span style="color: #800000;">"</span><span style="color: #800000;">Case %d: 0 iterations\n</span><span style="color: #800000;">"</span>,iCase);<br />           <span style="color: #0000ff;">continue</span>;<br />           <br />       }    <br />        <span style="color: #0000ff;">for</span>(res=<span style="color: #800080;">1</span>;res&lt;=<span style="color: #800080;">1000</span>;res++)<br />        {<br />            a[N]=a[<span style="color: #800080;">0</span>];<br />            <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">0</span>;i&lt;N;i++)<br />            {<br />                a[i]=abs(a[i]-a[i+<span style="color: #800080;">1</span>]);<br />            } <br />            <span style="color: #0000ff;">for</span>(j=<span style="color: #800080;">0</span>;j&lt;N-<span style="color: #800080;">1</span>;j++)<br />            {<br />                <span style="color: #0000ff;">if</span>(a[j]!=a[j+<span style="color: #800080;">1</span>])<span style="color: #0000ff;">break</span>;<br />            }  <br />            <span style="color: #0000ff;">if</span>(j&gt;=N-<span style="color: #800080;">1</span>)<span style="color: #0000ff;">break</span>;     <br />        }   <br />        <span style="color: #0000ff;">if</span>(res&lt;=<span style="color: #800080;">1000</span>)printf(<span style="color: #800000;">"</span><span style="color: #800000;">Case %d: %d iterations\n</span><span style="color: #800000;">"</span>,iCase,res);<br />        <span style="color: #0000ff;">else</span> printf(<span style="color: #800000;">"</span><span style="color: #800000;">Case %d: not attained\n</span><span style="color: #800000;">"</span>,iCase);  <br />    }    <br />    <span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span>;<br />}    </pre>
</div>
</div><br>文章来源:<a href='http://www.cnblogs.com/kuangbin/archive/2012/03/03/2378235.html'>http://www.cnblogs.com/kuangbin/archive/2012/03/03/2378235.html</a><img src ="http://www.cppblog.com/kuangbin/aggbug/167576.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kuangbin/" target="_blank">kuangbin</a> 2012-03-03 13:11 <a href="http://www.cppblog.com/kuangbin/archive/2012/03/03/167576.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[导入]店长推荐Ⅱ~~~~</title><link>http://www.cppblog.com/kuangbin/archive/2012/02/27/167577.html</link><dc:creator>kuangbin</dc:creator><author>kuangbin</author><pubDate>Mon, 27 Feb 2012 12:03:00 GMT</pubDate><guid>http://www.cppblog.com/kuangbin/archive/2012/02/27/167577.html</guid><wfw:comment>http://www.cppblog.com/kuangbin/comments/167577.html</wfw:comment><comments>http://www.cppblog.com/kuangbin/archive/2012/02/27/167577.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kuangbin/comments/commentRss/167577.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kuangbin/services/trackbacks/167577.html</trackback:ping><description><![CDATA[<table class="problem_mod">
<tbody>
<tr>
<td class="problem_mod_name">店长推荐Ⅱ</td>
</tr>
<tr>
<td>
<table class="problem_mod_info">
<tbody>
<tr>
<td>Time Limit: 1000 MS</td>
<td>Memory Limit: 65536 K</td>
</tr>
</tbody>
</table>
<table class="problem_mod_info">
<tbody>
<tr>
<td>Total Submit: 97<span class="problem_mod_info_user">(31 users)</span></td>
<td>Total Accepted: 28<span class="problem_mod_info_user">(24 users)</span></td>
<td>Special Judge: <span class="problem_mod_info_sj_no">No</span></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="problem_mod_title">Description</td>
</tr>
<tr>
<td class="problem_mod_content">
<p>想必大家已经领略了店长的调皮,自从店长知道了vagaa之后就一直沉迷期中不能自拔,教主看到后很是伤心，玩物丧志啊!于是教主教店长了一个vagaa的新用法,资源搜索功能。输入一些关键词后可以搜索出相关共享的好资源，店长得知后又是欣喜若狂。同时,教主又发明一个游戏，是上次的升级版,这次给出一些由字母和数字的玩具的同时，关键字不再是vagaa了，需要自己给出.看最后能组成多少个关键字。</p>
</td>
</tr>
<tr>
<td class="problem_mod_title">Input</td>
</tr>
<tr>
<td class="problem_mod_content">
<p>每行输入一个字符串由小写字母和数字组成，每个字符代表一个玩具, 紧接着输入一个关键字，同样由字母和数字组组成，字符串长度0&lt;n&lt;=10000，关键字长度0&lt;m&lt;=200</p>
<p>处理到文件结束</p>
</td>
</tr>
<tr>
<td class="problem_mod_title">Output</td>
</tr>
<tr>
<td class="problem_mod_content">
<p>输出能够组成关键字的数量</p>
<p>按照样例输出格式输出并换行.</p>
</td>
</tr>
<tr>
<td class="problem_mod_title">Sample Input</td>
</tr>
<tr>
<td class="problem_mod_content">
<p>vagaadsfaagav&nbsp; ga<br />asgvasdfzxcades&nbsp; dea</p>
</td>
</tr>
<tr>
<td class="problem_mod_title">Sample Output</td>
</tr>
<tr>
<td class="problem_mod_content">
<p>Case 1: 2<br />Case 2: 1</p>
</td>
</tr>
<tr>
<td class="problem_mod_title">Author</td>
</tr>
<tr>
<td class="problem_mod_content">void</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<div class="cnblogs_code">
<pre>#include&lt;stdio.h&gt;<br />#include&lt;<span style="color: #0000ff;">string</span>.h&gt;<br /><span style="color: #0000ff;">int</span> tt[<span style="color: #800080;">40</span>],count[<span style="color: #800080;">40</span>];<br /><span style="color: #0000ff;">char</span> str[<span style="color: #800080;">10010</span>];<br /><span style="color: #0000ff;">int</span> main()<br />{<br />    <span style="color: #0000ff;">int</span> len,m;<br />    <span style="color: #0000ff;">int</span> iCase=<span style="color: #800080;">0</span>;<br />    <span style="color: #0000ff;">while</span>(scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%s</span><span style="color: #800000;">"</span>,&amp;str)!=EOF)<br />    {<br />        iCase++;<br />        len=strlen(str);<br />        memset(tt,<span style="color: #800080;">0</span>,<span style="color: #0000ff;">sizeof</span>(tt));<br />        memset(count,<span style="color: #800080;">0</span>,<span style="color: #0000ff;">sizeof</span>(count));<br />        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">0</span>;i&lt;len;i++)<br />        {<br />            <span style="color: #0000ff;">if</span>(str[i]&gt;=<span style="color: #800000;">'</span><span style="color: #800000;">0</span><span style="color: #800000;">'</span>&amp;&amp;str[i]&lt;=<span style="color: #800000;">'</span><span style="color: #800000;">9</span><span style="color: #800000;">'</span>)<br />            {<br />                m=str[i]-<span style="color: #800000;">'</span><span style="color: #800000;">0</span><span style="color: #800000;">'</span>+<span style="color: #800080;">0</span>;<br />                tt[m]++;<br />                <br />            }    <br />            <span style="color: #0000ff;">else</span><br />            {<br />                m=str[i]-<span style="color: #800000;">'</span><span style="color: #800000;">a</span><span style="color: #800000;">'</span>+<span style="color: #800080;">10</span>;<br />                tt[m]++;<br />            }    <br />        }  <br />        scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%s</span><span style="color: #800000;">"</span>,&amp;str);<br />        len=strlen(str);<br />        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">0</span>;i&lt;len;i++)<br />        {<br />            <span style="color: #0000ff;">if</span>(str[i]&gt;=<span style="color: #800000;">'</span><span style="color: #800000;">0</span><span style="color: #800000;">'</span>&amp;&amp;str[i]&lt;=<span style="color: #800000;">'</span><span style="color: #800000;">9</span><span style="color: #800000;">'</span>)<br />            {<br />                m=str[i]-<span style="color: #800000;">'</span><span style="color: #800000;">0</span><span style="color: #800000;">'</span>+<span style="color: #800080;">0</span>;<br />                count[m]++;<br />                <br />            }    <br />            <span style="color: #0000ff;">else</span><br />            {<br />                m=str[i]-<span style="color: #800000;">'</span><span style="color: #800000;">a</span><span style="color: #800000;">'</span>+<span style="color: #800080;">10</span>;<br />                count[m]++;<br />            }    <br />        }    <br />        <span style="color: #0000ff;">int</span> res=<span style="color: #800080;">10000</span>;<br />        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">0</span>;i&lt;=<span style="color: #800080;">9</span>+<span style="color: #800080;">26</span>;i++)<br />        {<br />            <span style="color: #0000ff;">if</span>(count[i]&gt;<span style="color: #800080;">0</span>)<br />            {<br />                <span style="color: #0000ff;">int</span> tmp=tt[i]/count[i];<br />                <span style="color: #0000ff;">if</span>(tmp&lt;res) res=tmp;<br />            }    <br />        }    <br />        printf(<span style="color: #800000;">"</span><span style="color: #800000;">Case %d: %d\n</span><span style="color: #800000;">"</span>,iCase,res);<br />    }    <br />    <span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span>;<br />}    </pre>
</div>
<p>&nbsp;</p><br>文章来源:<a href='http://www.cnblogs.com/kuangbin/archive/2012/02/27/2370325.html'>http://www.cnblogs.com/kuangbin/archive/2012/02/27/2370325.html</a><img src ="http://www.cppblog.com/kuangbin/aggbug/167577.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kuangbin/" target="_blank">kuangbin</a> 2012-02-27 20:03 <a href="http://www.cppblog.com/kuangbin/archive/2012/02/27/167577.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[导入]青蛙过河~~~~</title><link>http://www.cppblog.com/kuangbin/archive/2012/02/27/167578.html</link><dc:creator>kuangbin</dc:creator><author>kuangbin</author><pubDate>Mon, 27 Feb 2012 07:16:00 GMT</pubDate><guid>http://www.cppblog.com/kuangbin/archive/2012/02/27/167578.html</guid><wfw:comment>http://www.cppblog.com/kuangbin/comments/167578.html</wfw:comment><comments>http://www.cppblog.com/kuangbin/archive/2012/02/27/167578.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kuangbin/comments/commentRss/167578.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kuangbin/services/trackbacks/167578.html</trackback:ping><description><![CDATA[<table class="problem_mod">
<tbody>
<tr>
<td class="problem_mod_name">青蛙过河</td>
</tr>
<tr>
<td>
<table class="problem_mod_info">
<tbody>
<tr>
<td>Time Limit: 1000 MS</td>
<td>Memory Limit: 65535 K</td>
</tr>
</tbody>
</table>
<table class="problem_mod_info">
<tbody>
<tr>
<td>Total Submit: 29<span class="problem_mod_info_user">(11 users)</span></td>
<td>Total Accepted: 9<span class="problem_mod_info_user">(9 users)</span></td>
<td>Special Judge: <span class="problem_mod_info_sj_no">No</span></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="problem_mod_title">Description</td>
</tr>
<tr>
<td class="problem_mod_content"><span style="white-space: normal;">在河上有一座独木桥，一只青蛙想沿着独木桥从河的一侧跳到另一侧。在桥上有一些石子，青蛙很讨厌踩在这些石子上。由于桥的长度和青蛙一次跳过的距离都是正整数，我们可以把独木桥上青蛙可能到达的点看成数轴上的一串整点：0，1，&hellip;&hellip;，L（其中L是桥的长度）。坐标为0的点表示桥的起点，坐标为L的点表示桥的终点。青蛙从桥的起点开始，不停的向终点方向跳跃。一次跳跃的距离是s到t之间的任意正整数（包括s,t）。<span style="color: #e53333;">当青蛙跳到或跳过坐标为L的点时，就算青蛙已经跳出了独木桥。</span></span><br style="white-space: normal;" /><span style="white-space: normal;"><br /></span><br style="white-space: normal;" /><span style="white-space: normal;">题目给出独木桥的长度L，青蛙跳跃的距离范围s,t，桥上石子的位置。你的任务是确定青蛙要想过河，最少需要踩到的石子数。</span></td>
</tr>
<tr>
<td class="problem_mod_title">Input</td>
</tr>
<tr>
<td class="problem_mod_content"><span style="white-space: normal;">有多组测试数据。</span><br style="white-space: normal;" /><span style="white-space: normal;">对于每组测试数据，第一行四个正整数L, s, t, n（1 &lt;= L &lt;= 10^5, 1 &lt;= s &lt;= t &lt;= 10，1 &lt;= n &lt;= 100），分别表示独木桥的长度，青蛙一次跳跃的最小距离，最大距离，及桥上石子的个数。第二行有n个不同的正整数分别表示这n个石子在数轴上的位置（数据保证桥的起点和终点处没有石子）。所有相邻的整数之间用一个空格隔开。</span></td>
</tr>
<tr>
<td class="problem_mod_title">Output</td>
</tr>
<tr>
<td class="problem_mod_content"><span style="white-space: normal;">每组测试数据仅输出一行，包括一个整数，表示青蛙过河最少需要踩到的石子数。</span></td>
</tr>
<tr>
<td class="problem_mod_title">Sample Input</td>
</tr>
<tr>
<td class="problem_mod_content"><span style="white-space: normal;">10 2 3 5</span><br style="white-space: normal;" /><span style="white-space: normal;">2 3 5 6 7</span></td>
</tr>
<tr>
<td class="problem_mod_title">Sample Output</td>
</tr>
<tr>
<td class="problem_mod_content">
<p>2</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<div class="cnblogs_code">
<pre>#include&lt;stdio.h&gt;<br />#include&lt;<span style="color: #0000ff;">string</span>.h&gt;<br /><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> MAXN=<span style="color: #800080;">100020</span>;<br /><span style="color: #0000ff;">int</span> flag[MAXN];<br /><span style="color: #0000ff;">int</span> dp[MAXN];<br /><span style="color: #0000ff;">int</span> main()<br />{<br />    <span style="color: #0000ff;">int</span> L,s,t,n;<br />    <span style="color: #0000ff;">int</span> a;<br />    <span style="color: #0000ff;">while</span>(scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d%d%d%d</span><span style="color: #800000;">"</span>,&amp;L,&amp;s,&amp;t,&amp;n)!=EOF)<br />    {<br />        memset(flag,<span style="color: #800080;">0</span>,<span style="color: #0000ff;">sizeof</span>(flag));<br />        memset(dp,-<span style="color: #800080;">1</span>,<span style="color: #0000ff;">sizeof</span>(dp));<span style="color: #008000;">//</span><span style="color: #008000;">初始化，-1为不能到达的 <br />        </span><span style="color: #008000;">//</span><span style="color: #008000;">dp[i]表示到底 i  点需要经过的最少石子数，-1表示不能到达 </span><span style="color: #008000;"><br /></span>        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">0</span>;i&lt;n;i++)<br />        {<br />            scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d</span><span style="color: #800000;">"</span>,&amp;a);<br />            flag[a]=<span style="color: #800080;">1</span>;<span style="color: #008000;">//</span><span style="color: #008000;">有石子为1，否则为0 </span><span style="color: #008000;"><br /></span>        }    <br />        dp[<span style="color: #800080;">0</span>]=<span style="color: #800080;">0</span>;<br />        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=s;i&lt;=L+t-<span style="color: #800080;">1</span>;i++)<br />        {<br />            <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> j=i-t;j&lt;=i-s;j++)<span style="color: #008000;">//</span><span style="color: #008000;"> j 点跳到 i 点 </span><span style="color: #008000;"><br /></span>            {<br />                <span style="color: #0000ff;">if</span>(j&gt;=<span style="color: #800080;">0</span>&amp;&amp;dp[j]!=-<span style="color: #800080;">1</span>)<span style="color: #008000;">//</span><span style="color: #008000;">j 点能够跳到 </span><span style="color: #008000;"><br /></span>                {<br />                    <span style="color: #0000ff;">if</span>(dp[i]==-<span style="color: #800080;">1</span>)dp[i]=dp[j]+flag[i]; <span style="color: #008000;">//</span><span style="color: #008000;">第一次 直 接 给 值 </span><span style="color: #008000;"><br /></span>                    <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span>(dp[i]&gt;dp[j]+flag[i]) dp[i]=dp[j]+flag[i];<span style="color: #008000;">//</span><span style="color: #008000;">找小的值 </span><span style="color: #008000;"><br /></span>                    <br />                }    <br />            }    <br />        }  <br />        <span style="color: #0000ff;">int</span> res=<span style="color: #800080;">10000</span>;<br />        <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=L;i&lt;=L+t-<span style="color: #800080;">1</span>;i++)<span style="color: #008000;">//</span><span style="color: #008000;">L 到 L+t-1 中最小的非 -1 值 </span><span style="color: #008000;"><br /></span>        {<br />            <span style="color: #0000ff;">if</span>(dp[i]!=-<span style="color: #800080;">1</span>&amp;&amp;dp[i]&lt;res) res=dp[i];<br />        }      <br />        printf(<span style="color: #800000;">"</span><span style="color: #800000;">%d\n</span><span style="color: #800000;">"</span>,res);<br />    }    <br />    <span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span>;<br />}    </pre>
</div>
<p>&nbsp;</p>
</td>
</tr>
</tbody>
</table><br>文章来源:<a href='http://www.cnblogs.com/kuangbin/archive/2012/02/27/2369901.html'>http://www.cnblogs.com/kuangbin/archive/2012/02/27/2369901.html</a><img src ="http://www.cppblog.com/kuangbin/aggbug/167578.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kuangbin/" target="_blank">kuangbin</a> 2012-02-27 15:16 <a href="http://www.cppblog.com/kuangbin/archive/2012/02/27/167578.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[导入]告别2011，迎接2012</title><link>http://www.cppblog.com/kuangbin/archive/2012/01/03/167579.html</link><dc:creator>kuangbin</dc:creator><author>kuangbin</author><pubDate>Mon, 02 Jan 2012 16:18:00 GMT</pubDate><guid>http://www.cppblog.com/kuangbin/archive/2012/01/03/167579.html</guid><wfw:comment>http://www.cppblog.com/kuangbin/comments/167579.html</wfw:comment><comments>http://www.cppblog.com/kuangbin/archive/2012/01/03/167579.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kuangbin/comments/commentRss/167579.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kuangbin/services/trackbacks/167579.html</trackback:ping><description><![CDATA[<p><strong><span style="font-size: 15px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2011已经逝去，2012已经到来~~~~</span></strong></p>
<p><strong><span style="font-size: 15px;">2011年，总感觉自己得到了很多，也失去了很多，也留下不尽的遗憾。仍记得2011年到来的时候，我自己对自己说这一年将会是我关键的一年，给自己定下了很多目标~~~~这些目标只能说是大致实现了吧，也很多遗憾！</span></strong></p>
<p><strong><span style="font-size: 15px;">为了迎接2012年，总感觉自己应该写点东西，来总结自己的2011，规划下2012.但是一直抽不出时间来写。等有时间了再写一篇来总结2011吧！</span></strong></p>
<p><strong><span style="font-size: 15px;">人生应该处于不断的奋斗当中！2012年，我要取得成功！2012年，我一定会做得更好！</span></strong></p>
<p><strong><span style="font-size: 15px;">加油！</span></strong></p>
<p><strong><span style="font-size: 15px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;by kuangbin</span></strong></p><br>文章来源:<a href='http://www.cnblogs.com/kuangbin/archive/2012/01/03/2310575.html'>http://www.cnblogs.com/kuangbin/archive/2012/01/03/2310575.html</a><img src ="http://www.cppblog.com/kuangbin/aggbug/167579.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kuangbin/" target="_blank">kuangbin</a> 2012-01-03 00:18 <a href="http://www.cppblog.com/kuangbin/archive/2012/01/03/167579.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[导入]HDU 1006 Tick and Tick</title><link>http://www.cppblog.com/kuangbin/archive/2011/12/04/167580.html</link><dc:creator>kuangbin</dc:creator><author>kuangbin</author><pubDate>Sun, 04 Dec 2011 07:17:00 GMT</pubDate><guid>http://www.cppblog.com/kuangbin/archive/2011/12/04/167580.html</guid><wfw:comment>http://www.cppblog.com/kuangbin/comments/167580.html</wfw:comment><comments>http://www.cppblog.com/kuangbin/archive/2011/12/04/167580.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kuangbin/comments/commentRss/167580.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kuangbin/services/trackbacks/167580.html</trackback:ping><description><![CDATA[<p>题目链接：<a href="http://acm.hdu.edu.cn/showproblem.php?pid=1006">http://acm.hdu.edu.cn/showproblem.php?pid=1006</a></p>
<p>&nbsp;</p>
<p>这题做了好久了，学习了网上的解法后自己写出来了。</p>
<p>就是枚举12*60分钟，看一分钟内有多少秒是happytime，一分钟内解三个不等式得到区间。</p>
<p>具体看代码。</p>
<p>代码有注释很详细的。</p>
<div class="cnblogs_code">
<pre>#include&lt;stdio.h&gt;<br />#include&lt;math.h&gt;<br />#include&lt;iostream&gt;<br />#include&lt;algorithm&gt;<br /><span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std;<br /><span style="color: #0000ff;">struct</span> qujian<br />{<br />    <span style="color: #0000ff;">double</span> l,r;<br />};    <br /><span style="color: #0000ff;">double</span> D;<br />qujian solve(<span style="color: #0000ff;">double</span> a,<span style="color: #0000ff;">double</span> b)<span style="color: #008000;">//</span><span style="color: #008000;">解方程 D&lt;=a*x+b&lt;=360-D ,并且和 [0,60] 取交集</span><span style="color: #008000;"><br /></span>{<br />    qujian p;<br />    <span style="color: #0000ff;">if</span>(a&gt;<span style="color: #800080;">0</span>)<br />    {<br />        p.l=(D-b)/a;<br />        p.r=(<span style="color: #800080;">360</span>-D-b)/a;<br />    }    <br />    <span style="color: #0000ff;">else</span><br />    {<br />        p.l=(<span style="color: #800080;">360</span>-D-b)/a;<br />        p.r=(D-b)/a;<br />    }    <br />    <span style="color: #0000ff;">if</span>(p.l&lt;<span style="color: #800080;">0</span>)p.l=<span style="color: #800080;">0</span>;<br />    <span style="color: #0000ff;">if</span>(p.r&gt;<span style="color: #800080;">60</span>)p.r=<span style="color: #800080;">60</span>;<br />    <span style="color: #0000ff;">if</span>(p.l&gt;=p.r)  p.l=p.r=<span style="color: #800080;">0</span>;<br />    <span style="color: #0000ff;">return</span> p;<br />}     <br />qujian jiao(qujian a,qujian b)<br />{<br />    qujian p;<br />    p.l=max(a.l,b.l);<br />    p.r=min(a.r,b.r);<br />    <span style="color: #0000ff;">if</span>(p.l&gt;=p.r) p.l=p.r=<span style="color: #800080;">0</span>;<br />    <span style="color: #0000ff;">return</span> p;<br />}    <br /><span style="color: #008000;">/*</span><span style="color: #008000;"><br />   hh=30*h+m/2+s/120;<br />   mm=6*m+s/10;<br />   ss=6*s;<br />   D&lt;=|hh-mm|&lt;=360-D;<br />   D&lt;=|hh-ss|&lt;=360-D;<br />   D&lt;=|mm-ss|&lt;=360-D;<br />   hh-mm=<br /></span><span style="color: #008000;">*/</span><br /><span style="color: #0000ff;">double</span> happytime(<span style="color: #0000ff;">int</span> h,<span style="color: #0000ff;">int</span> m)<span style="color: #008000;">//</span><span style="color: #008000;">计算 h 时，m 分 满足题意的秒数</span><span style="color: #008000;"><br /></span>{<br />    <span style="color: #0000ff;">double</span> a,b;<br />    qujian s[<span style="color: #800080;">3</span>][<span style="color: #800080;">2</span>];<br />    qujian s1;<br />    <br />    <span style="color: #008000;">//</span><span style="color: #008000;">解方程 D&lt;=|hh-mm|&lt;=360-D <br />    </span><span style="color: #008000;">//</span><span style="color: #008000;">hh=30*h+m/2+s/120;<br />    </span><span style="color: #008000;">//</span><span style="color: #008000;">mm=6*m+s/10;</span><span style="color: #008000;"><br /></span>    a=<span style="color: #800080;">1.0</span>/<span style="color: #800080;">120</span>-<span style="color: #800080;">0.1</span>;<br />    b=<span style="color: #800080;">30</span>*h+m/<span style="color: #800080;">2.0</span>-<span style="color: #800080;">6</span>*m;<br />    s[<span style="color: #800080;">0</span>][<span style="color: #800080;">0</span>]=solve(a,b);<br />    s[<span style="color: #800080;">0</span>][<span style="color: #800080;">1</span>]=solve(-a,-b);<br />    <br />    <span style="color: #008000;">//</span><span style="color: #008000;">解方程  D&lt;=|hh-ss|&lt;=360-D <br />    </span><span style="color: #008000;">//</span><span style="color: #008000;">hh=30*h+m/2+s/120;<br />    </span><span style="color: #008000;">//</span><span style="color: #008000;">ss=6*s;</span><span style="color: #008000;"><br /></span>    a=<span style="color: #800080;">1.0</span>/<span style="color: #800080;">120</span>-<span style="color: #800080;">6.0</span>;<br />    b=<span style="color: #800080;">30</span>*h+m/<span style="color: #800080;">2.0</span>;<br />    s[<span style="color: #800080;">1</span>][<span style="color: #800080;">0</span>]=solve(a,b);<br />    s[<span style="color: #800080;">1</span>][<span style="color: #800080;">1</span>]=solve(-a,-b);<br />    <br />    <span style="color: #008000;">//</span><span style="color: #008000;">解方程  D&lt;=|mm-ss|&lt;=360-D <br />    </span><span style="color: #008000;">//</span><span style="color: #008000;">mm=6*m+s/10;<br />    </span><span style="color: #008000;">//</span><span style="color: #008000;">ss=6*s;</span><span style="color: #008000;"><br /></span>    a=<span style="color: #800080;">0.1</span>-<span style="color: #800080;">6</span>;<br />    b=<span style="color: #800080;">6</span>*m;<br />    s[<span style="color: #800080;">2</span>][<span style="color: #800080;">0</span>]=solve(a,b);<br />    s[<span style="color: #800080;">2</span>][<span style="color: #800080;">1</span>]=solve(-a,-b);<br />    <br />    <span style="color: #0000ff;">double</span> res=<span style="color: #800080;">0</span>;<br />    <span style="color: #008000;">//</span><span style="color: #008000;">六个区间，选三个取交集。<br />    </span><span style="color: #008000;">//</span><span style="color: #008000;">因为绝对值的式子得到的两个区间要并，而三个不同表达式的区间要交，故这样做。 </span><span style="color: #008000;"><br /></span>    <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i=<span style="color: #800080;">0</span>;i&lt;<span style="color: #800080;">2</span>;i++)<br />      <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> j=<span style="color: #800080;">0</span>;j&lt;<span style="color: #800080;">2</span>;j++)<br />         <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> k=<span style="color: #800080;">0</span>;k&lt;<span style="color: #800080;">2</span>;k++)<br />         {<br />             s1=jiao(jiao(s[<span style="color: #800080;">0</span>][i],s[<span style="color: #800080;">1</span>][j]),s[<span style="color: #800080;">2</span>][k]);<br />             res+=s1.r-s1.l;<br />         }    <br />    <span style="color: #0000ff;">return</span> res;<br />}     <br /><br /><span style="color: #0000ff;">int</span> main()<br />{<br />    <span style="color: #0000ff;">while</span>(scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%lf</span><span style="color: #800000;">"</span>,&amp;D))<br />    {<br />        <span style="color: #0000ff;">if</span>(D==-<span style="color: #800080;">1</span>) <span style="color: #0000ff;">break</span>;<br />        <span style="color: #0000ff;">double</span> res=<span style="color: #800080;">0</span>;<br />        <span style="color: #0000ff;">int</span> h,m;<br />        <span style="color: #0000ff;">for</span>(h=<span style="color: #800080;">0</span>;h&lt;<span style="color: #800080;">12</span>;h++)<br />        {<br />            <span style="color: #0000ff;">for</span>(m=<span style="color: #800080;">0</span>;m&lt;<span style="color: #800080;">60</span>;m++)<br />            {<br />                res+=happytime(h,m);<br />            }    <br />        }    <br />        printf(<span style="color: #800000;">"</span><span style="color: #800000;">%.3lf\n</span><span style="color: #800000;">"</span>,res*<span style="color: #800080;">100.0</span>/(<span style="color: #800080;">60</span>*<span style="color: #800080;">60</span>*<span style="color: #800080;">12</span>));    <br />    }    <br />    <span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span>;<br />}    </pre>
</div>
<p>&nbsp;</p><br>文章来源:<a href='http://www.cnblogs.com/kuangbin/archive/2011/12/04/2275470.html'>http://www.cnblogs.com/kuangbin/archive/2011/12/04/2275470.html</a><img src ="http://www.cppblog.com/kuangbin/aggbug/167580.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kuangbin/" target="_blank">kuangbin</a> 2011-12-04 15:17 <a href="http://www.cppblog.com/kuangbin/archive/2011/12/04/167580.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>