模拟专题
2022/7/2 23:20:07
本文主要是介绍模拟专题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1095 Cars on Campus
Link
配对要求是,如果一个车多次进入未出,取最后一个值;如果一个车多次out未进入,取第一个值。
注意:一个车可能出入校园好多次,停车的时间应该取之和
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <string> #include <string.h> #include <vector> #include <unordered_map> using namespace std; const int N=10010; const int MAXT=24*3600; int n,k,hh,mm,ss,flag,num,maxv; string p,st; unordered_map<string,int>plates; unordered_map<int,string>revplates; vector<string>ansstr; struct Car{ int tot,flag; bool operator<(Car x)const{ return tot<x.tot; } }; vector<Car>cars[N]; int timeList[MAXT]; int main() { scanf("%d%d",&n,&k); for(int i=1;i<=n;++i){ cin>>p; if(!plates.count(p)) plates[p]=++num; revplates[plates[p]]=p; scanf("%d:%d:%d",&hh,&mm,&ss); int tot=hh*3600+mm*60+ss; cin>>st; if(st=="in") flag=1; else flag=0; cars[plates[p]].push_back({tot,flag}); } for(int i=1;i<=num;++i){ sort(cars[i].begin(),cars[i].end()); int j=0,span=0; while(j<cars[i].size()){ while(!cars[i][j].flag&&j<cars[i].size()) j++; if(j>=cars[i].size()) break; while(cars[i][j].flag&&j<cars[i].size()) j++; if(j>=cars[i].size()) break; //cars[i][j-1].flag==1,cars[i][j].flag==0 timeList[cars[i][j-1].tot]++; timeList[cars[i][j].tot]--; span+=cars[i][j].tot-cars[i][j-1].tot; j++; } if(span>maxv){ ansstr.clear(); ansstr.push_back(revplates[i]); maxv=span; }else if(span==maxv){ ansstr.push_back(revplates[i]); } } for(int i=1;i<MAXT;++i) timeList[i]+=timeList[i-1]; sort(ansstr.begin(),ansstr.end()); while(k--){ scanf("%d:%d:%d",&hh,&mm,&ss); int tot=hh*3600+mm*60+ss; printf("%d\n",timeList[tot]); } for(int i=0;i<ansstr.size();++i) cout<<ansstr[i]<<" "; printf("%02d:%02d:%02d\n",maxv/3600,(maxv/60)%60,maxv%60); return 0; }
这篇关于模拟专题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?