日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UVa 12096 The SetStack Computer 【STL】【stack】

發(fā)布時(shí)間:2024/3/13 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UVa 12096 The SetStack Computer 【STL】【stack】 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目鏈接:點(diǎn)擊打開鏈接

紫書116頁

AC代碼:

#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> #include <set> #include <map> #include <vector> #include <stack> using namespace std; #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x, x.begin()) typedef set<int> Set; map<Set,int> IDcache; vector<Set> Setcache;int ID(Set x) {if(IDcache.count(x)) return IDcache[x];Setcache.push_back(x);return IDcache[x] = Setcache.size() - 1; }int main() {int t, n;while(~scanf("%d",&t)){while(t--){stack<int> s;scanf("%d",&n);while(n--){string op;cin >> op;if(op[0] == 'P') s.push(ID(Set()));else if (op[0] == 'D') s.push(s.top());else{Set x1 = Setcache[s.top()]; s.pop();Set x2 = Setcache[s.top()]; s.pop();Set x;if(op[0] == 'U') set_union(ALL(x1), ALL(x2), INS(x));if(op[0] == 'I') set_intersection(ALL(x1), ALL(x2), INS(x));if(op[0] == 'A') { x = x2; x.insert(ID(x1)); }s.push(ID(x));}cout << Setcache[s.top()].size() << endl;}cout << "***" << endl;}}return 0; }

幾個(gè)用法: s.empty()?????? //堆棧空為真 s.pop()?????????? //移除棧頂元素 s.push()???????? //在棧頂增加元素 s.size()????????? //返回棧中元素?cái)?shù)目 s.top()??????????? //返回棧頂元素


STL內(nèi)置函數(shù)

set_union 求交集

set_intersection 求并集

總結(jié)

以上是生活随笔為你收集整理的UVa 12096 The SetStack Computer 【STL】【stack】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。