7-13 口罩发放 (10 分)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <unordered_map>
using namespace std;
struct Record{
string name, ID;
bool state;
string tim;
int num; // 在当天的第几条记录
};
Record r[10010];
Record w[10010];
int d, p, t, s, tot;
unordered_map <string, int> g;
bool checkID(string s)
{
if (s.size() != 18) return false;
for (int i=0; i<18; i++)
if (s[i] < '0' || s[i] > '9') return false;
return true;
}
bool cmp(Record a, Record b) {
if (a.tim < b.tim) return true;
else if (a.tim == b.tim && a.num < b.num) return true;
return false;
}
int main()
{
cin >> d >> p;
for (int day = 1; day <= d; day++)
{
cin >> t >> s;
string a, b, c;
bool st;
int cnt = 0;
for (int i=1; i<=t; i++) {
cin >> a >> b >> st >> c;
if (checkID(b)) { // 检查身份证是否合法
cnt++;
r[cnt] = {a, b, st, c, cnt};
}
if (st == 1) {
tot++;
w[tot] = r[cnt];
}
}
sort(r+1, r+cnt+1, cmp);
for (int i=1; i<=cnt; i++)
{
string cid = r[i].ID;
if (g.count(cid) == 0 && s) {
// cout << s << " --- " ;
printf("%s %s\n", r[i].name.c_str(), r[i].ID.c_str());
g[cid] = day;
s--;
} else {
int lastDay = g[cid];
//cout << "name last day : " << r[i].name << " " << lastDay << endl;
if (day - lastDay > p && s) {
// cout << s << " --- ";
printf("%s %s\n", r[i].name.c_str(), r[i].ID.c_str());
s--;
}
}
if (!s) break;
}
}
for (int i=1; i<=tot; i++)
{
bool printed = false;
for (int j=1; j<i; j++)
if (w[j].ID == w[i].ID) {
printed = true;
break;
}
if(!printed) printf("%s %s\n", w[i].name.c_str(), w[i].ID.c_str());
}
return 0;
}
7-13 口罩发放 (10 分)
最新推荐文章于 2024-03-20 23:35:22 发布