Added first working solution.

master
Tomasz Polgrabia 2025-02-09 21:58:36 +01:00
parent 69ec4d2e56
commit 12f5d3edf8
1 changed files with 23 additions and 9 deletions

View File

@ -11,21 +11,34 @@ const int MAX_BUFFER = 0x1000;
using namespace std; using namespace std;
void process_data(map<int,set<int>> &documents) { void process_data(map<int,set<int>> &documents) {
fprintf(stderr, "Processing data\n");
for (auto it1 = documents.begin(); it1 != documents.end(); it1++) { for (auto it1 = documents.begin(); it1 != documents.end(); it1++) {
for (auto it2 = documents.begin(); it2 != documents.end(); it2++) { for (auto it2 = documents.begin(); it2 != documents.end(); it2++) {
if (it1->first == it2->first) { if (it1->first >= it2->first) {
continue; continue;
} }
set<int> intersection; set<int> union_set;
set_intersection( set<int> intersection_set;
it1->second.begin(), it1->second.end(),
it2->second.begin(), it2->second.end(),
inserter(intersection, next(intersection.begin())));
if (intersection.size()) { for (auto el = it1->second.begin(); el != it1->second.end(); el++) {
fprintf(stderr, "Documents %d and %d have %d common elements\n", union_set.insert(*el);
it1->first, it2->first, intersection.size()); if (auto search = it2->second.find(*el); search != it2->second.end()) {
intersection_set.insert(*el);
}
}
for (auto el = it2->second.begin(); el != it2->second.end(); el++) {
union_set.insert(*el);
}
auto common_count = intersection_set.size();
auto union_count = union_set.size();
if (common_count) {
fprintf(stderr, "Documents %d and %d have %.2f sparse\n",
it1->first, it2->first, (double)common_count / (double)union_count);
} }
} }
} }
@ -81,6 +94,7 @@ int main() {
process_input(documents, buffer); process_input(documents, buffer);
} }
process_data(documents); process_data(documents);
fprintf(stderr, "Execution finished\n"); fprintf(stderr, "Execution finished\n");
return 0; return 0;