Cars on Campus (30)
https://www.nowcoder.com/pat/5/problem/4319
题目大意:给你一n个无序的停车场汽车进出情况日志,包括汽车车牌,记录时间和事件(in 或out),n最大为10000.
然后询问m次,每次给出一个事件点,要求输出该时刻停车场有多少辆车。最后输出在停车场停留最长的车和停留的时间。
分析:
1.一个场景,两个问题,用到的数据较多,比较繁琐。
2.给出的数据无序,可以先处理数据,让时间变得有序再进行下一步。
3.题目中有个大坑,只有同一辆车先后进入的数据有效,只进不出货进了有进这样的
情况一定要特别处理。
4.由于在同一日发生,最多只有86400s,所以每个时刻有多少车辆可以开一个数组来记录,切不可每次都遍历。
…
My code
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 10009;
const int maxns = 3600 * 24 + 10; //the totall second number in a a day
struct Indata{
//the input data
int time;
string name;
bool even;
bool operator < (const Indata& n){
//the method of sort Indata
return this->time < n.time;
}
}indata[maxn];
struct Log{
int time; //the seconde from 0:0:0 of a monent
bool even; //true mean in and false mean out
};
struct Car{
vector<Log>log; //a Car can have multipult of log
string name;
int sumtime; //total time of stay in campus
}car[maxn];
int car_size = 1;//the length - 1 of car[