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

            ArcTan

            dfs
            隨筆 - 16, 文章 - 117, 評論 - 6, 引用 - 0
            數據加載中……

            hdu 2419 (STL:set multiset)

            首先膜拜膜拜青島二中的 aKc大牛啊,我徹底給跪了?。?!
            差距太大,好好努力吧?。?!

            算法,數據結構,C++,STL。需要去學的啊,下午開始學吧學吧

            圖的操作,使用集合來維護,把操作序列倒過來看,割邊則看做兩個集合的合并。

            STL 的set和multiset 很強大啊,第一用STL寫東西

            wangs ,你該努力了,大牛之路,遠著呢。
            #include <cstdlib>
            #include 
            <cctype>
            #include 
            <cstring>
            #include 
            <cstdio>
            #include 
            <cmath>
            #include 
            <algorithm>
            #include 
            <vector>
            #include 
            <string>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <queue>
            #include 
            <stack>
            #include 
            <fstream>
            #include 
            <numeric>
            #include 
            <iomanip>
            #include 
            <bitset>
            #include 
            <list>
            #include 
            <stdexcept>
            #include 
            <functional>
            #include 
            <utility>
            #include 
            <ctime>
            #include 
            <cmath>
            #include 
            <climits>

            using namespace std;

            typedef pair
            <intint> PII;
            const int MAXN = 20010, MAXM = 60010, MAXQ = 300010;
            int value[MAXN], query[MAXQ][3];
            multiset
            <PII> e;
            multiset
            <int> v[MAXN];
            int pre[MAXN];

            int root(int a)
            {
                
            if(pre[a] != a)
                    pre[a] 
            = root(pre[a]);
                
            return pre[a];
            }

            int unionSet(int a, int b)
            {
                multiset
            <int>::iterator it;
                a 
            = root(a), b = root(b);
                
            if(a == b)
                    
            return 0;
                
            if(v[a].size() > v[b].size())
                    swap(a, b);
                
            for    (it = v[a].begin(); it != v[a].end(); it++)
                    v[b].insert(
            *it);
                v[a].clear();
                pre[a] 
            = b;
                
            return 0;
            }

            int update(int a, int x)
            {
                
            int ta = a;
                a 
            = root(a);
                v[a].erase(v[a].find(value[ta]));
                v[a].insert(x);
                value[ta] 
            = x;
                
            return 0;
            }

            int main()
            {
                
            int n, m, q;
                
            int a, b;
                
            int i,u;
                
            int cas=0;
                
            char ch[3];
                
            double ct = 0, sum = 0;
                multiset
            <PII>::iterator it;
                multiset
            <int>::iterator tp;
                
            while(scanf("%d%d%d",&n,&m,&q)==3)
                {
                    e.clear();
                    
            for (i = 1; i <= n; i++)
                        v[i].clear();

                    
            for (i = 1; i <= n; i++)
                    {
                        scanf(
            "%d"&value[i]);
                        pre[i] 
            = i;
                    }
                    
            for (i = 0; i < m; i++)
                    {
                        scanf(
            "%d%d"&a, &b);
                        
            if(a > b)
                            swap(a, b);
                        e.insert(PII(a, b));
                    }

                    
            for (i = 0; i < q; i++)
                    {
                        scanf(
            "%s"&ch);
                        scanf(
            "%d%d"&query[i][1], &query[i][2]);

                        query[i][
            0= ch[0];
                        
            if(ch[0== 'E')
                        {
                            
            if(query[i][1> query[i][2])
                                swap(query[i][
            1], query[i][2]);

                            it 
            = e.find(PII(query[i][1], query[i][2]));
                            e.erase(it);
                        }
                        
            else if(ch[0== 'U')
                            swap(value[query[i][
            1]], query[i][2]);
                    }

                    
            for (i = 1; i <= n; i++)
                        v[i].insert(value[i]);
                    
            for (it = e.begin(); it != e.end(); it++)
                        unionSet(it
            ->first, it->second);

               
            //     for (it = e.begin(); it != e.end(); it++)
                
            //        printf("%d %d\n",it->first, it->second);

                    ct
            =0;
                    sum
            =0;

                    
            for(int i = q - 1; i >= 0; i--)
                    {
                        
            if(query[i][0== 'E')
                            unionSet(query[i][
            1], query[i][2]);
                        
            else if(query[i][0== 'U')
                            update(query[i][
            1], query[i][2]);
                        
            else
                        {
                            ct 
            += 1;
                            u 
            = root(query[i][1]);
                            tp 
            = v[u].lower_bound(query[i][2]);
                            
            if(tp != v[u].end())
                                sum 
            += *tp;
                      
            //      printf("%d %d\n",u,*tp);
                        }
                    }
                    printf(
            "Case %d: %0.3lf\n",++cas,(double)sum/ct);
                }
                
            return 0;
            }

            posted on 2012-07-14 13:08 wangs 閱讀(265) 評論(0)  編輯 收藏 引用 所屬分類: ACM-數據結構

            伊人久久久AV老熟妇色| 99久久精品国产一区二区三区| 久久精品成人影院| 久久久久久亚洲精品不卡| 久久久精品国产亚洲成人满18免费网站| 久久精品国产一区二区三区不卡 | 亚洲精品乱码久久久久久蜜桃图片 | 中文字幕亚洲综合久久| 久久精品无码一区二区三区日韩| 狠狠色丁香婷婷久久综合| 青草国产精品久久久久久| 久久精品99无色码中文字幕| 亚洲愉拍99热成人精品热久久| 草草久久久无码国产专区| 99久久无色码中文字幕人妻| 国产一区二区精品久久凹凸 | 久久久精品久久久久影院| 2021精品国产综合久久| 热99RE久久精品这里都是精品免费| 日本道色综合久久影院| 亚洲AV无码一区东京热久久| 亚洲一区精品伊人久久伊人| 91亚洲国产成人久久精品网址| 亚洲中文字幕久久精品无码APP| 久久久久这里只有精品| 97超级碰碰碰碰久久久久| 久久精品国产亚洲AV无码娇色| 精品久久久久久无码不卡| 亚洲伊人久久成综合人影院| 精品99久久aaa一级毛片| 国产精品福利一区二区久久| 久久久久人妻精品一区二区三区| 亚洲欧洲精品成人久久曰影片 | 久久国产成人午夜aⅴ影院| 99久久免费国产精品热| 粉嫩小泬无遮挡久久久久久| 午夜久久久久久禁播电影| 性欧美大战久久久久久久久| 久久精品中文字幕一区| 久久人人爽人人爽人人片AV高清| 日本五月天婷久久网站|