当前位置:网站首页>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;
}边栏推荐
- 1115 counting nodes in a BST (30 points)
- [XSS bypass - protection strategy] understand the protection strategy and better bypass
- Triangular rasterization
- Learning record of arouter principle
- [set theory] relational representation (relational matrix | examples of relational matrix | properties of relational matrix | operations of relational matrix | relational graph | examples of relationa
- "Niuke brush Verilog" part II Verilog advanced challenge
- MC Layer Target
- [research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached
- Thesis reading_ Tsinghua Ernie
- Keepalived热备与HAProxy
猜你喜欢
![[tools run SQL blind note]](/img/c3/86db4568b221d2423914990a88eec2.png)
[tools run SQL blind note]

Keepalived热备与HAProxy

Uipath practice (08) - selector

Interface frequency limit access
![[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree](/img/0f/bc8c44aee7a2c9dccac050b1060017.jpg)
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree

Analysis of proxy usage of ES6 new feature
![[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

Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution

I stepped on a foundation pit today

Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
随机推荐
[luatos sensor] 1 light sensing bh1750
I stepped on a foundation pit today
[SQL injection point] location and judgment of the injection point
The process of browser accessing the website
Silent authorization login and registration of wechat applet
Market status and development prospect prediction of the global fire alarm sensor industry in 2022
Objects. Requirenonnull method description
Unity tool Luban learning notes 1
逆袭大学生的职业规划
[XSS bypass - protection strategy] understand the protection strategy and better bypass
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
联发科技2023届提前批IC笔试(题目)
M1 Pro install redis
1111 online map (30 points)
MPM model and ab pressure test
Retirement plan fails, 64 year old programmer starts work again
Market status and development prospects of the global IOT active infrared sensor industry in 2022
Market status and development prospect prediction of the near infrared sensor industry of the global Internet of things in 2022
112 stucked keyboard (20 points)
【SQL注入】联合查询(最简单的注入方法)