锘??xml version="1.0" encoding="utf-8" standalone="yes"?>99久久这里只有精品,久久亚洲AV无码精品色午夜麻豆 ,久久精品国产亚洲5555http://www.shnenglu.com/bennycen/category/15350.htmlzh-cnThu, 29 Mar 2012 12:29:05 GMTThu, 29 Mar 2012 12:29:05 GMT60hdu 2087 hud 1686http://www.shnenglu.com/bennycen/archive/2012/03/29/169456.htmlbennycenbennycenThu, 29 Mar 2012 12:13:00 GMThttp://www.shnenglu.com/bennycen/archive/2012/03/29/169456.htmlhttp://www.shnenglu.com/bennycen/comments/169456.htmlhttp://www.shnenglu.com/bennycen/archive/2012/03/29/169456.html#Feedback0http://www.shnenglu.com/bennycen/comments/commentRss/169456.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/169456.html 1#include <stdio.h> 2#include &...  闃呰鍏ㄦ枃

bennycen 2012-03-29 20:13 鍙戣〃璇勮
]]>
hdu 2896 澶氭ā寮忎覆鍖歸厤2http://www.shnenglu.com/bennycen/archive/2012/03/29/169451.htmlbennycenbennycenThu, 29 Mar 2012 10:18:00 GMThttp://www.shnenglu.com/bennycen/archive/2012/03/29/169451.htmlhttp://www.shnenglu.com/bennycen/comments/169451.htmlhttp://www.shnenglu.com/bennycen/archive/2012/03/29/169451.html#Feedback0http://www.shnenglu.com/bennycen/comments/commentRss/169451.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/169451.html  1#include&nbs...  闃呰鍏ㄦ枃

bennycen 2012-03-29 18:18 鍙戣〃璇勮
]]>
hdu 2222 澶氭ā寮忎覆鍖歸厤http://www.shnenglu.com/bennycen/archive/2012/03/29/169449.htmlbennycenbennycenThu, 29 Mar 2012 10:15:00 GMThttp://www.shnenglu.com/bennycen/archive/2012/03/29/169449.htmlhttp://www.shnenglu.com/bennycen/comments/169449.htmlhttp://www.shnenglu.com/bennycen/archive/2012/03/29/169449.html#Feedback0http://www.shnenglu.com/bennycen/comments/commentRss/169449.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/169449.html  1#include <stdio.h>  2#include <string.h>&n...  闃呰鍏ㄦ枃

bennycen 2012-03-29 18:15 鍙戣〃璇勮
]]>
姘撮涓ら亾http://www.shnenglu.com/bennycen/archive/2012/03/26/169047.htmlbennycenbennycenMon, 26 Mar 2012 12:19:00 GMThttp://www.shnenglu.com/bennycen/archive/2012/03/26/169047.htmlhttp://www.shnenglu.com/bennycen/comments/169047.htmlhttp://www.shnenglu.com/bennycen/archive/2012/03/26/169047.html#Feedback0http://www.shnenglu.com/bennycen/comments/commentRss/169047.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/169047.html
http://poj.org/problem?id=2081
姹傛暟鍒楃i欏?nbsp;0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9
瑙f硶錛氭寜鐓ч鐩姹傞掓帹鍗沖彲
#include <stdio.h>
#include 
<string.h>

bool visited[4000005];
int nums[4000005];

