Source:

PAT A1095 Cars on Campus (30 分)

Description:

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

Keys:

  • 模拟题

Code:

 /*
Data: 2019-08-24 16:39:21
Problem: PAT_A1095#Cars on Campus
AC: 43:46 题目大意:
查询某时刻校园内停放车辆的数量,以及一天之中停留时间最长的车辆
输入:
第一行给出,记录数N<=1e4,查询数K<=8e4
接下来N行,车牌号,时刻,出/入
接下来K行,递增顺序给出查询时刻
输出:
各时刻校内停放车辆的数量;
一天之中停留时间最长的车辆,id递增 基本思路:
设置两个列表;
首先按车牌信息归类并按时间顺序递增排序,筛选有效信息,并统计各个车辆的停留时间
再按照时间顺序重排有效信息,遍历列表并统计各时刻校内停放车辆的数量
*/
#include<cstdio>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
string id;
int time,status;
}tp;
vector<node> info,valid; bool cmp(const node &a, const node &b)
{
if(a.id != b.id)
return a.id<b.id;
else if(a.time != b.time)
return a.time < b.time;
else
return a.status < b.status;
} bool cmpTime(const node &a, const node &b)
{
return a.time < b.time;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,k;
scanf("%d%d", &n,&k);
for(int i=; i<n; i++)
{
string s;
int hh,mm,ss;
cin >> s;
tp.id =s;
scanf("%d:%d:%d", &hh,&mm,&ss);
tp.time=hh*+mm*+ss;
cin >> s;
if(s=="in")
tp.status = ;
else
tp.status = ;
info.push_back(tp);
} sort(info.begin(),info.end(),cmp);
int maxTime=;
vector<string> longest;
for(int i=; i<info.size(); i++)
{
int sum=;
while(i+<info.size() && info[i].id==info[i+].id)
{
if(info[i].status== && info[i+].status==)
{
sum += (info[i+].time-info[i].time);
valid.push_back(info[i]);
valid.push_back(info[i+]);
}
i++;
}
if(sum > maxTime)
{
maxTime = sum;
longest.clear();
longest.push_back(info[i].id);
}
else if(sum == maxTime)
longest.push_back(info[i].id);
} sort(valid.begin(),valid.end(),cmpTime);
int keep=,pt=;
for(int i=; i<k; i++)
{
int hh,mm,ss;
scanf("%d:%d:%d", &hh,&mm,&ss);
int time = hh*+mm*+ss;
while(pt<valid.size() && valid[pt].time<=time)
{
if(valid[pt].status==)
keep++;
else
keep--;
pt++;
}
printf("%d\n", keep);
} for(int i=; i<longest.size(); i++)
printf("%s ", longest[i].c_str());
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

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

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

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

  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 甲级 Cars on Campus (30)

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

  6. 1095 Cars on Campus——PAT甲级真题

    1095 Cars on Campus Zhejiang University has 6 campuses and a lot of gates. From each gate we can col ...

  7. 【刷题-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 ...

  8. 1095. Cars on Campus (30)

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

  9. 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 ...

随机推荐

  1. (5)C++ 循环和判断

    循环 一.for循环 ; i < ; i++) { cout << "abc"<< endl; } 或 ; i; i--) { cout <&l ...

  2. Lucence使用入门

    参考: https://blog.csdn.net/u014209975/article/details/50525624 https://www.cnblogs.com/hanyinglong/p/ ...

  3. [已解决]报错: Version in docker-compose is unsupported

    docker compose将解析版本为"2",而不是"3.3".应该改为: version: "2"

  4. [已解决]报错: twisted 18.7.0 requires PyHamcrest>=1.9.0

    1.下载对应的Twisted,下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted 2.通过Anaconda3的Anaconda Promp ...

  5. mysql 5.7.20 动态sql 传入参数

    drop procedure test; delimiter ;; CREATE procedure test() -- 取动态sql的值 -- 目前只测试出,在 where 后面, 可以用 ?,类似 ...

  6. Msys2编译Emacs

    Msys2编译Emacs */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839496;} Msy ...

  7. CF1215D

    CF1215D 两个整数的和是偶数,他们的差也是偶数 博弈好难啊qaq 我好zz啊qaq 如果M放最后一个M胜 现在和比较大的一边如果空位还多的话M胜 M可以通过在大的那边放9来消掉那边所有的空 由于 ...

  8. Neo4j基础入门

    图数据库基础知识 图数据库以图这种数据结构为基础,可以保存任意种类的数据,以下图为基础,简单介绍Neo4j中的几个简单概念: 1.节点(Nodes) 表示图数据库的实体(entities),代表图数据 ...

  9. shell只读变量

  10. redis的密码设置

    若连接redis时报错:Redis (error) NOAUTH Authentication required.,通常是由于redis设了密码但连接时却未提供密码引起的. 设置密码: 编辑redis ...