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 ...
随机推荐
- webpack构建缓存机制-hash介绍
前言 浏览器为了优化体验,会有缓存机制.如果浏览器判断当前资源没有更新,就不会去服务端下载,而是直接使用本地资源.在webpack的构建中,我们通常使用给文件添加后缀值来改名以及提取公共代码到不会改变 ...
- phhstrom 快捷键
TODO(表示待办事件)注释 快捷键 Alt+6 Alt+6 可以查看添加了//TODO注释的代码片段 一般我们在开发过程中由于时间或者各方面的时间来不及完成的代码,往往会先将逻辑写出来,实现留待以后 ...
- mongo聚合命令
db.getCollection('chat').aggregate([ { "$match": { "last": 1, "type": ...
- CentOS7下yum安装Jenkins
Jenkins官网最新稳定版:https://pkg.jenkins.io/redhat-stable/ 1.下载依赖 sudo wget -O /etc/yum.repos.d/jenkins.re ...
- psql 命令
(1)使用命令行连接数据库 psql -U postgres -h localhost -p 5433 (2)列出所有的数据库 \l -- 查看所有数据库 (3)进入某个数据库 \c name -- ...
- JQuery 全选 反选 获取Table 中指定td的元素值
//全选 function initTableCheckbox() { var $thr = $('table thead tr'); var $checkAllTh = $('<th>& ...
- js将数字转换成货币形式的字符
因为UI图上有的地方需要将数字转成货币形式的,例如:1234567转成 1,234,567 这样的,不过之前没弄过,然后在网上搜了下方法,参考了下面这篇文章 参考文章:JS将数字转成货币形式的简单 ...
- 快速上手的Glide4.x教程
安卓基础开发库,让开发简单点. DevRing & Demo地址:https://github.com/LJYcoder/DevRing 学习/参考地址: https://blog.csdn. ...
- Linux下如何查看系统是多少位的
在Linux命令行下输入 getconf LONG_BIT 命令
- linux子网掩码优化配置
prefix prefix是前缀的意思,这里指子网掩码的位数. 如255.255.255.0则在ifcfg-eth0的配置文件中:PREFIX=24而NETMASK与PREFIX的作用是一样的,都是配 ...