void pre()
{
    memset(visited,
0,sizeof(visited));
    memset(nums,
0,sizeof(nums));
    visited[
0= true;
    
for (int i = 1; i <= 500000++i)
    {
        
int k = nums[i-1- i;
        
if (k <=0 || visited[k])
        {
            nums[i] 
= nums[i-1+ i;
            visited[nums[i]] 
= true;
        }
        
else
        {
            nums[i] 
= nums[i-1- i;
            visited[nums[i]] 
= true;
        }
    }
}

int main()
{
    pre();
    
int n;
    
while(scanf("%d",&n) != EOF)
    {
        
if (n == -1)
        {
            
break;
        }
        printf(
"%d\n",nums[n]);
    }
    
return 0;
}

2250 
http://poj.org/problem?id=2250
鏈闀垮叕鍏變覆
  1 #include <iostream>
  2 #include <string.h>
  3 #include <string>
  4 #include <vector>
  5 using namespace std;
  6 
  7 string strs1[128];
  8 int len1;
  9 string strs2[128];
 10 int len2;
 11 int dp[128][128];
 12 int flags[128][128];//1 涓?nbsp;2 宸?nbsp;3 瀵硅
 13 
 14 void Test()
 15 {
 16     memset(dp,0,sizeof(dp));
 17     memset(flags,0,sizeof(flags));
 18     for (int i = 1; i <= len1; ++i)
 19     {
 20         for (int j = 1; j <= len2; ++j)
 21         {
 22             if (strs1[i] == strs2[j])
 23             {
 24                 dp[i][j] = dp[i-1][j-1+ 1;
 25                 flags[i][j] = 3;
 26             }
 27             else
 28             {
 29                 int m1 = dp[i-1][j];
 30                 int m2 = dp[i][j-1];
 31                 if (m1 < m2)
 32                 {
 33                     dp[i][j] = m2;
 34                     flags[i][j] = 2;
 35                 }
 36                 else
 37                 {
 38                     dp[i][j] = m1;
 39                     flags[i][j] = 1;
 40                 }
 41             }
 42         }
 43     }
 44     int pos1 = len1;
 45     int pos2 = len2;
 46     vector<string> vec;
 47     while(true)
 48     {
 49         if (flags[pos1][pos2] == 3)
 50         {
 51             vec.push_back(strs1[pos1]);
 52             --pos1;
 53             --pos2;
 54         }
 55         else if (flags[pos1][pos2] == 2)
 56         {
 57             --pos2;
 58         }
 59         else if (flags[pos1][pos2] == 1)
 60         {
 61             --pos1;
 62         }
 63         else
 64             break;
 65     }
 66     for (int i =  vec.size()-1; i >=0 ; --i)
 67     {
 68         cout << vec[i];
 69         if (i == 0)
 70         {
 71             cout << endl;
 72         }
 73         else
 74         {
 75             cout << " ";
 76         }
 77     }
 78 }
 79 
 80 int main()
 81 {
 82     //freopen("data.txt","r",stdin);
 83     string input;
 84     int k = 0;
 85     len1 = len2 = 0;
 86     while(cin >> input)
 87     {
 88         if (input == "#")
 89         {
 90             if (k == 1)
 91             {
 92                 Test();
 93                 k = 0;
 94                 len1 = len2 = 0;
 95                 continue;
 96             }
 97             else
 98             {
 99                 k = 1;
100             }
101         }
102         if (k == 0)
103         {
104             strs1[++len1] = input;
105         }
106         else
107         {
108             strs2[++len2] = input;
109         }
110     }
111     return 0;
112 }





bennycen 2012-03-26 20:19 鍙戣〃璇勮
]]>
zoj 3542http://www.shnenglu.com/bennycen/archive/2012/03/26/168973.htmlbennycenbennycenMon, 26 Mar 2012 02:42:00 GMThttp://www.shnenglu.com/bennycen/archive/2012/03/26/168973.htmlhttp://www.shnenglu.com/bennycen/comments/168973.htmlhttp://www.shnenglu.com/bennycen/archive/2012/03/26/168973.html#Feedback0http://www.shnenglu.com/bennycen/comments/commentRss/168973.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/168973.html 1#include <stdio.h> 2#include <string.h> 3 4char&n...  闃呰鍏ㄦ枃

bennycen 2012-03-26 10:42 鍙戣〃璇勮
]]>
poj 3074http://www.shnenglu.com/bennycen/archive/2012/03/12/167730.htmlbennycenbennycenMon, 12 Mar 2012 11:37:00 GMThttp://www.shnenglu.com/bennycen/archive/2012/03/12/167730.htmlhttp://www.shnenglu.com/bennycen/comments/167730.htmlhttp://www.shnenglu.com/bennycen/archive/2012/03/12/167730.html#Feedback3http://www.shnenglu.com/bennycen/comments/commentRss/167730.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/167730.html闃呰鍏ㄦ枃

bennycen 2012-03-12 19:37 鍙戣〃璇勮
]]>
閫嗗簭鏁板強鍏舵眰娉?/title><link>http://www.shnenglu.com/bennycen/archive/2011/11/17/160369.html</link><dc:creator>bennycen</dc:creator><author>bennycen</author><pubDate>Thu, 17 Nov 2011 12:46:00 GMT</pubDate><guid>http://www.shnenglu.com/bennycen/archive/2011/11/17/160369.html</guid><wfw:comment>http://www.shnenglu.com/bennycen/comments/160369.html</wfw:comment><comments>http://www.shnenglu.com/bennycen/archive/2011/11/17/160369.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/bennycen/comments/commentRss/160369.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/bennycen/services/trackbacks/160369.html</trackback:ping><description><![CDATA[<p>1. 閫嗗簭鏁?/p> <p>鎵璋撻嗗簭鏁幫紝灝辨槸鎸囦竴涓簭鍒桽[i]錛岀粺璁″浜庡簭鍒楃殑姣忎釜鏁扮殑姣旇繖涓暟澶у茍涓旀帓鍦ㄥ畠鍓嶉潰鐨勬暟鐨勬暟鐩紝鐒跺悗瀵逛簬鎵鏈夋暟錛屾妸榪欎釜鏁扮洰鍔犺搗鏉ユ眰鍜屽氨鏄簡銆?br />姣斿 4 3 1 2<br />4絎竴涓紝鎵浠ユ暟鐩負0<br />3鐨勫墠闈㈡槸4錛屽ぇ浜?鐨勬暟鐩負1<br />1鐨勫墠闈㈡槸4 3 錛屽ぇ浜?鐨勬暟鐩負2<br />2鐨勫墠闈㈡槸4 3 1錛屽ぇ浜?鐨勬暟鐩負2<br />鎵浠ラ嗗簭鏁頒負1+2+2 = 5</p> <p>姹傞嗗簭鏁扮殑涓ょ鏂規硶<br />甯歌鏂規硶鏄寜鐓ч嗗簭鏁扮殑瑙勫垯鍋氾紝緇撴灉澶嶆潅搴︽槸O(n*n)錛屼竴鑸潵璇達紝鏈変袱縐嶅揩閫熺殑姹傞嗗簭鏁扮殑鏂規硶<br />鍒嗗埆鏄綊騫舵帓搴忓拰鏍戠姸鏁扮粍娉?/p> <p><br />2. 褰掑茍鎺掑簭 <br />褰掑茍鎺掑簭鏄簮浜庡垎鑰屾不涔嬫濇兂錛岃緇嗙殑榪囩▼鍙互鏌ラ槄鍏朵粬璧勬枡錛屾諱綋鎬濇兂鏄垝鍒嗕竴鍗婏紝鍚勮嚜鎺掑ソ搴忓悗灝嗕袱涓湁搴忓簭鍒楀悎騫惰搗鏉ャ?/p> <p>濡備綍淇敼褰掑茍鎺掑簭姹傞嗗簭鏁?<br />棣栧厛鎴戜滑鍋囪涓や釜鏈夊簭搴忓垪 a[i]鍜宐[i]錛屽綋鍚堝茍鏃訛細<br />鐢變簬a[i]宸叉槸鏈夊簭錛屾墍浠ュ浜巃[i]鐨勫悇涓厓绱犳潵璇達紝鎺掑湪瀹冨墠闈笖姣斿畠澶х殑鏁扮洰閮芥槸0<br />褰揵[i]涓惈鏈夋瘮a[i]灝忕殑鍏冪礌鏃訛紝鎴戜滑蹇呯劧灝哹[i]鍏冪礌鎻掑埌鍓嶉潰錛岄偅涔堝氨鏄錛屽湪b[i]鍘熷厛浣嶇疆鍒拌鎻掔殑浣嶇疆涓紝鎵鏈夋暟閮芥瘮b[i]澶т笖鎺掑湪瀹冨墠闈?br />鎵浠ヨ繖鏄痓[i]鐨勬暟鐩負鏂版彃鍏ヤ綅緗畁ewPos - 鍘熸潵浣嶇疆oldPos</p> <p>閭d箞瀵逛簬涓鍗婄殑搴忓垪鍙堟庝箞鍋氬憿錛熸垜浠煡閬擄紝褰掑茍鎺掑簭浼氱戶緇悜涓嬮掑綊錛岃岄掑綊瀹屾垚榪斿洖鍚庡皢鏄袱緇勬湁搴忕殑搴忓垪錛屽茍涓旀嬁鍒板眬閮ㄧ殑閫嗗簭鏁幫紝<br />鎵浠ュ湪Merge鍑芥暟涓坊鍔犺繖涓璁℃暟鎿嶄綔鍗沖彲<br /></p> <p> </p>浠g爜紺轟緥濡備笅錛? <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">int</span><span style="color: #000000"> L[</span><span style="color: #000000">M</span><span style="color: #000000">];<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">int</span><span style="color: #000000"> R[M</span><span style="color: #000000">];<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">const</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> Max </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000"> </span><span style="color: #000000"><<</span><span style="color: #000000">30</span><span style="color: #000000">;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />__int64 change </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">void</span><span style="color: #000000"> Merge(</span><span style="color: #0000ff">int</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000">data,</span><span style="color: #0000ff">int</span><span style="color: #000000"> left,</span><span style="color: #0000ff">int</span><span style="color: #000000"> divide,</span><span style="color: #0000ff">int</span><span style="color: #000000"> right)<br /><img id="Codehighlighter1_134_559_Open_Image" onclick="this.style.display='none'; Codehighlighter1_134_559_Open_Text.style.display='none'; Codehighlighter1_134_559_Closed_Image.style.display='inline'; Codehighlighter1_134_559_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_134_559_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_134_559_Closed_Text.style.display='none'; Codehighlighter1_134_559_Open_Image.style.display='inline'; Codehighlighter1_134_559_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_134_559_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_134_559_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> lengthL </span><span style="color: #000000">=</span><span style="color: #000000"> divide </span><span style="color: #000000">-</span><span style="color: #000000"> left;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> lengthR </span><span style="color: #000000">=</span><span style="color: #000000"> right </span><span style="color: #000000">-</span><span style="color: #000000"> divide;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000"> i </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">; i </span><span style="color: #000000"><</span><span style="color: #000000"> lengthL; </span><span style="color: #000000">++</span><span style="color: #000000">i)<br /><img id="Codehighlighter1_234_262_Open_Image" onclick="this.style.display='none'; Codehighlighter1_234_262_Open_Text.style.display='none'; Codehighlighter1_234_262_Closed_Image.style.display='inline'; Codehighlighter1_234_262_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_234_262_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_234_262_Closed_Text.style.display='none'; Codehighlighter1_234_262_Open_Image.style.display='inline'; Codehighlighter1_234_262_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">    </span><span id="Codehighlighter1_234_262_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_234_262_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        L[i] </span><span style="color: #000000">=</span><span style="color: #000000"> data[left </span><span style="color: #000000">+</span><span style="color: #000000"> i];<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000"> i </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">; i </span><span style="color: #000000"><</span><span style="color: #000000"> lengthR; </span><span style="color: #000000">++</span><span style="color: #000000">i)<br /><img id="Codehighlighter1_299_329_Open_Image" onclick="this.style.display='none'; Codehighlighter1_299_329_Open_Text.style.display='none'; Codehighlighter1_299_329_Closed_Image.style.display='inline'; Codehighlighter1_299_329_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_299_329_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_299_329_Closed_Text.style.display='none'; Codehighlighter1_299_329_Open_Image.style.display='inline'; Codehighlighter1_299_329_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">    </span><span id="Codehighlighter1_299_329_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_299_329_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        R[i] </span><span style="color: #000000">=</span><span style="color: #000000"> data[divide </span><span style="color: #000000">+</span><span style="color: #000000"> i];<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    L[lengthL] </span><span style="color: #000000">=</span><span style="color: #000000"> R[lengthR] </span><span style="color: #000000">=</span><span style="color: #000000"> Max;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> i </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> j </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000"> k </span><span style="color: #000000">=</span><span style="color: #000000"> left; k </span><span style="color: #000000"><</span><span style="color: #000000"> right; </span><span style="color: #000000">++</span><span style="color: #000000">k)<br /><img id="Codehighlighter1_423_556_Open_Image" onclick="this.style.display='none'; Codehighlighter1_423_556_Open_Text.style.display='none'; Codehighlighter1_423_556_Closed_Image.style.display='inline'; Codehighlighter1_423_556_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_423_556_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_423_556_Closed_Text.style.display='none'; Codehighlighter1_423_556_Open_Image.style.display='inline'; Codehighlighter1_423_556_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">    </span><span id="Codehighlighter1_423_556_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_423_556_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(L[i] </span><span style="color: #000000"><=</span><span style="color: #000000"> R[j])<br /><img id="Codehighlighter1_446_477_Open_Image" onclick="this.style.display='none'; Codehighlighter1_446_477_Open_Text.style.display='none'; Codehighlighter1_446_477_Closed_Image.style.display='inline'; Codehighlighter1_446_477_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_446_477_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_446_477_Closed_Text.style.display='none'; Codehighlighter1_446_477_Open_Image.style.display='inline'; Codehighlighter1_446_477_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">        </span><span id="Codehighlighter1_446_477_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_446_477_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />            data[k] </span><span style="color: #000000">=</span><span style="color: #000000"> L[i];<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="color: #000000">++</span><span style="color: #000000">i;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">else</span><span style="color: #000000"> <br /><img id="Codehighlighter1_489_553_Open_Image" onclick="this.style.display='none'; Codehighlighter1_489_553_Open_Text.style.display='none'; Codehighlighter1_489_553_Closed_Image.style.display='inline'; Codehighlighter1_489_553_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_489_553_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_489_553_Closed_Text.style.display='none'; Codehighlighter1_489_553_Open_Image.style.display='inline'; Codehighlighter1_489_553_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">        </span><span id="Codehighlighter1_489_553_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_489_553_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />            change </span><span style="color: #000000">+=</span><span style="color: #000000"> divide </span><span style="color: #000000">-</span><span style="color: #000000"> i </span><span style="color: #000000">-</span><span style="color: #000000"> left ;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />            data[k] </span><span style="color: #000000">=</span><span style="color: #000000"> R[j];<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="color: #000000">++</span><span style="color: #000000">j;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">void</span><span style="color: #000000"> MergeSort(</span><span style="color: #0000ff">int</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000">data,</span><span style="color: #0000ff">int</span><span style="color: #000000"> left,</span><span style="color: #0000ff">int</span><span style="color: #000000"> right)<br /><img id="Codehighlighter1_664_822_Open_Image" onclick="this.style.display='none'; Codehighlighter1_664_822_Open_Text.style.display='none'; Codehighlighter1_664_822_Closed_Image.style.display='inline'; Codehighlighter1_664_822_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_664_822_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_664_822_Closed_Text.style.display='none'; Codehighlighter1_664_822_Open_Image.style.display='inline'; Codehighlighter1_664_822_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_664_822_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_664_822_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(left </span><span style="color: #000000"><</span><span style="color: #000000"> right </span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">)<br /><img id="Codehighlighter1_688_820_Open_Image" onclick="this.style.display='none'; Codehighlighter1_688_820_Open_Text.style.display='none'; Codehighlighter1_688_820_Closed_Image.style.display='inline'; Codehighlighter1_688_820_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_688_820_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_688_820_Closed_Text.style.display='none'; Codehighlighter1_688_820_Open_Image.style.display='inline'; Codehighlighter1_688_820_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">    </span><span id="Codehighlighter1_688_820_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_688_820_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">int</span><span style="color: #000000"> divide </span><span style="color: #000000">=</span><span style="color: #000000"> (left </span><span style="color: #000000">+</span><span style="color: #000000"> right)</span><span style="color: #000000">/</span><span style="color: #000000">2</span><span style="color: #000000">;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        MergeSort(data,left,divide);<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        MergeSort(data,divide,right);<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        Merge(data,left,divide,right);<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <p><br /><br />3. 鏍戠姸鏁扮粍<br />姹傞嗗簭鏁扮殑鍙﹀涓縐嶆柟娉曟槸浣跨敤鏍戠姸鏁扮粍<br />瀵逛簬灝忔暟鎹紝鍙互鐩存帴鎻掑叆鏍戠姸鏁扮粍錛屽浜庡ぇ鏁版嵁錛屽垯闇瑕佺鏁e寲錛屾墍璋撶鏁e寲錛屽氨鏄皢<br />100 200 300 400 500 ---> 1 2 3 4 5</p> <p>榪欓噷涓昏鍒╃敤鏍戠姸鏁扮粍瑙e喅璁℃暟闂銆?/p> <p>棣栧厛鎸夐『搴忔妸搴忓垪a[i]姣忎釜鏁版彃鍏ュ埌鏍戠姸鏁扮粍涓紝鎻掑叆鐨勫唴瀹規槸1錛岃〃紺烘斁浜嗕竴涓暟鍒版爲鐘舵暟緇勪腑銆?br />鐒跺悗浣跨敤sum鎿嶄綔鑾峰彇褰撳墠姣攁[i]灝忕殑鏁幫紝閭d箞褰撳墠i - sum鍒欒〃紺哄綋鍓嶆瘮a[i]澶х殑鏁幫紝濡傛鍙嶅鐩村埌鎵鏈夋暟閮界粺璁″畬錛?br />姣斿<br />4 3 1 2 <br />i = 1 : 鎻掑叆 4 : update(4,1)錛宻um(4)榪斿洖1錛岄偅涔堝綋鍓嶆瘮4澶х殑涓?i - 1 = 0;<br />i = 2 : 鎻掑叆 3 : update(3,1)錛宻um(3)榪斿洖1錛岄偅涔堝綋鍓嶆瘮3澶х殑涓?i - 1 = 1;<br />i = 3 : 鎻掑叆 1 : update(1,1)錛宻um(1)榪斿洖1錛岄偅涔堝綋鍓嶆瘮1澶х殑涓?i - 1 = 2;<br />i = 4 : 鎻掑叆 2 : update(2,1)錛宻um(2)榪斿洖2錛岄偅涔堝綋鍓嶆瘮2澶х殑涓?i - 2 = 2;</p> <p>榪囩▼寰堟槑浜嗭紝鎵浠ラ嗗簭鏁頒負1+2+2=5<br /><br />浠g爜紺轟緥濡備笅錛?/p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #008000">//</span><span style="color: #008000">鏍戠姸鏁扮粍</span><span style="color: #008000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000">__int64 sums[</span><span style="color: #000000">1005</span><span style="color: #000000">];<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">int</span><span style="color: #000000"> len;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />inline </span><span style="color: #0000ff">int</span><span style="color: #000000"> lowbit(</span><span style="color: #0000ff">int</span><span style="color: #000000"> t)<br /><img id="Codehighlighter1_62_88_Open_Image" onclick="this.style.display='none'; Codehighlighter1_62_88_Open_Text.style.display='none'; Codehighlighter1_62_88_Closed_Image.style.display='inline'; Codehighlighter1_62_88_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_62_88_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_62_88_Closed_Text.style.display='none'; Codehighlighter1_62_88_Open_Image.style.display='inline'; Codehighlighter1_62_88_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_62_88_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_62_88_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> t </span><span style="color: #000000">&</span><span style="color: #000000"> (t</span><span style="color: #000000">^</span><span style="color: #000000">(t</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">)); <br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">void</span><span style="color: #000000"> update(</span><span style="color: #0000ff">int</span><span style="color: #000000"> _x,</span><span style="color: #0000ff">int</span><span style="color: #000000"> _value)<br /><img id="Codehighlighter1_122_190_Open_Image" onclick="this.style.display='none'; Codehighlighter1_122_190_Open_Text.style.display='none'; Codehighlighter1_122_190_Closed_Image.style.display='inline'; Codehighlighter1_122_190_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_122_190_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_122_190_Closed_Text.style.display='none'; Codehighlighter1_122_190_Open_Image.style.display='inline'; Codehighlighter1_122_190_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_122_190_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_122_190_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">while</span><span style="color: #000000">(_x </span><span style="color: #000000"><=</span><span style="color: #000000"> len)<br /><img id="Codehighlighter1_143_188_Open_Image" onclick="this.style.display='none'; Codehighlighter1_143_188_Open_Text.style.display='none'; Codehighlighter1_143_188_Closed_Image.style.display='inline'; Codehighlighter1_143_188_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_143_188_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_143_188_Closed_Text.style.display='none'; Codehighlighter1_143_188_Open_Image.style.display='inline'; Codehighlighter1_143_188_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">    </span><span id="Codehighlighter1_143_188_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_143_188_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        sums[_x] </span><span style="color: #000000">+=</span><span style="color: #000000"> _value;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        _x </span><span style="color: #000000">+=</span><span style="color: #000000"> lowbit(_x);<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />__int64 sum(</span><span style="color: #0000ff">int</span><span style="color: #000000"> _end)</span><span style="color: #008000">//</span><span style="color: #008000">get sum[1<img alt="" src="http://www.shnenglu.com/Images/dot.gif" />_end]</span><span style="color: #008000"><br /><img id="Codehighlighter1_234_335_Open_Image" onclick="this.style.display='none'; Codehighlighter1_234_335_Open_Text.style.display='none'; Codehighlighter1_234_335_Closed_Image.style.display='inline'; Codehighlighter1_234_335_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_234_335_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_234_335_Closed_Text.style.display='none'; Codehighlighter1_234_335_Open_Image.style.display='inline'; Codehighlighter1_234_335_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_234_335_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_234_335_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    __int64 ret </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">while</span><span style="color: #000000">(_end </span><span style="color: #000000">></span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_272_320_Open_Image" onclick="this.style.display='none'; Codehighlighter1_272_320_Open_Text.style.display='none'; Codehighlighter1_272_320_Closed_Image.style.display='inline'; Codehighlighter1_272_320_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_272_320_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_272_320_Closed_Text.style.display='none'; Codehighlighter1_272_320_Open_Image.style.display='inline'; Codehighlighter1_272_320_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">    </span><span id="Codehighlighter1_272_320_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_272_320_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        ret </span><span style="color: #000000">+=</span><span style="color: #000000"> sums[_end];<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        _end </span><span style="color: #000000">-=</span><span style="color: #000000"> lowbit(_end);<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> ret;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #008000">//</span><span style="color: #008000">姹傞嗗簭鏁?/span><span style="color: #008000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000"><br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />__int64 ret </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">for</span><span style="color: #000000"> (__int64 i </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">; i </span><span style="color: #000000"><</span><span style="color: #000000"> k; </span><span style="color: #000000">++</span><span style="color: #000000">i)<br /><img id="Codehighlighter1_395_443_Open_Image" onclick="this.style.display='none'; Codehighlighter1_395_443_Open_Text.style.display='none'; Codehighlighter1_395_443_Closed_Image.style.display='inline'; Codehighlighter1_395_443_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_395_443_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_395_443_Closed_Text.style.display='none'; Codehighlighter1_395_443_Open_Image.style.display='inline'; Codehighlighter1_395_443_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_395_443_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_395_443_Open_Text"><span style="color: #000000">{<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    update(a[i],</span><span style="color: #000000">1</span><span style="color: #000000">);<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    ret </span><span style="color: #000000">+=</span><span style="color: #000000"> (i</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">) </span><span style="color: #000000">-</span><span style="color: #000000"> sum(a[i]);<br /><img alt="" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <p><br />姹傞嗗簭鏁扮殑棰樼洰鏈夛細<br /><a >http://poj.org/problem?id=2299</a><br /><a >http://poj.org/problem?id=3067</a><br /></p><img src ="http://www.shnenglu.com/bennycen/aggbug/160369.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/bennycen/" target="_blank">bennycen</a> 2011-11-17 20:46 <a href="http://www.shnenglu.com/bennycen/archive/2011/11/17/160369.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Poj 3310 鍒ょ幆+搴?/title><link>http://www.shnenglu.com/bennycen/archive/2011/11/17/160319.html</link><dc:creator>bennycen</dc:creator><author>bennycen</author><pubDate>Thu, 17 Nov 2011 02:50:00 GMT</pubDate><guid>http://www.shnenglu.com/bennycen/archive/2011/11/17/160319.html</guid><wfw:comment>http://www.shnenglu.com/bennycen/comments/160319.html</wfw:comment><comments>http://www.shnenglu.com/bennycen/archive/2011/11/17/160319.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/bennycen/comments/commentRss/160319.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/bennycen/services/trackbacks/160319.html</trackback:ping><description><![CDATA[     鎽樿: 棰樻剰錛氬垽鏂竴涓粰瀹氱殑鍥撅紝娌℃湁鐜紝鑰屼笖瀛樺湪涓涓摼錛屽浘涓婄殑鎵鏈夌偣鎴栬呭湪榪欐潯閾句笂鎴栬呭湪鍏剁殑閭誨眳棰樿В錛?.鍒ゆ柇鐜細瀵逛簬鏃犲悜鍥撅細濡傛灉 鐐?< 杈?+ 1錛屽垯瀛樺湪鐜紱鐒跺悗浣跨敤騫舵煡闆嗚繘涓姝ュ垽鏂幆鐨勫瓨鍦?.鍒ゆ柇鏄惁瀛樺湪閾鵑鍏堢粺璁″悇涓偣鐨勫害錛岀劧鍚庡浜庡害涓?鐨勭偣錛屽皢鍏剁浉榪炵殑杈瑰垹鎺夛紝鍐嶇粺璁℃柊鍥劇殑搴︼紝榪欐椂鏂板浘搴旇鍓╀笅涓鏉¢摼錛屼篃灝辨槸璇達紝鏂板浘鐨勪笉瀛樺湪澶т簬2涓害涓?鐨勭偣錛岃屼笖榪欎釜鐐瑰湪鏃у浘鐨勫害鏄ぇ浜?鐨勩備唬鐮侊細 Code...  <a href='http://www.shnenglu.com/bennycen/archive/2011/11/17/160319.html'>闃呰鍏ㄦ枃</a><img src ="http://www.shnenglu.com/bennycen/aggbug/160319.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/bennycen/" target="_blank">bennycen</a> 2011-11-17 10:50 <a href="http://www.shnenglu.com/bennycen/archive/2011/11/17/160319.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Poj 3104 浜屽垎絳旀http://www.shnenglu.com/bennycen/archive/2011/11/09/159861.htmlbennycenbennycenWed, 09 Nov 2011 04:45:00 GMThttp://www.shnenglu.com/bennycen/archive/2011/11/09/159861.htmlhttp://www.shnenglu.com/bennycen/comments/159861.htmlhttp://www.shnenglu.com/bennycen/archive/2011/11/09/159861.html#Feedback1http://www.shnenglu.com/bennycen/comments/commentRss/159861.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/159861.html棰樿В錛氱涓鏃墮棿灝辨兂鍒頒嬌鐢ㄤ簩鍒嗘灇鎹瓟妗?楠岃瘉榪欑鎬濊礬錛屼笉榪囪繖棰樿繕鏄湁浜涢櫡闃遍渶瑕佹敞鎰忋?br />1. 楠岃瘉絳旀鏃訛紝濡傛灉 a[i] <= mid錛岃瀹冭嚜鐒剁儤騫插嵆鍙?錛?濡傛灉a[i] > mid錛岄偅涔堢儤騫茶繖浠惰。鏈嶅彲浠ュ垎鎴愪袱孌墊椂闂達細浣跨敤鐑樺共鏈烘椂闂磝1 + 鑷劧鐑樺共鏃墮棿x2錛岄偅涔堝彲浠ュ垪鍑虹瓑寮忥細mid = x1 + x2; a[i] <= kx1+x2錛涗簬鏄緱x1 >= (a[i] -mid)/(k-1);鍗沖緱浣跨敤鐑樺共鏈虹殑鏈灝戞椂闂磝1
2.娉ㄦ剰褰搆==1鏃訛紝k-1 == 0錛岄渶瑕佺壒孌婂鐞嗭紝鐩存帴鎵撳嚭ans = maxV
3.娉ㄦ剰褰撴眰left+right鏃訛紝緇撴灉鍙兘瓚呭嚭鑼冨洿錛屾紜殑鏂規硶搴旇鏄痩eft + (right - left)*0.5;
#include <stdio.h>

