• <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 閱讀(838) 評論(1)  編輯 收藏 引用 所屬分類: 動態規劃
            Comments
             
            72种姿势欧美久久久久大黄蕉| 久久国产精品一国产精品金尊| 欧美亚洲日本久久精品| 俺来也俺去啦久久综合网| 99久久精品国产毛片| 久久久99精品成人片中文字幕 | 国产美女亚洲精品久久久综合| 欧美牲交A欧牲交aⅴ久久| 久久99国产一区二区三区| 亚洲成色WWW久久网站| 久久国产三级无码一区二区| 久久99久久99精品免视看动漫| 性高湖久久久久久久久AAAAA| 国产精品视频久久久| 中文无码久久精品| 久久夜色精品国产噜噜亚洲a| 久久精品国产99国产精偷 | 一极黄色视频久久网站| 色综合久久最新中文字幕| 色偷偷偷久久伊人大杳蕉| 一级做a爰片久久毛片看看| 国产精品成人99久久久久91gav| .精品久久久麻豆国产精品| 囯产极品美女高潮无套久久久 | 久久久无码一区二区三区| 亚洲精品午夜国产va久久| 日本精品久久久久影院日本| www亚洲欲色成人久久精品| 国产精品久久久久久吹潮| 久久久久人妻一区二区三区vr | 国内精品久久久久久99| 精品国际久久久久999波多野| 久久久国产精华液| 亚洲午夜无码久久久久| 亚洲色欲久久久综合网东京热| 亚洲午夜久久久| 亚洲精品国产美女久久久| 国产午夜福利精品久久2021| 久久国产亚洲精品麻豆| 国产精品美女久久久网AV| 久久亚洲天堂|