1095. Cars on Campus (30)
2015-12-06 11:54
447 查看
(模拟题)
时间限制220 ms
内存限制65536 kB
代码长度限制16000 B
判题程序Standard作者CHEN, Yue
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:
来源: <http://www.patest.cn/contests/pat-a-practise/1095>
[/code]
来自为知笔记(Wiz)
时间限制220 ms
内存限制65536 kB
代码长度限制16000 B
判题程序Standard作者CHEN, Yue
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:00Sample Output:
1 4 5 2 1 0 1 JH007BD ZD00001 07:20:09
来源: <http://www.patest.cn/contests/pat-a-practise/1095>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<string.h>
#pragma warning(disable:4996)
using namespace std;
struct Recode {
char card[8];
char time[9];
char statue[4];
int timeTrans;
int stat;
};
struct Car {
int intime = -1;
int outtime = -1;
int staytime = 0;
};
int totalStatue[86401] = { 0 };
map<string, Car> mp;
vector<Recode> r;
vector<string> longStay;
int longStayTime = 0;
bool cmp(Recode a,Recode b) {
return a.timeTrans < b.timeTrans;
}
bool cmpCard(string a,string b) {
return a < b;
}
int main(void) {
freopen("Text.txt", "r", stdin);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
Recode temp;
scanf("%s %s %s", temp.card, temp.time, temp.statue);
if (temp.statue[0] == 'i')
temp.stat = 0;//in
else
temp.stat = 1;//out
int ah, am, as;
sscanf(temp.time, "%d:%d:%d", &ah, &am, &as);
temp.timeTrans = ah * 3600 + am * 60 + as;
r.push_back(temp);
}
sort(r.begin(), r.end(), cmp);
for (int i = 0; i < n; i++) {
string cardStr;
int q = 0;
while (r[i].card[q] != 0) {
cardStr += r[i].card[q];
q++;
}
if (r[i].stat == 0) {
mp[cardStr].intime = r[i].timeTrans;
}
if (r[i].stat == 1) {
if (mp[cardStr].intime == -1) {
continue;
}
else {
mp[cardStr].outtime = r[i].timeTrans;
totalStatue[mp[cardStr].intime]++;
totalStatue[mp[cardStr].outtime]--;
mp[cardStr].staytime += (mp[cardStr].outtime - mp[cardStr].intime);
mp[cardStr].outtime = -1;
mp[cardStr].intime = -1;
if (mp[cardStr].staytime > longStayTime) {
longStay.clear();
longStay.push_back(cardStr);
longStayTime = mp[cardStr].staytime;
}
else if(mp[cardStr].staytime == longStayTime) {
longStay.push_back(cardStr);
}
}
}
}
int lastCheckTime = -1, hasCar = 0;
for (int i = 0; i < m; i++) {
char checkTime[9];
scanf("%s", checkTime);
int ch, cm, cs;
sscanf(checkTime, "%d:%d:%d", &ch, &cm, &cs);
int ctime = ch * 3600 + cm * 60 + cs;
//cout << totalStatue[ctime] << endl;
for (int j = lastCheckTime+1; j <= ctime; j++) {
if (totalStatue[j] != 0) {
hasCar += totalStatue[j];
}
}
lastCheckTime = ctime;
printf("%d\n", hasCar);
}
sort(longStay.begin(), longStay.end(), cmpCard);
for (int i = 0; i < longStay.size(); i++) {
cout << longStay[i] << " ";
}
int lh, lm, ls;
lh = longStayTime / 3600;
lm = longStayTime / 60 % 60;
ls = longStayTime % 60;
printf("%02d:%02d:%02d", lh, lm, ls);
return 0;
}
[/code]
来自为知笔记(Wiz)
相关文章推荐
- laravel的安装
- java程序开发工具集的使用
- NUPT大二队员淘汰赛1题解
- 1094. The Largest Generation (25)
- Vim命令合集
- Java编程高手对CLASSPATH应用的详细介绍
- DevExpress GridView 列标题文字设置
- 1093. Count PAT's (25)
- JavaScript-offsetWidth,clientWidth,scrollWidth,及对应top、left区别及实测结果
- Spring.NET学习笔记3——实现一个简易的IoC框架(练习篇) Level 100
- 1092. To Buy or Not to Buy (20)
- J2EE入门—浅谈J2EE的十三个规范
- 找不到类型“ITOO.ExamEvalTemplate.WCFService.ServiceBusines”
- Hoodp 的入门基础
- 1091. Acute Stroke (30)
- 教你怎么用WIN7系统自带工具调整硬盘分区
- 戒指
- 1090. Highest Price in Supply Chain (25)
- Linux任务计划及sudo详解
- MySQL on Azure高可用性设计 DRBD - Corosync - Pacemaker - CRM (二)