const int N = 100005;
int n;
int a[N];
int k;

bool check(int _value)
{
    
int cnt = 0;
    
for (int i = 0; i < n; ++i)
    
{
        
if (a[i] > _value)
        
{
            
double kk = ((double)(a[i] - _value))/(k-1);
            cnt 
+= (int)kk;
            
if (kk - (int)kk > 0)
            
{
                
++cnt;
            }

            
if (cnt > _value)
            
{
                
return false;
            }

        }

    }


    
return (cnt <= _value);
}


int BinarySearch(int _low,int _high)
{
    
int left = _low;
    
int right = _high;
    
int mid;
    
int ans = _high;
    
while(left <= right)
    
{
        mid 
= (left+(right-left)*0.5);
        
if (check(mid))
        
{
            ans 
= mid;
            right 
= mid - 1;
        }

        
else
        
{
            left 
= mid + 1;
        }

    }

    
return ans;
}


void Test()
{
    
int maxV = 0;
    
for (int i = 0; i < n; ++i)
    
{
        scanf(
"%d",&a[i]);
        
if (maxV < a[i])
        
{
            maxV 
= a[i];
        }

    }

    scanf(
"%d",&k);
    
if (k == 1)
    
{
        printf(
"%d\n",maxV);
    }

    
else
        printf(
"%d\n",BinarySearch(0,maxV));
}


