当前位置:网站首页>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;
}
边栏推荐
- [PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)
- [BMZCTF-pwn] 20-secret_ file
- Realize file download through the tag of < a > and customize the file name
- Shell script Basics - basic grammar knowledge
- Objects. Requirenonnull method description
- Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
- The programmer resigned and was sentenced to 10 months for deleting the code. JD came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
- Interface frequency limit access
- [SQL injection point] location and judgment of the injection point
- LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)
猜你喜欢
Leetcode simple question: check whether the array is sorted and rotated
Number of uniform strings of leetcode simple problem
Preparation for school and professional cognition
Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
【XSS绕过-防护策略】理解防护策略,更好的绕过
Symbol of array element product of leetcode simple problem
[tools run SQL blind note]
Handler understands the record
Truncated sentences of leetcode simple questions
Thesis reading_ Chinese NLP_ ELECTRA
随机推荐
Notes | numpy-10 Iterative array
Distinguish between releases and snapshots in nexus private library
带有注意力RPN和多关系检测器的小样本目标检测网络(提供源码和数据及下载)...
并发操作-内存交互操作
雇佣收银员(差分约束)
论文阅读_ICD编码_MSMN
Silent authorization login and registration of wechat applet
STM32 reverse entry
[research materials] annual report of China's pension market in 2021 - Download attached
Literature reading_ Research on the usefulness identification of tourism online comments based on semantic fusion of multimodal data (Chinese Literature)
[research materials] 2022q1 game preferred casual game distribution circular - Download attached
Actual combat 8051 drives 8-bit nixie tube
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
【XSS绕过-防护策略】理解防护策略,更好的绕过
Thesis reading_ Chinese medical model_ eHealth
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
Shell script -- condition judgment
Market status and development prospects of the global autonomous marine glider industry in 2022
[luatos sensor] 1 light sensing bh1750
[develop wechat applet local storage with uni app]