#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
const int maxn = 1e4 + 10;
int n, k;
struct car {
char num[10];
int hh, mm, ss;
int flag;
int intime, outtime;
void read() { scanf("%s %d:%d:%d", num, &hh, &mm, &ss); }
bool operator<(const car&x)const
{
return strcmp(num, x.num) == 0 ? hh == x.hh ? mm == x.mm ? ss < x.ss : mm < x.mm : hh < x.hh : strcmp(num, x.num) < 0;
}
}a[maxn];
struct point {
char number[10];
int intime, outtime, parktime;
bool operator<(const point &x)const
{
return parktime == x.parktime ? strcmp(number,x.number)<0: parktime>x.parktime;
}
};
vector<point>p;
int gettime(car x)
{
return x.hh * 60 * 60 + x.mm * 60 + x.ss;
}
int main()
{
scanf("%d%d", &n, &k);
char s[10];
for (int i = 0; i < n; i++)
{
a[i].read();
scanf("%s", s);
if (strcmp(s, "in") == 0)a[i].flag = 0, a[i].intime = gettime(a[i]);
else a[i].flag = 1, a[i].outtime = gettime(a[i]);
}
sort(a, a + n);
for (int i = 1; i < n; i++)
{
if (strcmp(a[i].num, a[i - 1].num) == 0 && a[i - 1].flag == 0 && a[i].flag == 1)
{
point x;
x.intime = a[i - 1].intime;
x.outtime = a[i].outtime;
strcpy(x.number, a[i].num);
x.parktime = x.outtime - x.intime;
p.push_back(x);
}
}
while (k--)
{
int h, m, s, time;
scanf("%d:%d:%d", &h, &m, &s);
time = h * 60 * 60 + m * 60 + s;
int cnt = 0;
for (int i = 0; i < p.size(); i++)
if (p[i].outtime > time&&time >= p[i].intime)cnt++;
printf("%d\n", cnt);
}
int maxtime = 0;
vector<point>f;
for (int i = 0; i < p.size(); i++)
{
if (i == 0)f.push_back(p[i]);
else
{
if (strcmp(p[i].number, f[f.size() - 1].number) == 0)f[f.size() - 1].parktime += p[i].parktime;
else
{
f.push_back(p[i]);
}
}
}
for (int i = 0; i < f.size(); i++)if (f[i].parktime > maxtime)maxtime = f[i].parktime;
sort(f.begin(), f.end());
for (int i = 0; i < f.size(); i++)
{
if (f[i].parktime == maxtime)printf("%s ", f[i].number);
else break;
}
printf("%02d:%02d:%02d", maxtime / 3600, maxtime % 3600 / 60, maxtime % 60);
return 0;
}
模拟一下就可以了,注意最后一个for里面要break出来,不然会超时,自然for之前要排下序
1095. Cars on Campus (30)
最新推荐文章于 2023-05-08 23:27:18 发布