int main()
{
    
while(scanf("%d",&n) != EOF)
    
{
        Test();
    }

    
return 0;
}




bennycen 2011-11-09 12:45 鍙戣〃璇勮
]]>
Poj1111 姘撮http://www.shnenglu.com/bennycen/archive/2011/11/09/159860.htmlbennycenbennycenWed, 09 Nov 2011 04:34:00 GMThttp://www.shnenglu.com/bennycen/archive/2011/11/09/159860.htmlhttp://www.shnenglu.com/bennycen/comments/159860.htmlhttp://www.shnenglu.com/bennycen/archive/2011/11/09/159860.html#Feedback1http://www.shnenglu.com/bennycen/comments/commentRss/159860.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/159860.html#include&n...  闃呰鍏ㄦ枃

bennycen 2011-11-09 12:34 鍙戣〃璇勮
]]>
Poj2010 - 鍫嗙殑搴旂敤http://www.shnenglu.com/bennycen/archive/2011/10/19/158671.htmlbennycenbennycenWed, 19 Oct 2011 03:04:00 GMThttp://www.shnenglu.com/bennycen/archive/2011/10/19/158671.htmlhttp://www.shnenglu.com/bennycen/comments/158671.htmlhttp://www.shnenglu.com/bennycen/archive/2011/10/19/158671.html#Feedback1http://www.shnenglu.com/bennycen/comments/commentRss/158671.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/158671.html闃呰鍏ㄦ枃

