1095. Cars on Campus (30)
Zhejiang University has 6 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 (<= 10000), the number of records, and K (<= 80000) 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
- #include<string>
- #include<iostream>
- #include<map>
- #include<stdio.h>
- #include<vector>
- #include<algorithm>
- #include<string.h>
- #include<stdlib.h>
- using namespace std;
- struct car
- {
- bool tag;
- int t;
- };
- map<string, vector<car> > smap;
- int hOfcar[];
- int numOfcar[**];
- bool cmp(car a,car b)
- {
- return a.t < b.t;
- }
- struct result
- {
- char name[];
- int t;
- long long id;
- };
- long long toInt(char name[])
- {
- long long id = ;
- for(int i = ;i <;++i)
- {
- int tem = ;
- if(name[i] >='' && name[i] <= '')
- tem = name[i] - '';
- else if(name[i] >='A' && name[i] <= 'Z')
- tem = name[i] - 'A' + ;
- id = id * + tem;
- }
- return id;
- }
- bool cmp2(result a,result b)
- {
- return a.id < b.id;
- }
- int main()
- {
- int n,m,hh,mm,ss;
- scanf("%d%d",&n,&m);
- char name[],tag[];
- car ctem;
- for(int i = ;i < n ;++i)
- {
- scanf("%s %d:%d:%d %s",name,&hh,&mm,&ss,tag);
- ctem.t = hh** + mm * + ss;
- if(tag[] == 'i')
- {
- ctem.tag = ;
- }
- else ctem.tag = ;
- smap[name].push_back(ctem);
- }
- vector<result> vv;
- for(map<string, vector<car> >::iterator it = smap.begin();it != smap.end();++it)
- {
- sort(it->second.begin(),it->second.end(),cmp);
- int size = it->second.size();
- int sum = ;
- for(int i = ;i < size - ;++i)
- {
- while(i < size - &&(!(!it->second[i].tag && it->second[i+].tag)))
- ++i;
- if(i < size -)
- {
- //不能直接遍历,否则最后一个case会超时
- //hOfcar[k], 保存该车在第k时全都停留,则加一
- int hlow = it->second[i].t / +;
- int hhigh = it->second[i+].t / ;
- for(int k = hlow ; k < hhigh;++k)
- ++hOfcar[k];
- //剩余部分
- if(hlow <= hhigh)
- {
- for(int k = it->second[i].t ;k < hlow * ;++k)
- ++numOfcar[k];
- for(int k = hhigh* ;k < it->second[i+].t ;++k)
- ++numOfcar[k];
- }
- else//注意 in 和 out 是在同一个小时的情况!
- {
- for(int k = it->second[i].t ;k < it->second[i+].t ;++k)
- ++numOfcar[k];
- }
- sum += it->second[i+].t - it->second[i].t;
- }
- }
- if(vv.empty() || sum == vv[].t)
- {
- result rtem;
- strcpy(rtem.name,it->first.c_str());
- rtem.id = toInt(rtem.name);
- rtem.t = sum;
- vv.push_back(rtem);
- }
- else if(sum > vv[].t)
- {
- vv.clear();
- result rtem;
- strcpy(rtem.name,it->first.c_str());
- rtem.id = toInt(rtem.name);
- rtem.t = sum;
- vv.push_back(rtem);
- }
- }
- for(int i = ;i < m;++i)
- {
- scanf("%d:%d:%d",&hh,&mm,&ss);
- int t = hh** + mm * + ss;
- printf("%d\n",hOfcar[hh]+numOfcar[t]);
- }
- sort(vv.begin(),vv.end(),cmp2);
- for(int i = ;i < vv.size();++i)
- {
- printf("%s ",vv[i].name);
- }
- printf("%02d:%02d:%02d\n",vv[].t/,(vv[].t%)/,vv[].t%);
- return ;
- }
1095. Cars on Campus (30)的更多相关文章
- PAT (Advanced Level) Practise - 1095. Cars on Campus (30)
http://www.patest.cn/contests/pat-a-practise/1095 Zhejiang University has 6 campuses and a lot of ga ...
- 1095 Cars on Campus (30)(30 分)
Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out time ...
- PAT (Advanced Level) 1095. Cars on Campus (30)
模拟题.仔细一些即可. #include<cstdio> #include<cstring> #include<cmath> #include<algorit ...
- PAT甲题题解-1095. Cars on Campus(30)-(map+树状数组,或者模拟)
题意:给出n个车辆进出校园的记录,以及k个时间点,让你回答每个时间点校园内的车辆数,最后输出在校园内停留的总时间最长的车牌号和停留时间,如果不止一个,车牌号按字典序输出. 几个注意点: 1.如果一个车 ...
- 【PAT甲级】1095 Cars on Campus (30 分)
题意:输入两个正整数N和K(N<=1e4,K<=8e4),接着输入N行数据每行包括三个字符串表示车牌号,当前时间,进入或离开的状态.接着输入K次询问,输出当下停留在学校里的车辆数量.最后一 ...
- PAT甲级——1095 Cars on Campus (排序、映射、字符串操作、题意理解)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93135047 1095 Cars on Campus (30 分 ...
- PAT 1095 Cars on Campus
1095 Cars on Campus (30 分) Zhejiang University has 8 campuses and a lot of gates. From each gate we ...
- 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甲级1095. Cars on Campus
PAT甲级1095. Cars on Campus 题意: 浙江大学有6个校区和很多门.从每个门口,我们可以收集穿过大门的汽车的进/出时间和车牌号码.现在有了所有的信息,你应该在任何特定的时间点告诉在 ...
随机推荐
- 树形菜单复选框级联选择HTML
模块标题 标识符 类别 链接 排序 系统管理 组 1 用户权限设定 Sys_UserModelConfigList 模块 Sys_UserModelConfigList.aspx 1 角色管理 ...
- 使用JDBC-ODBC读取Excel文件
以下代码我没有真正去实践,紧做为总结,方便以后查阅: 这种方法需要设置ODBC源..... 参考: http://xytang.blogspot.com/2008/02/how-to-connect- ...
- 洛谷P1251 餐巾(网络流)
P1251 餐巾 15通过 95提交 题目提供者该用户不存在 标签网络流贪心 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 为什么我全部10个测试点都对… 题目描述 一个餐厅在相继的N天里 ...
- innerHTML与innerText的PK
一.innerText属性用来定义对象所要输出的文本,在本例中innerText把对象it中的文本"您喜欢看微微一笑很倾城吗?"变成了"超级喜欢!"(语句it. ...
- MongoDB - Introduction of the mongo Shell
Introduction The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mong ...
- php学习笔记1--开发环境搭建:apache+php+mysql
php开发环境搭建:apache + php + mysql1.下载apache,php及mysql安装包2.安装apache:下载的apache若是.msi可直接双击,按指示一步一步安装:(若操作系 ...
- Android 动画学习笔记
Android动画的两种:Frame帧动画.Tween动画(位移动画)[实现:存放目录res/anim] Tween动画:(位移.缩放.旋转):通过对场景里的对象不断做图像变换. 四种效果Alpha. ...
- android ListView下拉刷新 上拉加载更多
背景 最近在公司的项目中要使用到ListView的下拉刷新和上拉加载更多(貌似现在是个项目就有这个功能!哈哈),其实这个东西GitHub上很多,但是我感觉那些框架太大,而且我这个项目只用到了ListV ...
- MySQL之建设工程监管信息系统
--创建SelfStudy数据库 CREATE DATABASE ConstructionDB ON PRIMARY --创建主数据库文件 ( NAME=' ConstructionDB', --数据 ...
- JAVA之执行cmd命令
感言在前:时隔好久没有更新博客园了,忙东忙西也没忙出个什么之所以然来.回首过去一两个月,只能用“疲倦”两个字来形容,而且是身心疲惫.每天11.12个小时的工作我都没觉得烦,但是总是想克服却又很难克服的 ...