1095. Cars on Campus
来源:互联网 发布:素描画图软件 编辑:程序博客网 时间:2024/05/16 08:58
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 7JH007BD 18:00:01 inZD00001 11:30:08 outDB8888A 13:00:00 outZA3Q625 23:59:50 outZA133CH 10:23:00 inZD00001 04:09:59 inJH007BD 05:09:59 inZA3Q625 11:42:01 outJH007BD 05:10:33 inZA3Q625 06:30:50 inJH007BD 12:23:42 outZA3Q625 23:55:00 inJH007BD 12:24:23 outZA133CH 17:11:22 outJH007BD 18:07:01 outDB8888A 06:30:50 in05:10:0006:30:5011:00:0012:23:4214:00:0018:00:0023:59:00Sample Output:
1452101JH007BD ZD00001 07:20:09
#include<iostream>#include<algorithm>#include<string>#include<vector>#include<set>using namespace std;typedef struct node{string id;int t;bool state;};bool cmp(node x,node y){if(x.id!=y.id)return x.id<y.id;elsereturn x.t<y.t;}node info[10000];vector <int> incnt(24*60*60);vector <int> outcnt(24*60*60);int main(){int n,k;cin>>n>>k;for(int i=0;i<n;++i){int h,m,s;string state;cin>>info[i].id;scanf("%d:%d:%d",&h,&m,&s);cin>>state;info[i].t=h*3600+m*60+s;info[i].state=(state=="in")?true:false;}sort(info,info+n,cmp);set <string> maxid;int maxt=0;int sumt=0;for(int i=1;i<n;i++){if(info[i].id==info[i-1].id){if(!info[i].state&&info[i-1].state){incnt[info[i-1].t]++;outcnt[info[i].t]++;sumt=sumt+info[i].t-info[i-1].t;if(sumt>maxt){maxt=sumt;maxid.clear();maxid.insert(info[i].id);}else if(sumt==maxt)maxid.insert(info[i].id);}}else{sumt=0;}}int carnum=0;int cnt=0;for(int i=0;i<k;++i){int h,m,s;scanf("%d:%d:%d",&h,&m,&s);int t=h*3600+m*60+s;while(cnt<=t){carnum=carnum+incnt[cnt]-outcnt[cnt];cnt++;}cout<<carnum<<endl;}for(auto str=maxid.begin();str!=maxid.end();++str)cout<<*str<<" ";printf("%02d:%02d:%02d\n",maxt/3600,maxt%3600/60,maxt%3600%60);return 0;}
- 1095.Cars on Campus
- 1095. Cars on Campus
- 1095. Cars on Campus
- 1095. Cars on Campus
- 1095. Cars on Campus (30)
- PAT 1095. Cars on Campus
- 1095. Cars on Campus (30)
- 1095. Cars on Campus (30)
- 1095. Cars on Campus (30)
- 1095. Cars on Campus (30)
- 1095. Cars on Campus (30)
- 1095. Cars on Campus (30)
- 1095. Cars on Campus (30)
- 1095. Cars on Campus (30)
- 1095. Cars on Campus (30)
- 1095. Cars on Campus (30)
- 1095. Cars on Campus (30)
- 1095. Cars on Campus (30)
- 基本分页、请求分页储存管理方式
- xargs的原理剖析及用法详解
- 集合类浅谈(1)
- 简易mvc框架配置类和日志类的简单实现
- js继承的实现
- 1095. Cars on Campus
- swift判断app第一次启动
- Angular解决输入框由禁用状态转可用状态自动获取焦点失效问题
- (10) java源码分析 ---- HashMap源码分析 及其 实现原理分析
- 7天入门php-文件打开/读取/写/常用判断
- python -- 配置mysql
- Oracle数据库安装先决条件检查失败解决方案
- 12
- Java8(jdk8)接口与抽象类的区别