A1095 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 (≤), 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 accendingorder 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注意点:1.查询时 now 必须放在外面不然会重复循环导致超时!!!
4
5
2
1
0
1
JH007BD ZD00001 07:20:09
2.清空cout缓存用cout<<flush;否则使用ios::sync_with_stdio(false);
cin.tie(0)时不与printf兼容,可能输出顺序错误。
#include<bits/stdc++.h>
using namespace std; const int maxn=; struct Record{
string carId;
int hh;
int mm;
int ss;
int time;
string status;
int flag;
}rec[maxn],valid[maxn]; int n,k; map<string,int> parkTime; int num=;
int maxTime=-; bool cmp1(Record a,Record b){
if(a.carId!=b.carId)
return a.carId<b.carId;
else
return a.time<b.time;
} bool cmp2(Record a,Record b){ return a.time<b.time; } int main(){ ios::sync_with_stdio(false);
cin.tie(); cin>>n>>k; // scanf("%d%d",&n,&k); char c;
Record temp; for(int i=;i<n;i++){
cin>>temp.carId>>temp.hh>>c>>temp.mm>>c>>temp.ss>>temp.status; //char str1[100];
//char str2[100];
//scanf("%s %d:%d:%d %s",&str1[0],&temp.hh,&temp.mm,&temp.ss,&str2[0]);
//temp.carId=str1;
//temp.status=str2; temp.time=temp.hh*+temp.mm*+temp.ss; if(temp.status=="in")
temp.flag=;
else
temp.flag=; rec[i]=temp;
} sort(rec,rec+n,cmp1); for(int i=;i<n-;i++){
if(rec[i].carId==rec[i+].carId&&
rec[i].flag==&&rec[i+].flag==){
valid[num++]=rec[i];
valid[num++]=rec[i+]; string carId=rec[i].carId; if(parkTime.count(carId)==){
parkTime[carId]=;
} parkTime[carId]+=(rec[i+].time-rec[i].time); maxTime=max(maxTime,parkTime[carId]); }
} sort(valid,valid+num,cmp2); int now=,nowCar=; //now必须放外面 for(int i=;i<k;i++){
int hh,mm,ss;
char c; cin>>hh>>c>>mm>>c>>ss; //scanf("%d:%d:%d",&hh,&mm,&ss); int queryTime=hh*+mm*+ss; while(now<num&&valid[now].time<=queryTime){
if(valid[now].flag==) nowCar++;
else nowCar--; now++; } cout<<nowCar<<endl; //printf("%d\n",nowCar); } for(map<string,int>::iterator it = parkTime.begin(); it != parkTime.end();it++){
if(it->second==maxTime)
{
cout<<it->first<<" "; // printf("%s ",it->first.c_str());
}
} cout<<flush; //清空cout缓存 //cout<<maxTime<<" "<<parkTime["JH007BD"]<<" "<<parkTime["ZD00001"]<<endl; printf("%02d:%02d:%02d\n",maxTime/,(maxTime/)%,maxTime%); return ;
}
A1095 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甲级】1095 Cars on Campus (30 分)
题意:输入两个正整数N和K(N<=1e4,K<=8e4),接着输入N行数据每行包括三个字符串表示车牌号,当前时间,进入或离开的状态.接着输入K次询问,输出当下停留在学校里的车辆数量.最后一 ...
- pat 甲级 Cars on Campus (30)
Cars on Campus (30) 时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard 题目描述 Zhejiang University ...
- 【刷题-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 ...
- 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 ...
- 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 ...
- 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 ...
- A1095. Cars on Campus
Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out time ...
- 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 ...
随机推荐
- Android中的Service的使用详解
按运行地点分类: 类别 区别 优点 缺点 应用 本地服务(Local) 该服务依附在主进程上, 服务依附在主进程上而不是独立的进程,这样在一定程度上节约了资源,另外Local服务因为是在同一进程因此不 ...
- form提交跳转问题
$.ajax({ type: "POST", url: url, data: $('.form-horizontal').serialize(), 提交form表单 success ...
- 17、通过maven生成测试报告
目录如下: 通过Maven 生成报告 进入testngTest根目录,运行mvn test 命令 进入 testngTest\target\surefire-reports 路径查看测试报告
- BZOJ 2460 & 洛谷 P4570 [BJWC2011]元素 (线性基 贪心)
题目链接: 洛谷 BZOJ 题意 给定 \(n\) 个矿石,每个矿石有编号和魔力值两种属性,选择一些矿石,使得魔力值最大且编号的异或和不为 0. 思路 线性基 贪心 根据矿石的魔力值从大到小排序. 线 ...
- Gerrit(1): Manage Projects
1) Register an openid account https://login.ubuntu.com/+login 2) Custom settings set SSH pubkey set ...
- 拾遗:govendor(Golang 依赖库版本控制)
官方资料: https://github.com/kardianos/govendor https://github.com/kardianos/govendor/blob/master/doc/fa ...
- python+tushare获取股票每日停复牌信息
接口:suspend 更新时间:不定期 描述:获取股票每日停复牌信息 注:tushare模块下载和安装教程,请查阅我之前的文章 输入参数 名称 | 类型 | 必 ...
- Python匿名函数(lambda函数)
匿名函数 -- 一行函数 lambda -- 关键字 x是普通函数的形参(位置,关键字...)可以不接收参数(x可以不写) :x是普通函数的函数值(只能返回一个数据类型)(:x返回值必须写) 1)此函 ...
- <随便写>软件设计遵循的基本原则
1.高内聚,低耦合 所谓高内聚,是指一个软件模块内各个元素彼此结合的紧密程度要高,即一个软件模块是由相关性很强的代码组成,只负责一项任务,也就是常说的单一责任原则. 所谓低耦合,是指一个软件系统内不同 ...
- 【构造共轭函数+矩阵快速幂】HDU 4565 So Easy! (2013 长沙赛区邀请赛)
[解题思路] 给一张神图,推理写的灰常明白了,关键是构造共轭函数,这一点实在是要有数学知识的理论基础,推出了递推式,接下来就是矩阵的快速幂了. 神图: 给个大神的链接:构造类斐波那契数列的矩阵快速幂 ...