记一道很坑的L2题目。。调试了一晚上,一开始用vector存的个人口罩领取日期记录,结果测试点4、5一直超时。
后来改成map之后没有超时了,但是还是显示答案错误。
第二天上午又改了一个多小时。。最后发现是忽略了这一点
一开始是抱着侥幸心理,以为只比较用户提交时间不会影响列表出现顺序。最后还是老老实实加了个pid(优先级),最后AC。
AC代码如下:
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
class Person {
public:
string name;
string id;
string time;
int pid; //优先级!!!
Person(string name, string id, string time) {
this->name = name;
this->id = id;
this->time = time;
}
bool operator==(const Person& a) {
return a.id == this->id;
}
};
bool checkId(string id) {
if (id.size() != 18) {
return true;
}
for (int j = 0; j < id.size(); j++)
{
if (id[j] > '9' || id[j] < '0') {
return true;
}
}
return false;
}
class Mycompare2 {
public:
bool operator()(Person a, Person b) {
if (a.time == b.time) {
return a.pid < b.pid;
}
else {
return a.time < b.time;
}
}
};
int main() {
int D = 0, P = 0;
cin >> D >> P;
int T = 0, S = 0;
map<string,int> allList;//总名单
vector<Person> dayList;//日名单
vector<Person> records;//身体不适成员
int status;
string id, time;
string name;
for (int i = 1; i <= D; i++)
{
dayList.clear();
cin >> T >> S;
for (int j = 0; j < T; j++)
{
cin >> name >> id >> status >> time;
if (checkId(id) || name.size()>10) {
continue;
}
Person person = Person(name, id,time);
if (status == 1 && find(records.begin(), records.end(), person) == records.end()) {
records.push_back(person);
}
person.pid = j;
dayList.push_back(person);
}
int count = 0;
sort(dayList.begin(), dayList.end(), Mycompare2());
for (vector<Person>::iterator it = dayList.begin(); it != dayList.end(); it++)
{
if (count == S) {
break;
}
else {
int day_record = allList[it->id];
if (day_record != 0) {
if (i - day_record < P + 1) {
continue;
}
allList.erase(it->id);
}
allList[it->id]= i;
cout << it->name << " " << it->id << endl;
count++;
}
}
}
for (vector<Person>::iterator it = records.begin(); it != records.end(); it++)
{
cout << it->name << " " << it->id << endl;
}
return 0;
}