bennycen 2011-10-19 11:04 鍙戣〃璇勮
]]>
Poj 1442 鍫嗘搷浣?/title><link>http://www.shnenglu.com/bennycen/archive/2011/06/02/147953.html</link><dc:creator>bennycen</dc:creator><author>bennycen</author><pubDate>Thu, 02 Jun 2011 07:34:00 GMT</pubDate><guid>http://www.shnenglu.com/bennycen/archive/2011/06/02/147953.html</guid><wfw:comment>http://www.shnenglu.com/bennycen/comments/147953.html</wfw:comment><comments>http://www.shnenglu.com/bennycen/archive/2011/06/02/147953.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/bennycen/comments/commentRss/147953.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/bennycen/services/trackbacks/147953.html</trackback:ping><description><![CDATA[棰樻剰錛?br />緇欏嚭涓ょ鎿嶄綔錛欰DD(x)錛屽皢x娣誨姞鍒版湁搴忓垪琛ㄤ腑錛汫ET()榪斿洖鍏ㄥ眬榪唬鍣ㄦ墍鎸囩殑鍊鹼紝鍏朵腑榪唬鍣ㄥ湪GET鎿嶄綔鍚庝細鑷坊鍔?<br />棰樿В錛?br />鍒氬紑濮嬬洿鎺ユ墜鎵撻摼琛ㄦā鎷燂紝緇撴灉瓚呮椂銆傝繖鏃跺簲浣跨敤鍙﹀涓縐嶆柟娉曪細浣跨敤澶ч《鍫嗗拰灝忛《鍫嗐?br />鍏朵腑錛屽浜庡簭鍒桽[1..n]錛屽強琛ㄧず榪唬鍣ㄤ綅緗殑index錛屽ぇ欏跺爢緇存姢鎺掑簭鍚庣殑S[1..index-1]錛屽皬欏跺爢緇存姢<br />鎺掑簭鍚庣殑S[index..n],渚嬪S[1..n] = 1,2,3,4,5,6,7錛宨ndex = 4錛屽垯澶ч《鍫嗕負{1,2,3}錛屽皬欏跺爢涓簕4,5,6,7}<br />涓轟粈涔堣榪欐牱緇存姢鍛紵鍥犱負褰撳皬鍫嗘渶灝忕殑鍏冪礌閮藉ぇ浜庡ぇ鍫嗘渶澶х殑鍏冪礌鏃訛紝閭d箞搴忓垪涓帓絎琻涓氨鏄皬鍫嗘渶灝忕殑鏁頒簡銆?br />鎴戜滑鍋囪絎琸瓚烥ET()鍚庯紝鏈変互涓嬫儏鏅?GET鍚巏鑷姩鍔?)錛?br />澶ч《鍫嗭細S[1..k]錛屽爢欏跺厓绱犱負S[k]錛屽皬欏跺爢錛歋[k+1,n]錛屽爢欏跺厓绱犱負S[k+1]錛岀劧鍚庢瘡褰撴坊鍔犱竴涓厓绱爊ewE鏃訛紝鍏堟坊鍔犲埌澶ч《鍫嗕腑錛岃繖鏃跺鏋滃嚭鐜板ぇ欏跺爢鏁板ぇ浜庡皬欏跺爢鐨勬暟鏃訛紝鐞嗗簲浜ゆ崲銆?br />浠g爜錛? <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"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #000000">#include </span><span style="color: #000000"><</span><span style="color: #000000">queue</span><span style="color: #000000">></span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />#include </span><span style="color: #000000"><</span><span style="color: #000000">stdio.h</span><span style="color: #000000">></span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000"> </span><span style="color: #0000ff">namespace</span><span style="color: #000000"> std;<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000"> m,n;<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000"> sequence[</span><span style="color: #000000">30005</span><span style="color: #000000">];<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">struct</span><span style="color: #000000"> cmp1<br /><img id="Codehighlighter1_101_165_Open_Image" onclick="this.style.display='none'; Codehighlighter1_101_165_Open_Text.style.display='none'; Codehighlighter1_101_165_Closed_Image.style.display='inline'; Codehighlighter1_101_165_Closed_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_101_165_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_101_165_Closed_Text.style.display='none'; Codehighlighter1_101_165_Open_Image.style.display='inline'; Codehighlighter1_101_165_Open_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_101_165_Closed_Text"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_101_165_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">bool</span><span style="color: #000000"> </span><span style="color: #0000ff">operator</span><span style="color: #000000">()(</span><span style="color: #0000ff">const</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> a,</span><span style="color: #0000ff">const</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> b)<br /><img id="Codehighlighter1_146_163_Open_Image" onclick="this.style.display='none'; Codehighlighter1_146_163_Open_Text.style.display='none'; Codehighlighter1_146_163_Closed_Image.style.display='inline'; Codehighlighter1_146_163_Closed_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_146_163_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_146_163_Closed_Text.style.display='none'; Codehighlighter1_146_163_Open_Image.style.display='inline'; Codehighlighter1_146_163_Open_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_146_163_Closed_Text"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_146_163_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> a</span><span style="color: #000000">></span><span style="color: #000000">b;<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />    }</span></span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" />}</span></span><span style="color: #000000">;<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">struct</span><span style="color: #000000"> cmp2<br /><img id="Codehighlighter1_180_244_Open_Image" onclick="this.style.display='none'; Codehighlighter1_180_244_Open_Text.style.display='none'; Codehighlighter1_180_244_Closed_Image.style.display='inline'; Codehighlighter1_180_244_Closed_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_180_244_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_180_244_Closed_Text.style.display='none'; Codehighlighter1_180_244_Open_Image.style.display='inline'; Codehighlighter1_180_244_Open_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_180_244_Closed_Text"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_180_244_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">bool</span><span style="color: #000000"> </span><span style="color: #0000ff">operator</span><span style="color: #000000">()(</span><span style="color: #0000ff">const</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> a,</span><span style="color: #0000ff">const</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> b)<br /><img id="Codehighlighter1_225_242_Open_Image" onclick="this.style.display='none'; Codehighlighter1_225_242_Open_Text.style.display='none'; Codehighlighter1_225_242_Closed_Image.style.display='inline'; Codehighlighter1_225_242_Closed_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_225_242_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_225_242_Closed_Text.style.display='none'; Codehighlighter1_225_242_Open_Image.style.display='inline'; Codehighlighter1_225_242_Open_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_225_242_Closed_Text"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_225_242_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> a</span><span style="color: #000000"><</span><span style="color: #000000">b;<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />    }</span></span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" />}</span></span><span style="color: #000000">;</span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000"> Test()<br /><img id="Codehighlighter1_393_904_Open_Image" onclick="this.style.display='none'; Codehighlighter1_393_904_Open_Text.style.display='none'; Codehighlighter1_393_904_Closed_Image.style.display='inline'; Codehighlighter1_393_904_Closed_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_393_904_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_393_904_Closed_Text.style.display='none'; Codehighlighter1_393_904_Open_Image.style.display='inline'; Codehighlighter1_393_904_Open_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_393_904_Closed_Text"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_393_904_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    priority_queue</span><span style="color: #000000"><</span><span style="color: #0000ff">int</span><span style="color: #000000">,vector</span><span style="color: #000000"><</span><span style="color: #0000ff">int</span><span style="color: #000000">></span><span style="color: #000000">,cmp1</span><span style="color: #000000">></span><span style="color: #000000">q1;</span><span style="color: #008000">//</span><span style="color: #008000">灝忓爢</span><span style="color: #008000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" /></span><span style="color: #000000">    priority_queue</span><span style="color: #000000"><</span><span style="color: #0000ff">int</span><span style="color: #000000">,vector</span><span style="color: #000000"><</span><span style="color: #0000ff">int</span><span style="color: #000000">></span><span style="color: #000000">,cmp2</span><span style="color: #000000">></span><span style="color: #000000">q2;</span><span style="color: #008000">//</span><span style="color: #008000">澶у爢</span><span style="color: #008000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" /></span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">for</span><span style="color: #000000"> (</span><span style="color: #0000ff">int</span><span style="color: #000000"> i </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">; i </span><span style="color: #000000"><</span><span style="color: #000000"> m; </span><span style="color: #000000">++</span><span style="color: #000000">i)<br /><img id="Codehighlighter1_516_547_Open_Image" onclick="this.style.display='none'; Codehighlighter1_516_547_Open_Text.style.display='none'; Codehighlighter1_516_547_Closed_Image.style.display='inline'; Codehighlighter1_516_547_Closed_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_516_547_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_516_547_Closed_Text.style.display='none'; Codehighlighter1_516_547_Open_Image.style.display='inline'; Codehighlighter1_516_547_Open_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_516_547_Closed_Text"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_516_547_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />        scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&</span><span style="color: #000000">sequence[i]);<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />    }</span></span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> op;<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> k </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">for</span><span style="color: #000000"> (</span><span style="color: #0000ff">int</span><span style="color: #000000"> i </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">; i </span><span style="color: #000000"><</span><span style="color: #000000"> n; </span><span style="color: #000000">++</span><span style="color: #000000">i)<br /><img id="Codehighlighter1_600_901_Open_Image" onclick="this.style.display='none'; Codehighlighter1_600_901_Open_Text.style.display='none'; Codehighlighter1_600_901_Closed_Image.style.display='inline'; Codehighlighter1_600_901_Closed_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_600_901_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_600_901_Closed_Text.style.display='none'; Codehighlighter1_600_901_Open_Image.style.display='inline'; Codehighlighter1_600_901_Open_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_600_901_Closed_Text"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_600_901_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />        scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&</span><span style="color: #000000">op);<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />        </span><span style="color: #0000ff">while</span><span style="color: #000000">(k </span><span style="color: #000000"><</span><span style="color: #000000"> op)<br /><img id="Codehighlighter1_639_837_Open_Image" onclick="this.style.display='none'; Codehighlighter1_639_837_Open_Text.style.display='none'; Codehighlighter1_639_837_Closed_Image.style.display='inline'; Codehighlighter1_639_837_Closed_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_639_837_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_639_837_Closed_Text.style.display='none'; Codehighlighter1_639_837_Open_Image.style.display='inline'; Codehighlighter1_639_837_Open_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif">        </span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_639_837_Closed_Text"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_639_837_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />            q1.push(sequence[k]);<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #000000">!</span><span style="color: #000000">q2.empty() </span><span style="color: #000000">&&</span><span style="color: #000000"> q1.top() </span><span style="color: #000000"><</span><span style="color: #000000"> q2.top())<br /><img id="Codehighlighter1_712_825_Open_Image" onclick="this.style.display='none'; Codehighlighter1_712_825_Open_Text.style.display='none'; Codehighlighter1_712_825_Closed_Image.style.display='inline'; Codehighlighter1_712_825_Closed_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_712_825_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_712_825_Closed_Text.style.display='none'; Codehighlighter1_712_825_Open_Image.style.display='inline'; Codehighlighter1_712_825_Open_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif">            </span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_712_825_Closed_Text"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_712_825_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />                </span><span style="color: #0000ff">int</span><span style="color: #000000"> t1 </span><span style="color: #000000">=</span><span style="color: #000000"> q1.top();<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />                q1.pop();<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />                </span><span style="color: #0000ff">int</span><span style="color: #000000"> t2 </span><span style="color: #000000">=</span><span style="color: #000000"> q2.top();<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />                q2.pop();<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />                q1.push(t2);<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />                q2.push(t1);<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />            }</span></span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />            </span><span style="color: #000000">++</span><span style="color: #000000">k;<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />        }</span></span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />        printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,q1.top());<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />        q2.push(q1.top());<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />        q1.pop();<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />    }</span></span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000"> main()<br /><img id="Codehighlighter1_918_983_Open_Image" onclick="this.style.display='none'; Codehighlighter1_918_983_Open_Text.style.display='none'; Codehighlighter1_918_983_Closed_Image.style.display='inline'; Codehighlighter1_918_983_Closed_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_918_983_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_918_983_Closed_Text.style.display='none'; Codehighlighter1_918_983_Open_Image.style.display='inline'; Codehighlighter1_918_983_Open_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_918_983_Closed_Text"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_918_983_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">while</span><span style="color: #000000">(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">&</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"> EOF)<br /><img id="Codehighlighter1_957_970_Open_Image" onclick="this.style.display='none'; Codehighlighter1_957_970_Open_Text.style.display='none'; Codehighlighter1_957_970_Closed_Image.style.display='inline'; Codehighlighter1_957_970_Closed_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_957_970_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_957_970_Closed_Text.style.display='none'; Codehighlighter1_957_970_Open_Image.style.display='inline'; Codehighlighter1_957_970_Open_Text.style.display='inline';" align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_957_970_Closed_Text"><img src="http://www.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_957_970_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />        Test();<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />    }</span></span><span style="color: #000000"><br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" />}</span></span></div><br /><img src ="http://www.shnenglu.com/bennycen/aggbug/147953.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/bennycen/" target="_blank">bennycen</a> 2011-06-02 15:34 <a href="http://www.shnenglu.com/bennycen/archive/2011/06/02/147953.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>PKU Campus 2011http://www.shnenglu.com/bennycen/archive/2011/05/24/147053.htmlbennycenbennycenTue, 24 May 2011 12:39:00 GMThttp://www.shnenglu.com/bennycen/archive/2011/05/24/147053.htmlhttp://www.shnenglu.com/bennycen/comments/147053.htmlhttp://www.shnenglu.com/bennycen/archive/2011/05/24/147053.html#Feedback0http://www.shnenglu.com/bennycen/comments/commentRss/147053.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/147053.html#include <stdio.h>#include <stri...  闃呰鍏ㄦ枃

