http://www.patest.cn/contests/pat-a-practise/1095

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

这道题是2015考研机试前的那个PAT的D题 http://www.patest.cn/contests/pat-a-101-125-1-2015-03-14

那次PAT据说比机试简单。。。于是很多高分大神申请了免机试。。。性价比超高。。。。

我表示很忧伤。。。虽然我对自己机试成绩还算满意,但是还是有点感慨。。。如果参加这次PAT 说不定分数更好。。。嗯,做梦的感觉好好好哦。。。

T_T  并不能轻易的承认 这貌似是我在pat上扯过的最长的代码了。。。不过好消息是A级我才做三分之一不到 哈哈哈哈 说不定有更长的

 #include<cstdio>
#include<cstring>
struct carrecord
{
long long carid;
int second;
int status; // 1-in 0-out
}records[];
int recordsnum=,queriesnum=,time[][]={}; long long str2int(char *str)//一个大于 (26字母+10数字)的数值即可 用于保持比较时有效的字典序列
{
long long num=,istr=;
while(str[istr]) num=num*+((''<=str[istr]&&str[istr]<='')?str[istr]-'':str[istr]-'A'+),istr++;
return num;
} void outlook(long long num)//一条记录输出
{
char car[]="";
int istr=,temp=;
car[]='\0';
while(istr>=)//int2str 恢复字符串名字
{
temp=num%;
if(temp>=) car[istr]=temp+'A'-;
else car[istr]=temp+'';
num/=,istr--;
}
printf("%s ",car);
} //基于汽车牌号(以转为对应序列的数值)和进出时间的快排
void QS(int low,int high,const int iqs) //1-carid 0-time
{
int l=low,h=high,second=records[l].second,status=records[l].status;
long long carid=records[l].carid; while(l<h)
{
if(iqs) while( l<h && (carid<records[h].carid ||(carid==records[h].carid && second<=records[h].second))) h--;
else while( l<h && (second<records[h].second ||( carid<=records[h].carid && second==records[h].second ))) h--;
if(l<h)
{
records[l].carid=records[h].carid;
records[l].second=records[h].second;
records[l].status=records[h].status; records[h].carid=carid;
records[h].second=second;
records[h].status=status;
} if(iqs) while( l<h && (carid>records[l].carid||(carid==records[l].carid&& second>=records[l].second))) l++;
else while( l<h && (second>records[l].second ||(carid>=records[l].carid&& second==records[l].second))) l++;
if(l<h)
{
records[h].carid=records[l].carid;
records[h].second=records[l].second;
records[h].status=records[l].status; records[l].carid=carid;
records[l].second=second;
records[l].status=status;
}
}
if(low+<l) QS(low,l-,iqs);
if(h+<high) QS(h+,high,iqs);
} int clean(int len,int in,int out)
{
int l=len,h=in;
records[l].carid=records[h].carid;
records[l].second=records[h].second;
records[l].status=records[h].status; l=l+,h=out;
records[l].carid=records[h].carid;
records[l].second=records[h].second;
records[l].status=records[h].status; return len+;
} int main()
{
scanf("%d%d",&recordsnum,&queriesnum); char carname[],status[];
int hh,mm,ss;
for(int i=;i<=recordsnum;i++)//从1开始是为了方便下面记录配对时直接移动即可 而不需temp
{
scanf("%s %d:%d:%d %s",carname,&hh,&mm,&ss,status);
records[i].carid=str2int(carname);// 比较、移动、复制等,操作简单,节省时间
records[i].second=ss+*(mm+*hh);
records[i].status=(==strcmp(status,"in")?:);
}
QS(,recordsnum,);// 基于汽车牌号(以转为对应序列的数值)的QS int num=,len=,flagin=-,flagout=-;
long long carid=;
while(num<=recordsnum)// Each "in" record is paired with the chronologically next record for the same car provided it is an "out" record
{
flagin=-,flagout=-,carid=records[num].carid;
while(carid==records[num].carid && num<=recordsnum) // Any "in" records that are not paired with an "out" record are ignored, as are "out" records not paired with an "in" record.
{
if(==records[num].status) flagin=num,flagout=-;
else if(-==flagin) flagin=-,flagout=-;
else len=clean(len,flagin,num),flagin=-,flagout=-;
num++;
}
}
recordsnum=len;
QS(,recordsnum-,); num=;
int istr=,carnum=,notfirst=;
if(recordsnum) notfirst=;
while(num<queriesnum) //For each query, output in a line the total number of cars parking on campus
{
scanf("%d:%d:%d",&hh,&mm,&ss);
len=ss+*(mm+*hh);
while(len>=records[istr].second && istr<recordsnum)
{
if(records[istr].status) carnum++;
else carnum--;
istr++;
}
if(num<queriesnum-notfirst) printf("%d\n",carnum);
else printf("%d",carnum);
num++;
} QS(,recordsnum-,);
num=,istr=,flagout=;
while(num<recordsnum) //the longest time period parked for
{
istr=,carid=records[num].carid;
while(carid==records[num].carid && num<recordsnum)
{
istr+=records[num+].second-records[num].second;
records[num+].second=-,records[num].second=-;
num+=;
}
records[num-].second=istr;
if(istr>flagout) flagout=istr;
} for(int i=;i<recordsnum;i++)
if(records[i].second==flagout) outlook(records[i].carid); //give the plate number of the car that has parked for the longest time period
printf("%02d:%02d:%02d",flagout/,(flagout/)%,flagout%); //and the corresponding time length
return ; }

