当前位置:网站首页>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;
}
边栏推荐
- Compile and decompile GCC common instructions
- [luatos sensor] 1 light sensing bh1750
- 1118 birds in forest (25 points)
- 论文阅读_ICD编码_MSMN
- The 19th Zhejiang I. barbecue
- [develop wechat applet local storage with uni app]
- Learn to use the idea breakpoint debugging tool
- Market status and development prospect forecast of global button dropper industry in 2022
- Caijing 365 stock internal reference: what's the mystery behind the good father-in-law paying back 50 million?
- 【SQL注入】联合查询(最简单的注入方法)
猜你喜欢
RT thread flow notes I startup, schedule, thread
2022-02-12 daily clock in: problem fine brush
Thesis reading_ Chinese NLP_ ELECTRA
Thesis reading_ Chinese medical model_ eHealth
Triangular rasterization
联发科技2023届提前批IC笔试(题目)
Source insight garbled code solution
[luatos sensor] 1 light sensing bh1750
[USACO 2009 Dec S]Music Notes
论文阅读_中文医疗模型_ eHealth
随机推荐
Shell script -- condition judgment
1111 online map (30 points)
I stepped on a foundation pit today
《牛客刷verilog》Part II Verilog进阶挑战
论文阅读_ICD编码_MSMN
Notes | numpy-11 Array operation
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
Market status and development prospect prediction of global colorimetric cup cover industry in 2022
Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022
Preparation for school and professional cognition
Network security textual research recommendation
[XSS bypass - protection strategy] understand the protection strategy and better bypass
Review the configuration of vscode to develop golang
[research materials] annual report of China's pension market in 2021 - Download attached
Blog building tool recommendation (text book delivery)
Valentine's day limited withdrawal guide: for one in 200 million of you
【PHP漏洞-弱类型】基础知识、php弱相等、报错绕过
Do you know UVs in modeling?
Source insight garbled code solution
Career planning of counter attacking College Students