bennycen 2011-05-24 20:39 鍙戣〃璇勮
]]>
POJ Challenge - 2011.04.10閮ㄥ垎棰樿Вhttp://www.shnenglu.com/bennycen/archive/2011/04/11/143951.htmlbennycenbennycenMon, 11 Apr 2011 07:59:00 GMThttp://www.shnenglu.com/bennycen/archive/2011/04/11/143951.htmlhttp://www.shnenglu.com/bennycen/comments/143951.htmlhttp://www.shnenglu.com/bennycen/archive/2011/04/11/143951.html#Feedback3http://www.shnenglu.com/bennycen/comments/commentRss/143951.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/143951.html闃呰鍏ㄦ枃

bennycen 2011-04-11 15:59 鍙戣〃璇勮
]]>
姘撮鍥涢亾 3-30http://www.shnenglu.com/bennycen/archive/2011/03/31/143061.htmlbennycenbennycenWed, 30 Mar 2011 16:15:00 GMThttp://www.shnenglu.com/bennycen/archive/2011/03/31/143061.htmlhttp://www.shnenglu.com/bennycen/comments/143061.htmlhttp://www.shnenglu.com/bennycen/archive/2011/03/31/143061.html#Feedback3http://www.shnenglu.com/bennycen/comments/commentRss/143061.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/143061.html闃呰鍏ㄦ枃

