思路:
首先建一个全局vector存有相关症状的人,再建一个局部vector存每一天的申请信息,排序后进行筛选。
Tip:
操作顺序:
- 检查身份证合法性
- 对于有相关症状的人员进行记录
- 排序
- 按照规则发放口罩
任何一步顺序都不能调换和丢失,否则本题无法通过。
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1000 + 5; const int INF = 0x7FFFFFFF; struct mmp { string name; string idcard; int shen; int times; int index; }; map<string, int> mp; set<string> smp; set<string> vHave; vector<mmp> v; bool cmp(mmp a, mmp b) { if (a.times == b.times) return a.index < b.index; return a.times < b.times; } int main() { int D, P; scanf("%d %d", &D, &P); for (int day = 1; day <= D; day++) { int ti, si; cin >> ti >> si; vector<mmp> use; for (int i = 1; i <= ti; i++) { string name; string idcard; int shen; int hh; int mm; cin >> name; cin >> idcard; cin >> shen; scanf("%d:%d", &hh, &mm); bool flag = true; if (idcard.length() != 18) continue; for (auto j:idcard) if (!(j >= '0' && j <= '9')) flag = false; if (flag) { if (shen && vHave.find(idcard) == vHave.end()) { v.push_back(mmp{name, idcard, shen, hh * 60 + mm, i}); vHave.insert(idcard); } use.push_back(mmp{name, idcard, shen, hh * 60 + mm, i}); } } sort(use.begin(), use.end(), cmp); int now = 0; for (int i = 0; i < use.size() && now < si; i++) { if (mp[use[i].idcard] == 0 || day >= P + mp[use[i].idcard] + 1) { now++; mp[use[i].idcard] = day; cout << use[i].name << " " << use[i].idcard << endl; } } } for (auto i:v) cout << i.name << " " << i.idcard << endl; return 0; }