当前位置:网站首页>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;
}边栏推荐
- First + only! Alibaba cloud's real-time computing version of Flink passed the stability test of big data products of the Institute of ICT
- Triangular rasterization
- 联发科技2023届提前批IC笔试(题目)
- Flutter monitors volume to realize waveform visualization of audio
- Literature reading_ Research on the usefulness identification of tourism online comments based on semantic fusion of multimodal data (Chinese Literature)
- Current market situation and development prospect forecast of the global fire boots industry in 2022
- Preparation for school and professional cognition
- Web security - CSRF (token)
- 《牛客刷verilog》Part II Verilog进阶挑战
- Symbol of array element product of leetcode simple problem
猜你喜欢

Concurrent operation memory interaction
![[research materials] 2022q1 game preferred casual game distribution circular - Download attached](/img/13/5a67c5d08131745759fdc70a71cf0f.jpg)
[research materials] 2022q1 game preferred casual game distribution circular - Download attached
![[PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)](/img/36/53886b9d3b98f744be2b6aa6b5d3eb.jpg)
[PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)

Number of uniform strings of leetcode simple problem

Leetcode simple question: the key with the longest key duration
![[XSS bypass - protection strategy] understand the protection strategy and better bypass](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[XSS bypass - protection strategy] understand the protection strategy and better bypass

Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis

JDBC database operation

Small sample target detection network with attention RPN and multi relationship detector (provide source code, data and download)

The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping
随机推荐
第十九届浙江省 I. Barbecue
关于开学的准备与专业认知
Market status and development prospect prediction of global fermentation acid industry in 2022
Wechat applet distance and map
Mobile terminal - uniapp development record (public request encapsulation)
【SQL注入】联合查询(最简单的注入方法)
Sdl2 + OpenGL glsl practice (Continued)
First + only! Alibaba cloud's real-time computing version of Flink passed the stability test of big data products of the Institute of ICT
I stepped on a foundation pit today
MPM model and ab pressure test
【PHP漏洞-弱类型】基础知识、php弱相等、报错绕过
[SQL injection point] location and judgment of the injection point
Thesis reading_ Tsinghua Ernie
The process of browser accessing the website
Retirement plan fails, 64 year old programmer starts work again
String matching: find a substring in a string
【SQL注入点】注入点出现位置、判断
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
Games101 Lesson 9 shading 3 Notes
What is UUID