Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you are supposed to tell, at any specific time point, the number of cars parking on campus, and at the end of the day find the cars that have parked for the longest time period.

Input Specification:

Each input file contains one test case. Each case starts with two positive integers N (≤), the number of records, and K (≤) the number of queries. Then N lines follow, each gives a record in the format:

plate_number hh:mm:ss status

where plate_number is a string of 7 English capital letters or 1-digit numbers; hh:mm:ss represents the time point in a day by hour:minute:second, with the earliest time being 00:00:00 and the latest 23:59:59; and status is either in or out.

Note that all times will be within a single day. Each in record is paired with the chronologically next record for the same car provided it is an out record. Any in records that are not paired with an out record are ignored, as are out records not paired with an in record. It is guaranteed that at least one car is well paired in the input, and no car is both in and out at the same moment. Times are recorded using a 24-hour clock.

Then K lines of queries follow, each gives a time point in the format hh:mm:ss. Note: the queries are given in ascending order of the times.

Output Specification:

For each query, output in a line the total number of cars parking on campus. The last line of output is supposed to give the plate number of the car that has parked for the longest time period, and the corresponding time length. If such a car is not unique, then output all of their plate numbers in a line in alphabetical order, separated by a space.

Sample Input:

16 7
JH007BD 18:00:01 in
ZD00001 11:30:08 out
DB8888A 13:00:00 out
ZA3Q625 23:59:50 out
ZA133CH 10:23:00 in
ZD00001 04:09:59 in
JH007BD 05:09:59 in
ZA3Q625 11:42:01 out
JH007BD 05:10:33 in
ZA3Q625 06:30:50 in
JH007BD 12:23:42 out
ZA3Q625 23:55:00 in
JH007BD 12:24:23 out
ZA133CH 17:11:22 out
JH007BD 18:07:01 out
DB8888A 06:30:50 in
05:10:00
06:30:50
11:00:00
12:23:42
14:00:00
18:00:00
23:59:00

Sample Output:

1
4
5
2
1
0
1
JH007BD ZD00001 07:20:09
 #include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
struct Node
{
string ID;
bool flag;//1是进,0是出
int time;
Node(string s, bool f, int t) :ID(s), flag(f), time(t) {}
};
vector<Node>Cars;
unordered_map<string, vector<Node>>map;//一辆车不止一个记录
vector<string>res;
int N, K, maxTime = ;
int main()
{
cin >> N >> K;
string ID, flag;
int h, m, s;
while (N--)
{
cin >> ID;
scanf("%d:%d:%d", &h, &m, &s);
cin >> flag;
map[ID].push_back(Node(ID, flag == "in", h * + m * + s));
}
for (auto ptr = map.begin(); ptr != map.end(); ++ptr)
{
sort(ptr->second.begin(), ptr->second.end(), [](Node a, Node b) {return a.time < b.time; });
int t = ;
for (int i = ; i < ptr->second.size()-; ++i)
{
if (ptr->second[i].flag == && ptr->second[i + ].flag == )//一进一出
{
Cars.push_back(ptr->second[i]);//记录合法时间
Cars.push_back(ptr->second[i + ]);//记录合法时间
t += ptr->second[i + ].time - ptr->second[i].time;//累加停车时间
}
}
if (t > maxTime)
{
maxTime = t;
res.clear();
res.push_back(ptr->first);
}
else if(t==maxTime)
res.push_back(ptr->first);
}
sort(Cars.begin(), Cars.end(), [](Node a, Node b) {return a.time < b.time; });
int num = , i = ;
while (K--)
{
scanf("%d:%d:%d", &h, &m, &s);
int time = h * + m * + s;
for (; i < Cars.size() && Cars[i].time <= time; ++i)
num += Cars[i].flag ? : -;//使用用-1表示该车开出去了
cout << num << endl;
}
sort(res.begin(), res.end());
for (auto v : res)
cout << v << " ";
printf("%02d:%02d:%02d\n", maxTime / , maxTime % / , maxTime % );
return ;
}

