当前位置:网站首页>1095 cars on campus (30 points)
1095 cars on campus (30 points)
2022-07-03 04:55:00 【vs5】
The main idea of the topic : Give the entry and exit time of each license plate , every last in Only with the next one with the same number out matching , If there's no match in or out Is ignored , Then give the corresponding inquiry , Find out how many cars stay in a certain period of time , And find the longest time to stay .
Ideas :
1. First, read all the data and sort by license plate number and time .( Convert time into seconds )
2. Comparing the two , Deal with legal license plates , And use map Save the total stay time of each license plate , Record the maximum .
3. Deal with inquiries , The number of vehicles staying in each time period can be pretreated ( The prefix and , After testing, there is no prefix and no timeout )
4. The last step is to traverse map Output the license plate with the same dwell time
If the vehicle that stays for the longest time is not unique , Output in dictionary order , It can be used directly map save , Guaranteed dictionary order .
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
// Convert time into seconds
struct node
{
string s;
int time,flag;
bool operator < (const node&W)
{
if(s != W.s) return s < W.s;// Put the same brand together
return time < W.time;
}
}e[10010];
int pre[10010];
map<string,int>mp;
int main()
{
int n,k,maxtime = 0;
cin >> n >> k;
for(int i = 0; i < n; i ++)
{
char zt[10];int a,b,c;
cin >> e[i].s;
scanf("%d:%d:%d %s",&a,&b,&c,zt);
e[i].time = a * 3600 + b * 60 + c;
if(zt[0] == 'i') e[i].flag = 1;
else e[i].flag = -1;
}
sort(e,e + n);
vector<node>ans;
for(int i = 0 ; i < n - 1; i ++)
{
if(e[i].s == e[i + 1].s && e[i].flag == 1 && e[i + 1].flag == -1)
{
ans.push_back(e[i]),ans.push_back(e[i + 1]);
mp[e[i].s] +=(e[i + 1].time - e[i].time);
maxtime = max(maxtime,mp[e[i].s]);
}
}
sort(ans.begin(),ans.end(),[](node a,node b)
{
return a.time < b.time;
});
for(int i = 0 ; i < ans.size(); i ++)
{
if(i == 0) pre[i] = ans[i].flag;
else pre[i] = pre[i - 1] + ans[i].flag;// The prefix and
}
int last = 0;
while(k --)
{
int a,b,c;
scanf("%d:%d:%d",&a,&b,&c);
int t = a * 3600 + b * 60 + c,cnt = 0;
for(int i = last; i < ans.size(); i ++)
{
if(ans[i].time > t)
{
printf("%d\n",pre[i - 1]);
break;
}
else if (i == ans.size() - 1) printf("%d\n",pre[i]);
last = i;
}
}
for(auto it : mp)
{
if(it.second == maxtime) printf("%s ",it.first.c_str());
}
printf("%02d:%02d:%02d",maxtime / 3600, maxtime % 3600 / 60, maxtime % 60);
return 0;
}边栏推荐
- Network security textual research recommendation
- Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly
- Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
- [luatos sensor] 2 air pressure bmp180
- Valentine's day limited withdrawal guide: for one in 200 million of you
- [tools run SQL blind note]
- Market status and development prospects of the global IOT active infrared sensor industry in 2022
- Literature reading_ Research on the usefulness identification of tourism online comments based on semantic fusion of multimodal data (Chinese Literature)
- Do you know UVs in modeling?
- MC Layer Target
猜你喜欢

联发科技2023届提前批IC笔试(题目)
![[research materials] 2021 China's game industry brand report - Download attached](/img/b7/a377b0b7c742078e2feb28ebfbca62.jpg)
[research materials] 2021 China's game industry brand report - Download attached

ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation

2022-02-11 daily clock in: problem fine brush

论文阅读_清华ERNIE

Silent authorization login and registration of wechat applet
![[tools run SQL blind note]](/img/c3/86db4568b221d2423914990a88eec2.png)
[tools run SQL blind note]

Kept hot standby and haproxy

MPM model and ab pressure test

逆袭大学生的职业规划
随机推荐
Number of uniform strings of leetcode simple problem
[luatos sensor] 1 light sensing bh1750
1114 family property (25 points)
Uipath practice (08) - selector
General undergraduate college life pit avoidance Guide
移动端——uniapp开发记录(公共请求request封装)
Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022
Silent authorization login and registration of wechat applet
[tools run SQL blind note]
关于开学的准备与专业认知
Wechat applet distance and map
Realize file download through the tag of < a > and customize the file name
MC Layer Target
I stepped on a foundation pit today
MySQL winter vacation self-study 2022 12 (3)
1118 birds in forest (25 points)
document. The problem of missing parameters of referer is solved
[USACO 2009 Dec S]Music Notes
Why does I start with =1? How does this code work?
I've seen a piece of code in the past. I don't know what I'm doing. I can review it when I have time