• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            A O(NM) dynamic programming algorithm is quite apparent after sorting the computers and network interfaces by their coordinates. Furthermore, in any optimized case, for each computer the difference between the the indices of the network interfaces matching to and closest to the computer is never larger than N. So the complexity could be reduced to O(N2)


            有很多細節不好考慮,應該是我的水平原因。最后我向updog要了數據才過的。而且代碼寫的不好。將就看一下吧。

            /*************************************************************************
            Author: WHU_GCC
            Created Time: 2000-9-10 14:03:51
            File Name: pku3375.cpp
            Description: 
            ***********************************************************************
            */

            #include 
            <iostream>
            using namespace std;

            #define out(x) (cout << #x << ": " << x << endl)
            typedef 
            long long int64;
            const int maxint = 0x7FFFFFFF;
            const int64 maxint64 = 0x7FFFFFFFFFFFFFFFLL;
            template 
            <class T> void show(T a, int n) for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl; }
            template 
            <class T> void show(T a, int r, int l) for (int i = 0; i < r; ++i) show(a[i], l); cout << endl; }

            const int maxm = 100010;

            int n, m;
            int interface[maxm];
            int computer[maxm];
            int f[2][maxm];
            int last[2];

            int main()
            {
                
            while (scanf("%d%d"&m, &n) != EOF)
                
            {
                    
            for (int i = 1; i <= m; i++)
                        scanf(
            "%d"&interface[i]);
                    
            for (int i = 1; i <= n; i++)
                        scanf(
            "%d"&computer[i]);
                    
                    sort(
            interface + 1interface + 1 + m);
                    sort(computer 
            + 1, computer + 1 + n);

                    
            for (int i = 0; i <= m; i++)
                        f[
            1][i] = maxint;

                    
            for (int i = 0; i <= m; i++)
                        f[
            0][i] = 0;

                    last[
            0= 0;

                    
            for (int i = 1; i <= n; i++)
                    
            {
                        
            int l = 1;
                        
            int r = m;
                        
            while (l + 1 < r)
                        
            {
                            
            int mid = (l + r) / 2;
                            
            if (interface[mid] >= computer[i])
                                r 
            = mid;
                            
            else
                                l 
            = mid;
                        }

                        
            int st = max(l - n - 11);
                        
            int ed = min(l + n + 1, m);
                        
            int now = i % 2;
                        
            int prev = (i + 1% 2;
                        last[now] 
            = ed;
                        
            for (int j = st; j <= ed; j++)
                        
            {
                            
            if (f[prev][j - 1!= maxint)
                                f[now][j] 
            <?= f[prev][j - 1+ abs(computer[i] - interface[j]);
                            
            else if (last[prev] < j - 1)
                                f[now][j] 
            <?= f[prev][last[prev]] + abs(computer[i] - interface[j]);
                            f[now][j] 
            <?= f[now][j - 1];
                        }

                        
            for (int j = 0; j <= m; j++)
                            f[prev][j] 
            = maxint;
                    }

                    
            int ans = maxint;
                    
            for (int i = 0; i <= m; i++)
                        ans 
            <?= f[n % 2][i];

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

                
            return 0;
            }
            posted on 2007-09-11 22:28 Felicia 閱讀(823) 評論(1)  編輯 收藏 引用 所屬分類: 動態規劃
            Comments
             
            国产精品成人99久久久久| 97精品依人久久久大香线蕉97| 久久精品国产亚洲AV无码娇色| 久久青青草原精品国产| 久久93精品国产91久久综合| 思思久久99热只有频精品66| 777米奇久久最新地址| 久久露脸国产精品| 99久久久精品免费观看国产| 欧美成a人片免费看久久| 一本一道久久综合狠狠老| 嫩草影院久久国产精品| 欧美黑人激情性久久| 国产AV影片久久久久久| 亚洲国产精品高清久久久 | 四虎国产精品成人免费久久| 国产成人久久精品激情 | 久久亚洲AV成人无码| 久久AⅤ人妻少妇嫩草影院| 无码国产69精品久久久久网站| 国产精品日韩深夜福利久久| 日韩久久久久久中文人妻| 伊人热热久久原色播放www| 狠狠色伊人久久精品综合网| 东京热TOKYO综合久久精品| 无码人妻久久一区二区三区免费丨| 久久久久香蕉视频| 88久久精品无码一区二区毛片 | 亚洲а∨天堂久久精品9966| 国内精品久久久久久久coent| 久久久av波多野一区二区| 久久久久久亚洲精品成人| 无码国内精品久久人妻蜜桃 | 久久久久亚洲AV无码专区网站 | 久久亚洲精品视频| 99久久国语露脸精品国产| 久久国产色AV免费看| 国产综合久久久久久鬼色| 国产精品久久久久9999| 国产69精品久久久久99| 草草久久久无码国产专区|