本文整理汇总了C++中unordered_map::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::clear方法的具体用法?C++ unordered_map::clear怎么用?C++ unordered_map::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_map
的用法示例。
在下文中一共展示了unordered_map::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, i = 0;
while(cin >> n){
v.clear();
inc.clear();
topo.clear();
order.clear();
string line, line2;
while(n--){ //read all nodes
cin >> line;
v[line];
inc[line] = 0;
order[line] = n;
}
cin >> m;
while(m--){ //read vertex
cin >> line >> line2;
v[line].push_back(line2);
++inc[line2];
}
topo_sort();
//prints answer
cout << "Case #" << ++i << ": Dilbert should drink beverages in this order:";
for(auto &a: topo) cout << " " << a;
cout << ".\n\n";
}
return 0;
}
示例2: main
int main(){
string input;
while(cin>>input){
char c1 = input[0], c2 = input[2];
adjacency[c1].push_back(c2);
}
for(int i = 65; i < 91; i++){
to_print = false;
complete.clear();
visited.clear();
char terminal = ';';
char start = i;
if(!visited[start]){
if(cycle_found(start)&&to_print){
incycle.push_back(start);
//cout<<start<<' ';
break;
}
}
}
sort(incycle.begin(), incycle.end());
for(int i = 0; i < incycle.size(); i++){
cout<<incycle[i]<<' ';
}
}
示例3: main
int main(){
cout << setprecision(6)<<fixed;
int t;
cin >> t;
set<int> s;
map<int, int> convert;
while(t--){
dm.clear();
dc.clear();
s.clear();
convert.clear();
cin >> n;
double f, fa;
for(int k=0;k<n;k++){
f=(double)k/(double)(n-1.0);
fa=f;
alpha[k]=0;
for(int i=0;i<1000;i++){
alpha[k] +=fa;
fa *=f;
}
}
for(int k=0;k<(n*n);k++){
f=(double)k/(double)((n*n));
fa=f;
beta[k]=0;
for(int i=0;i<1000;i++){
beta[k] +=fa;
fa *=f;
}
}
for(int i=0;i<n;i++){
cin >> a[i];
s.insert(a[i]);
}
int p = 0;
for(auto k: s){
if(convert.find(k) == convert.end()){
convert[k] = p;
}
p++;
}
int m=0;
for(int i=0;i<n;i++){
a[i] = convert[a[i]];
m = setm(m,i,a[i]);
}
cout<<"Monty "<<M(m)<<" Carlos "<<C(m)<<endl;
}
}
示例4: solve
void solve(int start, string &s, vector<string> &words)
{
//m stores info, m1 stores current info
unordered_map<string, int>::iterator it;
int p1 = start, p2 = start, len = words[0].length(), cur = 0;
m1.clear();
while(p2 + len - 1 < s.length())
{
while(cur != m.size() && p2 + len - 1 < s.length())
{
string tmp = s.substr(p2, len);
it = m.find(tmp);
if(it == m.end())
{
p2 += len;
p1 = p2;
cur = 0;
m1.clear();
continue;
}
else if(it->second == m1[tmp])
{
string tmp2 = "";
while(p1 != p2 && tmp2 != tmp)
{
tmp2 = s.substr(p1, len);
if(m1.find(tmp2) != m1.end())
{
if(m1[tmp2] == m[tmp2])
cur--;
m1[tmp2]--;
}
p1 += len;
}
continue;
}
m1[tmp]++;
if(it->second == m1[tmp])
cur++;
p2 += len;
}
while(cur == m.size() && p1 <= p2)
{
ans.push_back(p1);
string tmp = s.substr(p1, len);
it = m1.find(tmp);
if(it == m1.end())
{
p1 += len;
continue;
}
it->second--;
if(it->second < m[tmp])
cur--;
p1 += len;
}
}
}
示例5: maxPathSum
int maxPathSum(TreeNode *root){
if(root == NULL)
return 0;
pathSum.clear();
nodeSum.clear();
dfs(root);
return dfsMax(root);
}
示例6: gao_TF_IDF
void gao_TF_IDF(char * dim_items_txt){
fstream item_values_file(dim_items_txt); // for item's value
int tot = 0, now = 0;
// get item's value vector --------
LL item, cat; string values_string;
double st = clock();
while(item_values_file >> item >> cat >> values_string){
assert(item < M);
if (now++ % SHOW == 0)
cerr<<"now:\t"<<now<<"\titem:\t"<<item<<"\tcat\t"<<cat<<"\tvs\t"<<values_string<<endl;
vector<LL> values;
stringstream ss(values_string);
LL val; char douhao;
while(ss >> val){
ss >> douhao;
assert(douhao == ',' || douhao == '\n');
values.push_back(val);
item_value_times[item][val]++;
}
if ((now - 1) % SHOW == 0){ for (int i = 0; i < values.size(); i++) cerr<<" "<<values[i]; cerr<<"\n"; }
sort(values.begin(), values.end());
//values.erase(unique(values.begin(), values.end()), values.end());
int sz = unique(values.begin(), values.end()) - values.begin();
for (int i = 0; i < sz; i++){ // must unique for idf
value_times[values[i]]++;
}
item_values[item] = values;
item_cat[item] = cat;
cat_items[cat].push_back(item);
tot++;
}
now = 0;
for (unordered_map<LL, vector<LL> >::iterator it = item_values.begin(); it != item_values.end(); it++){
LL item = it->first;
vector<LL> & v = it->second;
if (now++ % SHOW == 0)
cerr<<"now:\t"<<now<<"\titem:\t"<<item<<"\tvaluesize:\t"<<v.size()<<endl;
vector<PDL> res;
sort(v.begin(), v.end());
int sz = unique(v.begin(), v.end()) - v.begin();
int words = v.size();
for (int i = 0; i < sz; i++){
LL val = v[i];
double tf = item_value_times[item][val] * 1.0 / words;
double idf = log(tot * 1.0 / (1 + value_times[val]));
res.push_back(PDL(tf * idf, val));
if ((now - 1) % SHOW == 0) { cerr<<"tf-idf = "<<tf*idf<<"\tval = "<<val<<endl; }
}
item_vector[item] = res;
item_vector_len[item] = len(res);
}
cout<<"get item's vector over, time use:\t"<<(clock() - st) / CLOCKS_PER_SEC<<"\n";
item_value_times.clear();
value_times.clear();
}
示例7: dfs
UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node) {
if (node == NULL) return NULL;
dfs(node);
visit.clear();
dfs2(node);
visit.clear();
UndirectedGraphNode * result = node->neighbors[(int)node->neighbors.size() - 1];
dfs3(node);
return result;
}
示例8: canCross
bool canCross(vector<int> &stones) {
if (stones.size() == 1)
return true;
if (stones[1] - stones[0] != 1)
return false;
s.clear(), m.clear();
for (int i = 0; i < stones.size(); i++)
s[stones[i]] = i;
return helper(stones, 1, 1);
}
示例9: AllOne
/** Initialize your data structure here. */
AllOne()
{
Str2Num.clear();
Num2Strs.clear();
Num2Iter.clear();
ListNum.clear();
ListNum.push_back(0);
Num2Iter[0] = ListNum.begin();
}
示例10: SendStats
void StatsSender::SendStats(unordered_map<unsigned int, unsigned __int64> pickedItems, unordered_map<int, int> timers){
_pickedItems = pickedItems;
_timers = timers;
pickedItems.clear();
timers.clear();
HANDLE h = CreateThread(NULL, 0, StaticThreadStart2, (void*) this, 0, 0);
}
示例11: main
int main()
{
int tests;
int citiesN;
int relationsN;
int paths;
string name;
cin >> tests;
for (int t = 0; t < tests; t++)
{
cityId.clear();
graph.clear();
cin >> citiesN;
for(int c = 1; c <= citiesN; c++)
{
distances[c] = infinity;
emptyDistances[c] = infinity;
city city;
cin >> city.name;
graph[c] = city;
cityId[city.name] = c;
cin >> relationsN;
for(int r = 0; r < relationsN; r++)
{
way way1;
cin >> way1.destination >> way1.cost;
graph[c].adjacent.push_back(way1);
way way2 = way1;
way2.destination = c;
graph[way2.destination].adjacent.push_back(way2);
}
}
cin >> paths;
for (int p = 0; p < paths; p++)
{
string source, destination;
cin >> source >> destination;
distances = emptyDistances;
fill(visited.begin(), visited.end(), false);
dijkstra(cityId[source], cityId[destination]);
cout << distances[cityId[destination]] << endl;
}
}
return 0;
}
示例12: main
int main()
{
// freopen("in.txt","r",stdin);
string name,party,club;
char ins[100],*ptr;
int TC,tmp,ans;
TC = atoi(gets(ins));
gets(ins);
while(TC--)
{
name_set.clear(); party_set.clear(); club_set.clear();
memset(graph,0,sizeof(graph));
N = 1;
while(gets(ins) && strlen(ins))
{
ptr = strtok(ins," ");
name = string(ptr);
ptr = strtok(NULL," ");
party = string(ptr);
graph[get(name_set,name)][get(party_set,party)] = 1;
while(ptr = strtok(NULL," "))
{
club = string(ptr);
graph[source()][get(club_set,club)] = 1;
graph[get(club_set,club)][get(name_set,name)] = 1;
}
}
tmp = (club_set.size() - 1) / 2;
for(unordered_map<string,int>::iterator it = party_set.begin();it != party_set.end();it++)
graph[it->second][target()] = tmp;
ans = 0;
visited.reset();
while(tmp = maxflow(source(),INT_MAX))
{
ans += tmp;
visited.reset();
}
if(ans != club_set.size()) printf("Impossible.\n");
else
for(unordered_map<string,int>::iterator it_name = name_set.begin();it_name != name_set.end();it_name++)
for(unordered_map<string,int>::iterator it_club = club_set.begin();it_club != club_set.end();it_club++)
if(graph[it_name->second][it_club->second])
{
printf("%s %s\n",(it_name->first).c_str(),(it_club->first).c_str());
break;
}
if(TC) printf("\n");
}
return 0;
}
示例13: main
int main()
{
ios_base::sync_with_stdio(false);
bool first = true;
int n;
while (cin >> n)
{
if (first) first = false;
else cout << '\n';
Buys buy_orders(buy_cmp);
Sells sell_orders(sell_cmp);
for (auto i = 1; i <= n; ++i)
{
string cmd; cin >> cmd;
if (cmd[0] == 'B')
process_incoming(buy_orders, sell_orders, i);
else if (cmd[0] == 'S')
process_incoming(sell_orders, buy_orders, i);
else // cancel order
{
int ci; cin >> ci;
if (!gone.count(ci))
{
if (b_seq2iter.count(ci))
{
auto &it = b_seq2iter[ci];
price2size[it->price] -= it->size;
buy_orders.erase(it);
}
else
{
auto &it = s_seq2iter[ci];
price2size[it->price] -= it->size;
sell_orders.erase(it);
}
gone.insert(ci);
}
}
print_quote(buy_orders, sell_orders);
}
price2size.clear();
b_seq2iter.clear();
s_seq2iter.clear();
gone.clear();
}
return 0;
}
示例14: minMalwareSpread
int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {
int n = graph.size();
parent.clear();
count.clear();
for(int i = 0; i < n; ++i) {
parent[i] = i; count[i] = 1;
}
vector<int> visited(n, false);
for(int i = 0; i < n; ++i)
{
for(int j = 0; j < n; ++j)
{
if(graph[i][j])
{
int pi = findParent(i);
int pj = findParent(j);
if(pi != pj)
{
parent[pi] = pj;
count[pj] += count[pi];
}
}
}
}
sort(initial.begin(), initial.end());
map<int, vector<int>> m;
for(int i : initial)
{
m[findParent(i)].push_back(i);
}
int minCount = 0;
int minIdx = initial[0];
for(const auto& p : m)
{
if(p.second.size() == 1)
{
if(count[p.first] > minCount)
{
minCount = count[p.first];
minIdx = p.second[0];
}
}
}
return minIdx;
}
示例15: Node
/*
* Main method to call the prefix generation
* @Params A - Vector of strings
*/
vector<string> Solution::prefix(vector<string> &A) {
// create a empty vector for results
vector<string> result;
// clear the global hashmap
res.clear();
// return empty vector in case A is empty
if(A.size() == 0) return result;
// Generate the prefix tree
Node* Tree = new Node("*");
for(int i = 0; i < A.size(); i++) {
Tree->insertChild(A[i]);
}
// Traverse the tree to generate hashmap
// Not needed if the order of prefix isn't important
traverse(Tree, "");
// generate ordered result from hashmap
for(int i = 0; i < A.size(); i++) {
result.push_back(res[A[i]]);
}
return result;
}