AcWing 1340. 贪婪的送礼者
原题链接
简单
作者:
ywt51
,
2023-05-23 22:09:20
,
所有人可见
,
阅读 59
算法1:模拟-字符串-操作-map(枚举) $O(n)$
#include <bits/stdc++.h>
using namespace std;
const int N = 15;
int n;
string a[N];
unordered_map<string, int> mp;
int main() {
cin >> n;
for (int i = 0; i < n; ++ i) cin >> a[i];
for (int i = 0; i < n; ++ i) {
string x, y;
int m, t;
cin >> x >> m >> t;
if (!t) continue; //t为0,跳过,发给0个人,细节,不然有除0错误
mp[x] -= m/t * t; //x减去要发出去的钱
for (int i = 0; i < t; ++ i) {
cin >> y;
mp[y] += m/t; //y加上收到的钱
}
}
for (int i = 0; i < n; ++ i)
cout << a[i] << ' ' << mp[a[i]] << endl;
return 0;
}