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

            f(sixleaves) = sixleaves

            重劍無鋒 大巧不工

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              95 隨筆 :: 0 文章 :: 7 評論 :: 0 Trackbacks
             1 #include <set>
             2 #include <string>
             3 #include <vector>
             4 #include <map>
             5 #include <stack>
             6 #include <iostream>
             7 #include <algorithm>
             8 #define ALL(x) x.begin(), x.end()
             9 #define INS(x) inserter(x, x.begin())
            10 
            11 using namespace std;
            12 
            13 typedef set<int> Set;
            14 map<Set, int> IDCache;
            15 vector<Set> Setcache;
            16 // 主要的想法是能想到用map<set<int>, int>這種數據結構來把集合映射成整數
            17 // 關鍵實現在ID函數,對于給定的set<int>都能返回一個唯一編號、vector雖然不能保證元素的唯一性。
            18 // 但是我們可以先對map進行檢查來保證vector中元素的唯一性,這樣每個元素就能唯一編號,剛好可以利用他們的整數索引。
            19 // 其中set_union、set_intersection中得實現原理不是重點,先學會怎么用才是重點。
            20 // ID函數實現了對新的集合存儲,并且
            21 int ID(Set x);
            22 int main() {
            23 
            24     
            25     stack<int> s;
            26     int t, n;
            27     string op;
            28     cin >> t;
            29     while (t--) {
            30         cin >> n;
            31         IDCache.clear();
            32         Setcache.clear();
            33         for (int i = 0; i < n; i++) {
            34 
            35             cin >> op;
            36             if (op[0] == 'P') s.push(ID(Set())); // Set()就是空集
            37             else if(op[0] == 'D') s.push(s.top());
            38             else {
            39                 
            40                 Set x1 = Setcache[s.top()]; s.pop();
            41                 Set x2 = Setcache[s.top()]; s.pop();
            42                 Set x;
            43                 if (op[0] == 'U') set_union (ALL(x1), ALL(x2), INS(x));
            44                 if (op[0] == 'I') set_intersection (ALL(x1), ALL(x2), INS(x));
            45                 if (op[0] == 'A') { x = x2; x.insert(ID(x1)); }
            46                 s.push(ID(x));
            47                 
            48             }
            49             
            50             cout << Setcache[s.top()].size() << endl;
            51         }
            52         cout << "***" << endl;
            53     
            54     }
            55     return 0;
            56 }
            57 
            58 // 相當于數據庫中得auto_increment, 返回一個唯一的ID值
            59 int ID(Set x) {
            60     
            61     if (IDCache.count(x)) return IDCache[x];
            62     Setcache.push_back(x);
            63     return IDCache[x] = Setcache.size() - 1;
            64 
            65 }
            posted on 2015-03-23 22:29 swp 閱讀(168) 評論(0)  編輯 收藏 引用 所屬分類: algorithm
            久久热这里只有精品在线观看| 久久久精品人妻无码专区不卡| 伊人久久大香线蕉无码麻豆| 欧美一级久久久久久久大| 亚洲va中文字幕无码久久| 久久不射电影网| 久久一本综合| 99久久综合狠狠综合久久止| 久久久91人妻无码精品蜜桃HD| 欧美黑人激情性久久| 一级做a爰片久久毛片人呢| 欧美精品一区二区久久| 97r久久精品国产99国产精| 久久久久亚洲爆乳少妇无| 九九精品99久久久香蕉| 中文成人久久久久影院免费观看 | 久久精品国产精品亚洲人人 | 亚洲а∨天堂久久精品9966| 伊人久久大香线蕉AV色婷婷色| 国产精品免费久久| 久久久女人与动物群交毛片| 久久久久国产精品麻豆AR影院 | 国产精品99久久久久久董美香| 久久久黄色大片| 久久国产成人精品国产成人亚洲| 99久久精品费精品国产一区二区| 久久99国产精品久久99小说 | 久久精品中文无码资源站| 亚洲欧美成人久久综合中文网| 国产精品免费久久久久影院| 久久偷看各类wc女厕嘘嘘| 精品久久久久久久久免费影院| 久久久久久久久久免免费精品| 99久久综合国产精品二区| 国产精品久久久久影院嫩草| 狠狠狠色丁香婷婷综合久久五月| 久久久久久无码Av成人影院| 色诱久久久久综合网ywww| 久久综合88熟人妻| 丰满少妇人妻久久久久久| 国内精品久久久久影院一蜜桃|