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. selenium2-java环境搭建 示例为chrome浏览器

    首先,安装并配置JDK,安装eclipse,安装firefox和chrome.下载selenium语言的JAVA库文件,下载地址为,如果打不开,则需要翻墙:http://www.seleniumhq. ...

  2. python模块学习之HTMLTestRunner模块生成HTML测试报告

    #!/usr/bin/env python #-*- coding:utf-8 -*- from HTMLTestRunner import HTMLTestRunner import time im ...

  3. 关于audio不能拖放

    图一,图二均为wav格式文件 图一为播放本地的音频,可以拖放 图二为放在后台的音频,不可以拖放 把这两个图片发给后台,让后台分析下两个的headers不同之处

  4. 对于Final关键字的总结

    1.final关键字可以用于成员变量.本地变量.方法以及类. 2. final成员变量必须在声明的时候初始化或者在构造器中初始化,否则就会报编译错误. 3. 你不能够对final变量再次赋值. 4.  ...

  5. Python删除列表中的空格

    list1 = ['122','2333','3444',' ','422',' ',' ','54',' '] list1=[x.strip() for x in list1 if x.strip( ...

  6. oracle数据库 唯一约束的创建与删除

    1.创建索引: alter table TVEHICLE add constraint CHECK_ONLY unique (CNUMBERPLATE, CVIN, CPLATETYPE, DWQCH ...

  7. [轉]udp_sendmsg空指针漏洞分析 by wzt

    udp_sendmsg空指针漏洞分析    by wzt 漏洞描述: 由于Linux ipv4协议栈中udp_sendmsg()函数设计上存在缺陷, 导致struct rtable *rt以空指针形式 ...

  8. 我学习的自定义ASP.NET分页控件

    public class MyPagecontroll { public int TotalCount { get; set; }//数据的总条数 public int PageSize { get; ...

  9. spring基于注解的事务控制

    pom配置: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http ...

  10. 解决code first Migration 增加外键时出现错误的问题

    先上模型 Comment public class Comment { [Key] public int CommentId { get; set; } [Required] public int S ...