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. 四. jenkins部署springboot项目(1)--window环境

    前提:jenkins和springboot运行在同一台机器 springboot项目使用git和maven jenkins所需的插件如Maven,Git等这里就不再详述. 1.jenkins配置git ...

  2. Java关于Math类的三个取整方法

    0x01 在java的Math类中有三个关于浮点数取整数的方法,分别是ceil (向上取整) floor(向下取整) round(四舍五入) 三个方法 0x02 ceil 向上取整,取整后总是比原来的 ...

  3. Excel表格文本格式的数字和数字格式如何批量转换

    Excel表格文本格式的数字和数字格式如何批量转换 在使用Excel表格对数据求和时,只能对单元格内常规格式的数据进行计算,而不能对单元格中的文本格式的数据进行计算,特点就是在单元格的左上角有一个绿色 ...

  4. ORACLE切非归档模式:

    C:\Documents and Settings\Administrator>sqlplus /nologSQL> conn / as sysdbaConnected to an idl ...

  5. 使用IntelliJ IDEA配置Maven(详细操作)

    一,下载Maven 进入官网http://maven.apache.org/  点击Download 找到如下图所示的区域,注意你的操作系统. 点击安装你所需要的安装包,下载,解压. 二,Maven环 ...

  6. 给Laravel4添加中文语系(转)

    Laravel 4 官方不附带英文以外的 validataion 错误信息翻译. 今天发现GitHub 上有一个 repository 收集不同的翻译,大家可以下载需要的翻译. GitHub项目地址: ...

  7. WPF非UI线程访问网络资源造成页面假死现象

    公司内部一个项目是用WPF作为GUI 访问web接口的形式获取数据, 但是由于数据量比较大,也没做分页,于是就需要一个loading的控件,网上查了很多资料但都比较浅.这里完成需求后,总结一下. 首先 ...

  8. Leetcode 200.岛屿的数量 - DFS、BFS

    Leetcode 200 岛屿的数量: DFS利用函数调用栈保证了检索顺序, BFS则需要自己建立队列,把待检索对象按规则入队. class Solution { // DFS解法,8ms/10.7M ...

  9. BZOJ 1576: [Usaco2009 Jan]安全路经Travel

    日常自闭半小时后看题解,太弱了qwq. 感觉这道题还是比较难的,解法十分巧妙,不容易想到. 首先题目说了起点到每个点的最短路都是唯一的,那么对这个图求最短路图必定是一棵树,而且这棵树是唯一的. 那么我 ...

  10. vue项目从0开始记录

    1.安装vue-cli 2.通过脚手架进行项目的创建    4.配置第三方UI库快速开发(如ivew,element ui) 5.配置axios 库 一.安装vue-cli npm install - ...