bennycen 2011-03-31 00:15 鍙戣〃璇勮
]]>
SRM489 Div2棰樿Вhttp://www.shnenglu.com/bennycen/archive/2010/12/01/135207.htmlbennycenbennycenWed, 01 Dec 2010 15:56:00 GMThttp://www.shnenglu.com/bennycen/archive/2010/12/01/135207.htmlhttp://www.shnenglu.com/bennycen/comments/135207.htmlhttp://www.shnenglu.com/bennycen/archive/2010/12/01/135207.html#Feedback1http://www.shnenglu.com/bennycen/comments/commentRss/135207.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/135207.html闃呰鍏ㄦ枃

bennycen 2010-12-01 23:56 鍙戣〃璇勮
]]>
ACM/ICPC鏉窞绔?- hdu3683http://www.shnenglu.com/bennycen/archive/2010/11/11/133305.htmlbennycenbennycenThu, 11 Nov 2010 06:02:00 GMThttp://www.shnenglu.com/bennycen/archive/2010/11/11/133305.htmlhttp://www.shnenglu.com/bennycen/comments/133305.htmlhttp://www.shnenglu.com/bennycen/archive/2010/11/11/133305.html#Feedback2http://www.shnenglu.com/bennycen/comments/commentRss/133305.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/133305.html闃呰鍏ㄦ枃

bennycen 2010-11-11 14:02 鍙戣〃璇勮
]]>
ACM/ICPC鏉窞绔?- hdu3687http://www.shnenglu.com/bennycen/archive/2010/11/11/133304.htmlbennycenbennycenThu, 11 Nov 2010 05:45:00 GMThttp://www.shnenglu.com/bennycen/archive/2010/11/11/133304.htmlhttp://www.shnenglu.com/bennycen/comments/133304.htmlhttp://www.shnenglu.com/bennycen/archive/2010/11/11/133304.html#Feedback0http://www.shnenglu.com/bennycen/comments/commentRss/133304.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/133304.htmlhttp://acm.hdu.edu.cn/showproblem.php?pid=3687
棰樼洰澶ф剰錛?鍦╪*m鎺掔潃n*n涓+鍏碉紝浼戞伅鏃舵暎寮(鍙兘姘村鉤鏁e紑)錛岄泦涓椂瑕侀噸鏂扮珯鎴恘*n鏂歸樀錛屾眰鎬諱綋鏈灝戠Щ鍔ㄦ鏁?br>棰樿В錛氭敞鎰忔槸鍙兘姘村鉤鏁e紑錛屾墍浠ヨ棰樹篃鎴愪負姘撮浜?br>1.鎺掑簭
2.鏋氫婦宸﹁竟鎺掑紑濮嬬珯鐨勫垪鏁幫紝妯℃嫙璁$畻姣忔绔欑殑鑺辮垂
3.杈撳嚭鏈灝忚姳璐?br>
浠g爜錛?br>
#include <stdio.h>
#include 
<math.h>
#include 
<algorithm>
using namespace std;

int n,m;

struct Point
{
    
int x;
    
int y;
    friend 
bool operator < (const Point &_p1,const Point & _p2)
    
{
        
if(_p1.x == _p2.x)
            
return _p1.y < _p2.y;
        
else
            
return _p1.x < _p2.x;
    }

}
;
Point points[
3600];

void Test()
{
    
int size = n*n;
    
int x1,y1;
    
for(int i = 0; i < size; ++i)
    
{
        scanf(
"%d %d",&x1,&y1);
        points[i].x 
= x1;
        points[i].y 
= y1;
    }

    sort(points,points
+size);

    
int ans = 1 << 30;
    
//鏋氫婦鍒楁暟
    for(int i = 1; i <= m-n+1++i)
    
{
        
int ans2 = 0;
        
int k = 0;
        
//n*n甯冨眬
        for(int x = 0; x < n; ++x)
        
{
            
for(int y = 0; y < n; ++y)
            
{
                
//姘村鉤鐩稿噺
                ans2 += abs(i+- points[k].y);
                
++k;
            }

        }

        ans 
= min(ans,ans2);
    }

    printf(
"%d\n",ans);
}


int main()
{
    
while(scanf("%d %d",&n,&m) != EOF)
    
{
        
if(n == 0 || m == 0)
            
break;
        Test();
    }

    
return 0;
}


bennycen 2010-11-11 13:45 鍙戣〃璇勮
]]>
ACM/ICPC鏉窞绔?- hdu3685http://www.shnenglu.com/bennycen/archive/2010/11/11/133300.htmlbennycenbennycenThu, 11 Nov 2010 05:41:00 GMThttp://www.shnenglu.com/bennycen/archive/2010/11/11/133300.htmlhttp://www.shnenglu.com/bennycen/comments/133300.htmlhttp://www.shnenglu.com/bennycen/archive/2010/11/11/133300.html#Feedback1http://www.shnenglu.com/bennycen/comments/commentRss/133300.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/133300.html闃呰鍏ㄦ枃

bennycen 2010-11-11 13:41 鍙戣〃璇勮
]]>
ACM/ICPC鏉窞绔?- hdu3682http://www.shnenglu.com/bennycen/archive/2010/11/10/133220.htmlbennycenbennycenWed, 10 Nov 2010 09:10:00 GMThttp://www.shnenglu.com/bennycen/archive/2010/11/10/133220.htmlhttp://www.shnenglu.com/bennycen/comments/133220.htmlhttp://www.shnenglu.com/bennycen/archive/2010/11/10/133220.html#Feedback1http://www.shnenglu.com/bennycen/comments/commentRss/133220.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/133220.html闃呰鍏ㄦ枃

