PAT_A1095#Cars on Campus
Source:
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 being00:00:00
and the latest23:59:59
; andstatus
is eitherin
orout
.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 anout
record. Anyin
records that are not paired with anout
record are ignored, as areout
records not paired with anin
record. It is guaranteed that at least one car is well paired in the input, and no car is bothin
andout
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的更多相关文章
- PAT甲级1095. Cars on Campus
PAT甲级1095. Cars on Campus 题意: 浙江大学有6个校区和很多门.从每个门口,我们可以收集穿过大门的汽车的进/出时间和车牌号码.现在有了所有的信息,你应该在任何特定的时间点告诉在 ...
- PAT 1095 Cars on Campus
1095 Cars on Campus (30 分) Zhejiang University has 8 campuses and a lot of gates. From each gate we ...
- PAT甲级——1095 Cars on Campus (排序、映射、字符串操作、题意理解)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93135047 1095 Cars on Campus (30 分 ...
- 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 ...
- pat 甲级 Cars on Campus (30)
Cars on Campus (30) 时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard 题目描述 Zhejiang University ...
- 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 ...
- 【刷题-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 ...
- 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 ...
- 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 ...
随机推荐
- 2的N次方求解-----C++
2的N次方求解,一般情况如果不超出C/C++基本数据类型的表达范围,这个问题及其容易,但是如果N的值十分的大,以致于超出基本数据类型表达范围 下面的程序正是解决2的N次方这个大数精确求解的源码 #in ...
- embed元素 autostart false 失效时的解决方法
embed元素 autostart false 失效时的解决方法 最近在工作中碰到了在网页中嵌入播放器播放声音文件的需求,最后使用了embed元素 代码如下: <embed src='1093. ...
- 数据访问层的基类BaseDALSQL
using System; using System.Text; using System.Collections; using System.Data; using System.Data.Comm ...
- 【lua学习笔记】——Notepad++ 设置运行 lua 和 python
一.设置 run -> 设置 cmd /k lua "$(FULL_CURRENT_PATH)" & PAUSE & EXIT 二.原理: cmd /k ...
- elementui表格表头合并
第一步:用多级表头,该删删 该减减 第二步:使用header-cell-style属性
- python+tushare获取股票和基金每日涨跌停价格
接口:stk_limit 描述:获取全市场(包含A/B股和基金)每日涨跌停价格,包括涨停价格,跌停价格等,每个交易日8点40左右更新当日股票涨跌停价格. 限量:单次最多提取4800条记录,可循环调取, ...
- Spark on YARN--WordCount、TopK
原文地址:http://blog.csdn.net/cklsoft/article/details/25568621 1.首先利用http://dongxicheng.org/framework-on ...
- Python之实现一个优先级队列
问题 怎样实现一个按优先级排序的队列? 并且在这个队列上面每次 pop 操作总是返回优先级最高的那个元素 解决方案 下面的类利用 heapq 模块实现了一个简单的优先级队列: import heapq ...
- 为 STM32 移植 Berry 脚本语言
Berry 是我为单片机设计的一款脚本语言,该语言具有资源占用小.平台无关.执行速度快和易于掌握等优点.在单片机上使用脚本语言可以提高单片机的二次开发能力以及调试效率,同时也是一种比较新颖的玩法.本教 ...
- centos6.5大于2T容量硬盘分区、格式化、挂载!
一. 超过2T容量硬盘使用parted创建分区 1.fdisk l(查看需要分区的硬盘盘符如:sda) 2.parted /dev/sda 3.rm 1 4.mklabel gpt(超过2T磁盘格式 ...