You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB
C++

#pragma once
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
using namespace std;
bool nextComb(vector<int> &indices, int n) {
int k = indices.size();
int i = n - 1;
int j = k - 1;
while (indices[j] == i) {
if (j == 0)
return 1;
i--;
j--;
}
indices[j]++;
for (int l = 0; l <= k - j - 1; l++) {
indices[j + l] = indices[j] + l;
}
return 0;
}
template <typename S>
unordered_set<S> intersectSets(unordered_set<S> s1, unordered_set<S> s2) {
unordered_set<S> s;
if (s1.size() <= s2.size()) {
for (auto &el : s1) {
if (s2.find(el) != s2.end()) {
s.insert(el);
}
}
}
else {
for (auto &el : s2) {
if (s1.find(el) != s1.end()) {
s.insert(el);
}
}
}
return s;
}
template <typename K, typename V>
vector<K> getShuffleKeys(unordered_map<K, V> map) {
srand(time(NULL));
vector<K> output;
for (auto& pair : map) {
output.push_back(pair.first);
}
random_shuffle(output.begin(), output.end());
return output;
}