bennycen 2010-11-10 17:10 鍙戣〃璇勮
]]>
ACM/ICPC鏉窞绔?- hdu3681http://www.shnenglu.com/bennycen/archive/2010/11/10/133217.htmlbennycenbennycenWed, 10 Nov 2010 08:54:00 GMThttp://www.shnenglu.com/bennycen/archive/2010/11/10/133217.htmlhttp://www.shnenglu.com/bennycen/comments/133217.htmlhttp://www.shnenglu.com/bennycen/archive/2010/11/10/133217.html#Feedback1http://www.shnenglu.com/bennycen/comments/commentRss/133217.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/133217.html闃呰鍏ㄦ枃

bennycen 2010-11-10 16:54 鍙戣〃璇勮
]]>
ACM/ICPC鏉窞绔?- hdu3680http://www.shnenglu.com/bennycen/archive/2010/11/10/133213.htmlbennycenbennycenWed, 10 Nov 2010 08:47:00 GMThttp://www.shnenglu.com/bennycen/archive/2010/11/10/133213.htmlhttp://www.shnenglu.com/bennycen/comments/133213.htmlhttp://www.shnenglu.com/bennycen/archive/2010/11/10/133213.html#Feedback3http://www.shnenglu.com/bennycen/comments/commentRss/133213.htmlhttp://www.shnenglu.com/bennycen/services/trackbacks/133213.html棰樼洰閾炬帴錛?/strong>http://acm.hdu.edu.cn/showproblem.php?pid=3680
棰樻剰錛?/strong>緇欏畾涓ゆ暟n錛宮(0< n,m < 10^500)錛岃姹傜敤涓夌鎿嶄綔(-,+,*2)瀹屾垚浠巑鍙樻崲鍒皀
棰樿В錛?/strong>鍜嬬溂鐪嬭繕浠ヤ負鏄畝鍗曟按棰橈紝http://poj.org/problem?id=3278 灝辨槸榪欓鐨勫師濮嬬増錛?br>騫朵笖榪欎釜棰樼洰涓嬮潰榪樼櫧綰擱粦瀛楀啓鏄?0<N,M<10500)錛屽寙蹇欏啓涓狟FS鎻愪氦錛岀粨鏋淩E錛屽叾瀹為鐩殑鏁版嵁鑼冨洿
搴旇鏄?<N,M<10^500銆傘傘?br>鏆存悳琛屼笉閫氾紝灝辮鏈変釜濂界偣鐨勬柟娉曪紝鎯充簡涓涓嬫兂涓嶅埌錛岀粨鏋滅湅浜嗕釜瑙i鎶ュ憡錛屾墠鐭ラ亾鎬庝箞瑙e喅

濡傛灉m > n錛氬彧鏈夊噺鎿嶄綔
濡傛灉n > m錛氬彲浠ヤ粠鍚庡線鍓嶆帹綆楋細
璁緁(x,n)琛ㄧず鏁皒鍙樻崲鍒皀闇瑕佺殑姝ユ暟 f(x,n)
閭d箞濡傛灉x涓哄鏁幫細f(x,n) = f(x/2,n) + 2
濡傛灉x涓哄伓鏁?錛歠(x,n) = f(x/2,n) + 1
褰撳墠絳旀鍗充負 abs(m-x) + f(x,m)
涓鐩磋綆楃洿鍒?*x > m 銆?br>鍙渶瑕佽綆梮鍜寈+1鐨勬鏁板嵆鍙紝濡備綍璇佹槑錛?br>浠ヤ笅浠?x,n,y)琛ㄧず錛屽叾涓瓂 = f(x,n)
 鍒嗗埆璁ㄨx鍜寈+1鐨勫鍋舵э紝(x/2,n,y1)鍜?(x+k)/2,n,y2)鐨勫ぇ灝?浣滃樊)
緇撴灉鍙戠幇褰搆>=2鏃訛紝y2 > y1銆?br>

鐢變簬瑕佸ぇ鏁幫紝鎵浠ョ敤java姣旇緝鏂逛究銆傘傘?br> 

浠g爜錛?br>
import java.io.*;
import java.util.*;
import java.math.*;

public class Main 
{    
    
public static Scanner in = new Scanner(System.in);
    
public static BigInteger Abs(BigInteger num)
    
{
        
return num.abs();
    }

    
public static BigInteger Min(BigInteger num1,BigInteger num2)
    
{
        
return num1.min(num2);
    }

    
public static void main(String[] args) 
    
{
        BigInteger n,m;
        
while(true)
        
{
            n 
= in.nextBigInteger();
            m 
= in.nextBigInteger();
            
if((n.compareTo(BigInteger.ZERO) == 0|| (m.compareTo(BigInteger.ZERO) == 0))
            
{
                
break;
            }

            
else
            
{
                
if(m.compareTo(n) > 0)
                
{
                    System.out.println(m.subtract(n));
                }

                
else
                
{
                    BigInteger x1,x2,y1,y2,x;
                    x 
= n;
                    x1 
= BigInteger.ZERO;
                    x2 
= BigInteger.ONE;
                    BigInteger ans 
= n.subtract(m);
                    
while(x.multiply(BigInteger.valueOf(2)).compareTo(m) > 0)
                    
{
                        
//x涓哄伓鏁?/span>
                        if(x.mod(BigInteger.valueOf(2)).compareTo(BigInteger.ZERO) == 0)
                        
{
                            y1 
= Min(x1.add(BigInteger.valueOf(1)),x2.add(BigInteger.valueOf(2)));
                            
//x+1涓哄鏁?/span>
                            y2 = Min(x1.add(BigInteger.valueOf(2)),x2.add(BigInteger.valueOf(2)));
                        }

                        
else
                        
{
                            
//x涓哄鏁?/span>
                            y1 = Min(x1.add(BigInteger.valueOf(2)),x2.add(BigInteger.valueOf(2)));
                            
//x+1涓哄伓鏁?/span>
                            y2 = Min(x1.add(BigInteger.valueOf(2)),x2.add(BigInteger.valueOf(1)));
                        }


                        x 
= x.divide(BigInteger.valueOf(2));
                        x1 
= y1;
                        x2 
= y2;
                        
//x鐨勬鏁?/span>
                        ans = Min(ans,Abs(x.subtract(m)).add(y1));
                        
//x+1鐨勬鏁?/span>
                        ans = Min(ans,Abs(x.subtract(m).add(BigInteger.ONE)).add(y2));
                    }


                    System.out.println(ans);
                }

            }

        }

    }

}



bennycen 2010-11-10 16:47 鍙戣〃璇勮
]]>
韩国三级中文字幕hd久久精品| 久久精品国产精品亚洲人人| 久久93精品国产91久久综合| 久久精品人人做人人爽97| 精品久久久一二三区| 亚洲欧洲久久久精品| 热综合一本伊人久久精品| 国产精品无码久久四虎| 国产精品99久久不卡| 99久久www免费人成精品| 99久久综合国产精品二区| 欧美亚洲国产精品久久蜜芽| 青青青国产成人久久111网站| 国产精品久久久久天天影视| 2022年国产精品久久久久| 久久精品成人免费看| 成人国内精品久久久久影院VR| 狠狠色综合网站久久久久久久 | 欧美亚洲国产精品久久久久| 欧美成a人片免费看久久| 国内精品久久国产| 久久久一本精品99久久精品88| 国产一区二区三区久久| 国产叼嘿久久精品久久| 亚洲欧美国产精品专区久久 | 中文字幕久久久久人妻| 久久不见久久见免费视频7| 99久久婷婷国产一区二区| 一97日本道伊人久久综合影院| 久久久久久久波多野结衣高潮| 久久久久人妻精品一区二区三区 | 久久国产成人午夜aⅴ影院| 一本色道久久88综合日韩精品 | 很黄很污的网站久久mimi色| 精品久久8x国产免费观看| 91精品国产91久久久久久青草 | 国产亚洲美女精品久久久2020| 久久w5ww成w人免费| 久久午夜无码鲁丝片午夜精品| 色欲久久久天天天综合网| 精品久久久中文字幕人妻 |