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. Linux学习常用命令大全

    Linux知识大全 转载须说明出处,整理不易 一.常用的linux命令 1.2 ls 命令说明 1.3 ls 通配符的使用 2.切换目录cd命令 3.创建和删除文件操作 4.移动和拷贝文件 4.3.m ...

  2. h5自定义播放器得实现原理

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. C# AD 验证登陆

    using System.DirectoryServices; using System.DirectoryServices.AccountManagement; using (DirectoryEn ...

  4. matplotlib 知识点11:绘制饼图(pie 函数精讲)

    饼图英文学名为Sector Graph,又名Pie Graph.常用于统计学模块. 画饼图用到的方法为:matplotlib.pyplot.pie( ) #!/usr/bin/env python # ...

  5. Batch the files in the directory

    #!/bin/bash #sourceFolder = /home/bigdatagfts/pl62716/refdata #targetFolder = /home/bigdatagfts/pl62 ...

  6. CollabNet Subversion Edge 迁移的方法

    服务器迁移或重新搭建时,数据迁移方法,安装配置在https://www.cnblogs.com/pinpin/p/9889362.html种 这里只是迁移用户和数据,做个备注而且,比较简单所以不截图了 ...

  7. Python+Selenium----使用HTMLTestRunner.py生成自动化测试报告1(使用IDLE)

    1.说明 自动化测试报告是一个很重要的测试数据,网上看了一下,使用HTMLTestRunner.py生成自动化测试报告使用的比较多,但是呢,小白刚刚入手,不太懂,看了很多博客,终于生成了一个测试报告, ...

  8. ubuntu查看系统版本和内核版本

    查看系统版本: cat /etc/issue sudo lsb_release -a 查看内核版本: uname -r

  9. easyui databox获取当前时间

    class=easyui-datebox $(document).ready(function() {             $("#thedate").datebox(&quo ...

  10. 排序算法对比,步骤,改进,java代码实现

    前言 发现是时候总结一番算法,基本类型的增删改查的性能对比,集合的串并性能的特性,死记太傻了,所以还是写在代码里,NO BB,SHOW ME THE CODE! github地址:https://gi ...