-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMerge.cpp
More file actions
59 lines (51 loc) · 1.11 KB
/
Copy pathMerge.cpp
File metadata and controls
59 lines (51 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <map>
#include <vector>
#include <fstream>
using namespace std;
static const int Sz = 8;
typedef long long LL;
struct Zt {
LL cs;
double qz;
Zt (LL b = 0, double c = 0) {
cs = b, qz = c;
}
};
map<vector<LL>, Zt> mp;
inline void Merge(string s) {
ifstream fin(s.data());
LL b;
double c;
vector<LL> a;
while (fin >> b >> c) {
a.clear();
for (int i = 1; i <= Sz; ++i) {
LL x;
fin >> x;
a.push_back(x);
}
auto now = mp.find(a);
if (now == mp.end()) {
mp[a] = Zt(1, c);
} else {
double sum = now->second.qz * now->second.cs;
now->second.cs += b;
sum += c * b;
now->second.qz = sum / now->second.cs;
}
}
fin.close();
}
int main() {
Merge("tmp/data1.data");
Merge("tmp/data2.data");
ofstream fout("tmp/merge.data");
for (auto x : mp) {
fout << x.second.cs << ' ' << x.second.qz << ' ';
for (auto y : x.first) {
fout << y << ' ';
}
}
fout.close();
return 0;
}