zoukankan      html  css  js  c++  java
  • 【紫书】(UVa12096) The SetStack Computer

    突然转进到第五章的low题目的原因是做到图论了(紫书),然后惊喜的发现第一题就做不出来。那么里面用到了这一题的思想,我们就先解决这题。当然,dp必须继续做下去,这是基本功。断不得。

    题意分析

    这条题真的是一条sb模拟题。但是我们还是可以学些什么:一,标id的思想(后面用到了,就是那条UVa12219)。二,set的基本操作。具体思路看代码。但是这题哪里有什么算法...set 和 map 混合应用,真的用板子写的话代码相近度很高

    代码

    #include <bits/stdc++.h>
    
    #define NQUICKIO
    #define ALL(x) x.begin(),x.end()
    #define INS(x) inserter(x,x.begin())
    #define REP(x) for(int i=0;i!=(x);++i)
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    
    map<set<int>, int> m;
    vector<set<int> > idxm;
    inline int ID(set<int>& _s)
    {
        if(m.find(_s)!=m.end()) return m[_s];
        idxm.push_back(_s);
        return m[_s]=idxm.size()-1;
    }
    
    
    int main()
    {
    #ifdef QUICKIO
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
    #endif
        int kase; cin>>kase;
    
        while(kase--)
        {
            m.clear();
            stack<int> s;
            int n; cin>>n;
            for(int i=1;i<=n;++i)
            {
                string tmpstr; cin>>tmpstr;
                if(tmpstr[0]=='P')
                {
                    set<int> tmp;
                    s.push(ID(tmp));
                }
                else if(tmpstr[0]=='D')
                    s.push(s.top());
                else
                {
                    auto s1=idxm[s.top()]; s.pop();
                    auto s2=idxm[s.top()]; s.pop();
                    set<int> tmps;
                    if(tmpstr[0]=='U')
                        set_union(ALL(s1),ALL(s2),INS(tmps));
                    if(tmpstr[0]=='I')
                        set_intersection(ALL(s1),ALL(s2),INS(tmps));
                    if(tmpstr[0]=='A')
                    {
                        tmps=s2; tmps.insert(ID(s1));
                    }
                    s.push(ID(tmps));
                }
                cout<<idxm[s.top()].size()<<endl;
            }
            cout<<"***"<<endl;
        }
        return 0;
    }
    如非注明,原创内容遵循GFDLv1.3发布;其中的代码遵循GPLv3发布。
  • 相关阅读:
    3.springMVC参数绑定过程(页面向后台传参)
    2.springMVC入门程序
    1.理解springMVC的原理
    RTO
    DC Congestion Control
    docs for DC Network
    FCT和QCT
    下行TM
    上行TM
    调度与队列
  • 原文地址:https://www.cnblogs.com/samhx/p/UVa-12096.html
Copyright © 2011-2022 走看看