【链接】 我是链接,点我呀:)
【题意】
【题解】
用set【错的次数】
在这里输入错的次数【反思】
这种一层套一层的方法好巧妙。。【代码】
#include <bits/stdc++.h>
using namespace std;
typedef set<int> Set;
map <Set, int> mymap;
stack <int> sta;
vector <Set> what;
int ID(Set x)
{
if (mymap.find(x) != mymap.end()) return mymap[x];
what.push_back(x);
mymap[x] = (int)what.size() - 1;
return mymap[x];
}
int main()
{
//freopen("F:\rush.txt", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--)
{
what.clear();
while (!sta.empty()) sta.pop();
mymap.clear();
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
if (s[0] == 'P')
sta.push(ID(Set()));
else
if (s[0] == 'D')
sta.push(sta.top());
else
{
Set x = what[sta.top()]; sta.pop();
Set y = what[sta.top()]; sta.pop();
Set temp;
if (s[0] == 'U')
set_union(x.begin(), x.end(), y.begin(), y.end(), inserter(temp, temp.begin()));
if (s[0] == 'I')
set_intersection(x.begin(), x.end(), y.begin(), y.end(), inserter(temp, temp.begin()));
if (s[0] == 'A')
{
temp = y;
temp.insert(ID(x));
}
sta.push(ID(temp));
}
cout << (int)what[sta.top()].size() << endl;
}
cout << "***" << endl;
}
return 0;
}