• <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>

            poj1201

            Intervals

            Time Limit: 2000MS Memory Limit: 65536K
            Total Submissions: 15733 Accepted: 5871

            Description

            You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.
            Write a program that:
            reads the number of intervals, their end points and integers c1, ..., cn from the standard input,
            computes the minimal size of a set Z of integers which has at least ci common elements with interval [ai, bi], for each i=1,2,...,n,
            writes the answer to the standard output.

            Input

            The first line of the input contains an integer n (1 <= n <= 50000) -- the number of intervals. The following n lines describe the intervals. The (i+1)-th line of the input contains three integers ai, bi and ci separated by single spaces and such that 0 <= ai <= bi <= 50000 and 1 <= ci <= bi - ai+1.

            Output

            The output contains exactly one integer equal to the minimal size of set Z sharing at least ci elements with interval [ai, bi], for each i=1,2,...,n.

            Sample Input

            5
            3 7 3
            8 10 3
            6 8 1
            1 3 1
            10 11 1

            Sample Output

            6
            這題最多可能有5w的點,但是給的邊數有5w
            而且要注意的是 對每個區間[i-1,i]都有>=0 <=1的條件
            如果直接建圖的話,邊數可能有15w
            所以時間上bellman_ford 可能很難承受
            所有要優化
            對于那些默認的條件,顯然我們可以不用把這些邊加進去,
            在每次判斷時候,判斷一邊即可
            對于bellman_ford 還有優化是,如果一次循環中沒有修改任何值,則說明bellman_ford已經得到解了,
            沒必要繼續執行了 直接推出就行了
            目標是求dist[mx]-dist[mn]
            #include<algorithm>
            #include
            <iostream>
            #include
            <cstring>
            #include
            <cstdio>
            #include
            <cstdlib>
            #include
            <string>
            #include
            <cmath>
            using namespace std;
            #define inf 0x7ffffff
            #define max 50004
            struct node 
            {
                
            int u,v,w;
            }
            edge[max];
            int n,dist[max],mn,mx;
            void init()
            {
                
            int i;
                
            for(i=0;i<max;i++) dist[i]=0;
                mx
            =1;mn=inf;
            }

            void bellman_ford()
            {
                
            int k,t;
                
            bool flag=true;
                
            while(flag)
                
            {
                    flag
            =false;
                    
            for(k=0;k<n;k++)
                    
            {
                        t
            =dist[edge[k].u]+edge[k].w;
                        
            if (dist[edge[k].v]>t)
                        
            {
                            dist[edge[k].v]
            =t;
                            flag
            =true;
                        }

                    }

                    
            for(k=mn;k<mx;k++)
                    
            {
                        t
            =dist[k-1]+1;
                        
            if (dist[k]>t)
                        
            {
                            dist[k]
            =t;
                            flag
            =true;
                        }

                    }

                    
            for(k=mn;k<mx;k++)
                    
            {
                        
            if (dist[k-1]>dist[k])
                        
            {
                            dist[k
            -1]=dist[k];
                            flag
            =true;
                        }

                    }

                }

            }

            int main()
            {
                
            int i,u,v,w;
                
            while (scanf("%d",&n)!=EOF)
                
            {
                    
            for(i=0;i<n;i++)
                    
            {
                        scanf(
            "%d%d%d",&u,&v,&w);
                        edge[i].u
            =v;
                        edge[i].v
            =u-1;
                        edge[i].w
            =-w;
                        
            if (u<mn)
                        
            {
                            mn
            =u;
                        }

                        
            if (v>mx)
                        
            {
                            mx
            =v;
                        }

                    }

                    bellman_ford();
                    printf(
            "%d\n",dist[mx]-dist[mn-1]);
                }

                
            return 0;
            }

            posted on 2012-04-03 17:38 jh818012 閱讀(186) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            久久er国产精品免费观看2| 久久综合色区| 久久国产福利免费| 人妻无码精品久久亚瑟影视| 久久精品桃花综合| 久久99久久99精品免视看动漫| 久久国产亚洲精品麻豆| 国产成人综合久久久久久| 久久久久久久波多野结衣高潮 | 欧美一级久久久久久久大| 亚洲国产成人精品91久久久| 久久A级毛片免费观看| 青青青伊人色综合久久| 亚洲综合伊人久久大杳蕉| 久久99精品久久久久久齐齐| 亚洲综合熟女久久久30p| 久久精品国产欧美日韩| 久久亚洲AV成人无码国产| 97视频久久久| 日韩亚洲国产综合久久久| 久久99国产综合精品女同| 无码伊人66久久大杳蕉网站谷歌| 伊人久久无码精品中文字幕| 久久久青草久久久青草| 国产精品99久久久精品无码 | 国产真实乱对白精彩久久| 久久婷婷五月综合国产尤物app| 久久久久久久亚洲精品 | 久久e热在这里只有国产中文精品99| 亚洲伊人久久精品影院| 伊人久久大香线蕉综合5g| 久久久久国产| 久久久久一本毛久久久| 国产激情久久久久影院老熟女| 婷婷久久久亚洲欧洲日产国码AV | 久久亚洲国产精品成人AV秋霞| 久久精品国产色蜜蜜麻豆| 国产激情久久久久影院老熟女免费| 国产精品一久久香蕉国产线看 | 久久强奷乱码老熟女| 亚洲国产成人久久精品动漫|