【PAT - 甲级1095】Cars on Campus (30分)(模拟)

题干:

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 (≤10​4​​), the number of records, and K (≤8×10​4​​) 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

题目大意:

给出n个车牌号、时间点、进出状态的记录,然后查询k个时间点这时校园内的车辆个数。最后还要输出在校园里面呆的时间最长的车的车牌号,以及呆了多久的时间。如果有多辆车就按照它的字母从小到大输出车牌。
配对要求是,如果一个车多次进入未出,取最后一个值;如果一个车多次out未进入,取第一个值。
注意:一个车可能出入校园好多次,停车的时间应该取之和。

解题报告:

注意凑样例的过程中,发现是要先对记录表单进行排错,然后再进行统计。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
char s[105],op[105];
int n,q;
struct Node {string name;int op;int Time;
} R[MAX];
bool cmp(Node a,Node b) {if(a.Time != b.Time) return a.Time < b.Time;else return a.op < b.op;
}
map<string,int> state;//记录每辆车的状态 
map<string,int> Time;//每辆车的停车时间 
map<string,int> has;
vector<string> ans;
int anst;
bool ok[MAX];
int main()
{memset(ok,1,sizeof ok);cin>>n>>q;for(int hh,mm,ss,i = 1; i<=n; i++) {scanf("%s",s);scanf("%d:%d:%d",&hh,&mm,&ss);scanf("%s",op);R[i].name = s;R[i].op = (op[0] == 'i' ? 1 : 2);R[i].Time = hh*3600+mm*60+ss;}for(int hh,mm,ss,i = 1; i<=q; i++) {scanf("%d:%d:%d",&hh,&mm,&ss);R[n+i].op = 3;R[n+i].Time = hh*3600+mm*60+ss;}sort(R+1,R+n+q+1,cmp);has.clear();for(int i = 1; i<=n+q; i++) {if(R[i].op == 1) {has[R[i].name] = 1;}else if(R[i].op == 2){if(has[R[i].name] == 0) ok[i] = 0; has[R[i].name] = 0;}}for(int i = 1; i<=n+q; i++) has[R[i].name] = -1;for(int i = n+q; i>=1; i--) {if(ok[i] == 0) continue;if(R[i].op == 2) {has[R[i].name] = 0;}else if(R[i].op == 1) {if(has[R[i].name] != 0) ok[i] = 0; has[R[i].name] = 1;}}has.clear();int cur = 0;for(int i = 1; i<=n+q; i++) {if(ok[i] == 0) continue;if(R[i].op == 3) printf("%d\n",cur);else if(R[i].op == 1) {state[R[i].name] = R[i].Time;has[R[i].name] = 1;cur++;} else {has[R[i].name] = 0;cur--;Time[R[i].name] += R[i].Time - state[R[i].name];}}for(auto tar : Time) {if(tar.second > anst) {anst = tar.second; ans.clear(); ans.pb(tar.first);}else if(tar.second == anst) {ans.pb(tar.first);}}sort(ans.begin(),ans.end());for(auto tar : ans) {cout << tar << " ";}int hh,mm,ss;hh = anst / 3600; anst -= hh * 3600;mm = anst / 60; anst -= mm * 60;ss = anst;printf("%02d:%02d:%02d\n",hh,mm,ss);return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/439461.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

TFS中的迭代(五)

从团队资源管理器中打开迭代选项。 TFS在新建完团队项目后会自动为本团队项目新建迭代子项&#xff0c;包含发布和冲刺。第一级为团队项目TestProject&#xff0c;第二层为发布&#xff0c;第三层为冲刺&#xff0c;这样的层次一共可以建14层。 这些选项可以编辑&#xff0c;添…

2022百度ApolloDay技术开放日:文心大模型在自动驾驶感知中的落地应用

2数据处理大模型技术是自动驾驶行业近年的热议趋势&#xff0c;但能否落地应用、能否用好是关键难题。百度自动驾驶依托文心大模型特色优势&#xff0c;率先实现技术应用突破。百度自动驾驶技术专家王井东表示&#xff1a;文心大模型-图文弱监督预训练模型&#xff0c;背靠文心…

【PAT - 甲级1155】Heap Paths (30分)(栈,dfs,二叉树)

题干&#xff1a; In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equal to…

TFS中的工作项(六)

TFS中的工作项 在VS中打开团队资源管理器 工作项有功能&#xff0c;产品积压工作项&#xff0c;任务&#xff0c;测试用例&#xff0c;Bug&#xff0c;障碍&#xff0c;它们之间的关系是&#xff1a;一个产品或应用&#xff0c;有一系列功能&#xff0c;功能最大&#xff0c;可…

单目3D物体检测模型(CaDDN): Categorical Depth Distribution Network for Monocular 3D Object Detection

本文介绍一篇单目3D物体检测模型&#xff1a;CaDDN&#xff0c;论文收录于 CVPR2021。 单目3D物体检测的主要挑战在于准确预测物体深度&#xff0c;由于缺乏直接的距离测量&#xff0c;因此必须根据物体和场景线索来推断物体深度。过去许多方法试图直接估计深度来辅助3D检测&am…

【PAT - 甲级1003】Emergency (25分)(Dijkstra,最短路条数,双权值最短路)

题干&#xff1a; As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of…

抠图、换背景、正装图证件照制作方法

本篇灵感是最近又要使用别的底色的正装照的图片。上学的时候&#xff0c;要求证件照的底色是蓝底、党员档案里要求图片的底色是红底、 将来上班的证件照要求是白底&#xff0c;并且无论是考研还是找工作都是制作简历的时候&#xff0c;根据简历的样板不同需要更换不同的底色。 …

TFS的Web门户工作项(七)

在TFS的web门户中有更丰富和更全面的设置和数据展示。 Web门户如图有A&#xff0c;B&#xff0c;C&#xff0c;D四部分组成。A部分为团队项目和项目切换&#xff0c;登录人员和登录人员切换。B部分是Web门户主要功能的菜单&#xff0c;C部分是当前团队项的一些信息的展示&#…

详解多视角3D检测模型 BEVDepth: Acquisition of Reliable Depth for Multi-view 3D Object Detection

本文介绍一个多视角的3D检测模型&#xff1a;BEVDepth&#xff0c;论文收录于 AAAI2023。在这篇文章中&#xff0c;作者提出了一种新的具有可信深度估计的三维物体检测器。本文提出的BEVDepth通过利用激光雷达显式深度监督来提高图像深度估计的可信度。作者引入了摄像机感知深度…

TFS版本管理(八)

目前TFS支持两种版本管理方式&#xff0c;一种是自带的TFS版本控制&#xff0c;一种是Git&#xff0c;后一种是分布式&#xff0c;并且分支功能相对强大&#xff0c;关于Git可以找更详细的资源学习。 如果没有创建项&#xff0c;在web门户中代码下的资源管理器是空的。 团队资…

【PAT - 甲级1006】Sign In and Sign Out (25分)(STLmap)

题干&#xff1a; At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing ins and outs, you are supposed to find the ones who have …

Python开发常用工具库

本文汇总了在使用Python开发时常用到的第三方库和工具。 1.Python 官网地址&#xff1a;https://www.python.org/doc/ 博文地址&#xff1a;《Python编程&#xff1a;从入门到实践》速查表 2.OpenCV&#xff08;图像处理&#xff09; 官网地址&#xff1a;https://opencv.o…

TFS中的统一集成(九)

首先要在TFS服务器上配置生成配置&#xff0c;操作如下&#xff1a; 现在可以创建一个生成定义了&#xff0c;单击团队资源管理器的生成。 新建生成定义&#xff1a; 这里选择的是手动。触发这个生成有很多条件&#xff0c;我们选择手动主式。 在要服务器上共享一个文件夹&…

【PAT - 甲级1009】Product of Polynomials (25分)(模拟,细节)

题干&#xff1a; This time, you are supposed to find AB where A and B are two polynomials. Input Specification: Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N​1​​ a​N​…

常用工具整理:数学,论文,代码等

1. Mathpix&#xff08;图片转数学公式工具&#xff09; 官网地址&#xff1a;Mathpix Snip在线LaTeX公式编辑&#xff1a;在线LaTeX公式编辑器-编辑器 (latexlive.com)推荐另一个开源的工具&#xff1a;Image to LaTex Converter&#xff0c;官网地址&#xff1a;GitHub - ki…

【PAT - 甲级1010】Radix (25分)(二分,进制转化)

题干&#xff1a; Given a pair of positive integers, for example, 6 and 110, can this equation 6 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number. Now for any pair of positive integers N​1​​ and N​2​​, your task …

C#中 ??、 ?、 ?: 、?.、?[ ]、:

1. 可空类型修饰符&#xff08;&#xff1f;&#xff09; 引用类型可以使用空引用表示一个不存在的值&#xff0c;而值类型通常不能表示为空。 例如&#xff1a;string strnull; 是正确的&#xff0c;int inull; 编译器就会报错。 为了使值类型也可为空&#xff0c;就可以使用…

几位无人驾驶领域的杰出科学家

本文介绍了几位无人驾驶领域杰出的科学家们&#xff0c;大家可以关注他们的主页&#xff0c;及时了解一些无人驾驶行业最新动态。 &#xff08;当然还有很多杰出的科学家&#xff0c;这里不一一列举了&#xff0c;暂时只列举出4位&#xff1a;3位外国科学家1位中国科学家&#…

【PAT - 甲级1012】The Best Rank (25分)

题干&#xff1a; To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we encourage s…

Razor语法和Razor引擎大全

一、Razor语法 1、Razor的标识符 解释&#xff1a;字符被定义为Razor服务器代码块的标识符&#xff0c;后面的表示是服务器代码了。web form中使用<%%>中写服务器代码一个道理。在vs工具里面提供了代码着色和智能感应的功能。 { string userName "启超"; &…