P3879 [TJOI2010]阅读理解
我永远喜欢STL
显然要用到哈希类似的东西,说到哈希我就想到了map。
但是map怎么存一串数字还不MLE啊?说到存一串数字还不MLE我就先到了vector。
所以这道题的做法就是搞一个map<string,vector<int> >
,暴力解决。
WA警告:输出的序号要去重。比如样例里面查ha
只能有一个1。
听说数据能卡trie树,可惜没卡STL。
/*************************************************************************
@Author: Garen
@Created Time : Sun 10 Mar 2019 10:02:21 AM CST
@File Name: P3879.cpp
@Description:
************************************************************************/
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
#define ll long long
std::map<string,vector<int> > mmp;
int n, m;
int main() {
std::ios::sync_with_stdio(false);
string str;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> m;
while(m--) {
cin >> str;
mmp[str].push_back(i);
}
}
cin >> m;
while(m--) {
cin >> str;
auto vec = mmp[str];
for(auto it = vec.begin(), pre = vec.begin(); it != vec.end(); pre = it, ++it) {
if(it == vec.begin()) {
cout << *it;
} else {
if(*pre == *it) continue;
else cout << ' ' << *it;
}
}
cout << endl;
}
return 0;
}