PAT (Advanced Level) Practise - 1095. Cars on Campus (30)的更多相关文章

  1. PAT甲题题解-1095. Cars on Campus(30)-(map+树状数组,或者模拟)

    题意:给出n个车辆进出校园的记录,以及k个时间点,让你回答每个时间点校园内的车辆数,最后输出在校园内停留的总时间最长的车牌号和停留时间,如果不止一个,车牌号按字典序输出. 几个注意点: 1.如果一个车 ...

  2. PAT (Advanced Level) 1095. Cars on Campus (30)

    模拟题.仔细一些即可. #include<cstdio> #include<cstring> #include<cmath> #include<algorit ...

  3. PAT (Advanced Level) Practise - 1094. The Largest Generation (25)

    http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...

  4. PAT (Advanced Level) Practise 1004 解题报告

    GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...

  5. PAT (Advanced Level) Practise - 1092. To Buy or Not to Buy (20)

    http://www.patest.cn/contests/pat-a-practise/1092 Eva would like to make a string of beads with her ...

  6. PAT (Advanced Level) Practise - 1093. Count PAT's (25)

    http://www.patest.cn/contests/pat-a-practise/1093 The string APPAPT contains two PAT's as substrings ...

  7. 1079. Total Sales of Supply Chain (25)【树+搜索】——PAT (Advanced Level) Practise

    题目信息 1079. Total Sales of Supply Chain (25) 时间限制250 ms 内存限制65536 kB 代码长度限制16000 B A supply chain is ...

  8. PAT (Advanced Level) Practise - 1099. Build A Binary Search Tree (30)

    http://www.patest.cn/contests/pat-a-practise/1099 A Binary Search Tree (BST) is recursively defined ...

  9. 1076. Forwards on Weibo (30)【树+搜索】——PAT (Advanced Level) Practise

    题目信息 1076. Forwards on Weibo (30) 时间限制3000 ms 内存限制65536 kB 代码长度限制16000 B Weibo is known as the Chine ...

随机推荐

  1. Listener、Filter、Servlet的创建及初始化顺序

    一.创建顺序 1.web.xml文件中的加载顺序为:listener-filter-servlet 2.如果web.xml中配置了<context-param>,初始化顺序: contex ...

  2. mac上gradle升级版本

    参考:https://www.jianshu.com/p/9fa9d2b4dbc9    http://www.gradle.org/downloads下载gradle 终端输入:open .bash ...

  3. HTTP/TCP协议基础

    HTTP协议 基本概念 HTTP协议(超文本传输协议 HyperText Transfer Protocol):是用于从WWW服务器传输超文本到本地浏览器的传送协议.它不仅保证计算机正确快速地传输超文 ...

  4. 定时备份mysql数据库

    第一步:编写mysqldump备份数据库脚本,先新建txt文档,编辑内容为 @echo off set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%" ...

  5. 最简实例演示asp.net5中用户认证和授权(2)

    上接最简实例演示asp.net5中用户认证和授权(1) 基础类建立好后,下一步就要创建对基础类进行操作的类了,也就是实现基础类的增删改查(听起来不太高大上),当然,为了使用asp.net5的认证机制, ...

  6. ruby firefox23报错:waiting for evaluate.js load failed

    解决方法 gem install selenium-webdriver -v='2.34.0'

  7. P1868 饥饿的奶牛

    题目描述 有一条奶牛冲出了围栏,来到了一处圣地(对于奶牛来说),上面用牛语写着一段文字. 现用汉语翻译为: 有N个区间,每个区间x,y表示提供的x~y共y-x+1堆优质牧草.你可以选择任意区间但不能有 ...

  8. 安装flask-mysqldb的时候,提示 mysql_config not found 的解决方法

    解决办法: sudo apt-get install libmysqlclient-dev sudo updatedb locate mysql_config 然后进入mysql_config的路径( ...

  9. vue3.0学习笔记(二)

    一.选择合适的ide 推荐使用vs code编辑器,界面清晰.使用方便,控制台功能很好用.webstorm也可以,看个人喜好. 二.ui框架选择 目前,pc端一般是选择element ui(饿了么), ...

  10. spring-boot 配置jsp

    sring-boot 集成  jsp spring-boot默认使用的页面展示并不是jsp,若想要在项目中使用jsp还需要配置一番. 虽然spring-boot中也默认配置了InternalResou ...