PAT甲级——A1095 Cars on Campus的更多相关文章

  1. PAT甲级1095. Cars on Campus

    PAT甲级1095. Cars on Campus 题意: 浙江大学有6个校区和很多门.从每个门口,我们可以收集穿过大门的汽车的进/出时间和车牌号码.现在有了所有的信息,你应该在任何特定的时间点告诉在 ...

  2. PAT甲级——1095 Cars on Campus (排序、映射、字符串操作、题意理解)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93135047 1095 Cars on Campus (30 分 ...

  3. 【刷题-PAT】A1095 Cars on Campus (30 分)

    1095 Cars on Campus (30 分) Zhejiang University has 8 campuses and a lot of gates. From each gate we ...

  4. A1095 Cars on Campus (30)(30 分)

    A1095 Cars on Campus (30)(30 分) Zhejiang University has 6 campuses and a lot of gates. From each gat ...

  5. PAT A1095 Cars on Campus (30 分)——排序,时序,从头遍历会超时

    Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out time ...

  6. A1095. Cars on Campus

    Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out time ...

  7. A1095 Cars on Campus (30 分)

    Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out time ...

  8. PAT_A1095#Cars on Campus

    Source: PAT A1095 Cars on Campus (30 分) Description: Zhejiang University has 8 campuses and a lot of ...

  9. pat 甲级 Cars on Campus (30)

    Cars on Campus (30) 时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard  题目描述 Zhejiang University ...

随机推荐

  1. Codeforces 479【E】div3

    题目链接:http://codeforces.com/problemset/problem/977/E 题意:就是给你相连边,让你求图内有几个环. 题解:我图论很差,一般都不太会做图论的题.QAQ看官 ...

  2. 面试39 MySQL读写分离

    (1)如何实现mysql的读写分离? 其实很简单,就是基于主从复制架构,简单来说,就搞一个主库,挂多个从库,然后我们就单单只是写主库,然后主库会自动把数据给同步到从库上去. (2)MySQL主从复制原 ...

  3. 解决通过vmware克隆虚拟机后,无法上网的问题

    注意:如果源主机是CentOS 6.8,复制出来的机器会出现无法上网. 如果源主机是CentOS 7,复制出来的机器可以正常上网.复制后,只要改下IP地址即可上网. 出现该问题的原因是,我们克隆后,将 ...

  4. List<Map>中根据map的同一指标项数据——去重代码

    先看网络上,博客经常出现的错误代码: for(ABatchAddCheckVO aBatchAddCheckVO : addList){ dto.put("aac001",aBat ...

  5. 如何读懂Web服务的系统架构图

    Web服务的一个重要特点就是流量大.数据多,仅靠一台服务器肯定难以支撑大规模的服务. 所以我们经常会看到诸如以下的一些术语,教人好生不懂: *:系统架构.物理架构.Web服务基础设施 *:应用服务器 ...

  6. PROJECT | 四则运算UI设计 - PSP表格&需求分析

    PSP表格(TP版) 需求分析 [GUI编程语言选择] 考虑到Java编写GUI效率偏低且界面不算特别美观(即使有Windowbuilder插件帮助),所以我们使用控件更多,开发效率更高,具有集成开发 ...

  7. innodb_file_per_table 理解

    MYSQL innodb存储引擎 默认将所有的数据库 innodb 引擎的表数据存储在一个共享空间中:ibdata1,当增删数据库的时候, ibdata1文件不会自动收缩,单个数据库的备份也会成为问题 ...

  8. c# 使用Expression 生成sql

    使用Expression 生成sql  update语句的时候遇到了个问题 ,Expression<Action<T>>  la   这个委托里面老获取不到 引用类型的值,甚至 ...

  9. leetcode-229-求众数②

    题目描述: 方法一:摩尔投票法 class Solution: def majorityElement(self, nums: List[int]) -> List[int]: candiate ...

  10. Delphi屏幕截图的实现

    首先要获得设备环境的句柄,可以通过GetDC函数来获得,对于这个函数,MSDN上是这样说明的 The GetDC function retrieves a handle to a device con ...