首页 > 其他分享 >PAT (Advanced Level) - 1095 Cars on Campus

PAT (Advanced Level) - 1095 Cars on Campus

时间:2024-05-25 10:26:28浏览次数:20  
标签:status 1095 PAT Level int res ss car events

在这里插入图片描述

模拟,哈希,字符串,STL

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;

struct Event {
	int time, status;

	bool operator<(const Event &t) const {
		return time < t.time;
	}
};

int n, m;
unordered_map<string, vector<Event> > cars;

int get(vector<Event> &v) {
	int res = 0;
	for (int i = 0; i < v.size(); i += 2)
		res += v[i + 1].time - v[i].time;
	return res;
}

int main() {
	scanf("%d%d", &n, &m);

	char id[10], status[10];
	for (int i = 0; i < n; ++i) {
		int hh, mm, ss;
		scanf("%s %d:%d:%d %s", id, &hh, &mm, &ss, status);

		int t = hh * 3600 + mm * 60 + ss;
		int s = 0;						// in  0
		if (status[0] == 'o') s = 1;	// out 1

		cars[id].push_back({t, s});
	}

	vector<Event> events;

	for (auto &car : cars) {
		auto &v = car.second;
		sort(v.begin(), v.end());
		vector<Event> new_v;

		for (int i = 0; i < v.size(); ++i)
			if (v[i].status == 0) {
				if (i + 1 < v.size() && v[i + 1].status == 1) {
					new_v.push_back(v[i]);
					new_v.push_back(v[i + 1]);
					++i;
				}
			}

		v = new_v;
		for (auto i : v) events.push_back(i);
	}

	sort(events.begin(), events.end());

	int i = 0, sum = 0;
	while (m--) {
		int hh, mm, ss;
		scanf("%d:%d:%d", &hh, &mm, &ss);
		int t = hh * 3600 + mm * 60 + ss;

		for (; i < events.size() && events[i].time <= t; ++i) {
			if (events[i].status == 0) sum++;		// in
			else sum--;							    // out
		}

		printf("%d\n", sum);
	}

	int maxt = 0;
	for (auto &car : cars) {
		maxt = max(maxt, get(car.second));
	}

	vector<string> res;
	for (auto &car : cars)
		if (get(car.second) == maxt)
			res.push_back(car.first);

	sort(res.begin(), res.end());

	for (auto it : res) cout << it << " ";
	printf("%02d:%02d:%02d\n", maxt / 3600, maxt % 3600 / 60, maxt % 60);

	return 0;
}

标签:status,1095,PAT,Level,int,res,ss,car,events
From: https://blog.csdn.net/Akira37/article/details/139140246

相关文章

  • 【论文速读】LLM-Augmented Retrieval:EnhancingRetrievalModels Through LanguageMod
    论文链接:https://arxiv.org/html/2404.05825v1文章标题:LLM-AugmentedRetrieval:EnhancingRetrievalModelsThroughLanguageModelsandDoc-LevelEmbedding这篇文章提出了一种与检索模型无关的框架框架,通过大型语言模型来丰富文档的嵌入,显著提高了现有检索模型的性......
  • (PAT乙级刷题)
    题目:题解:#include<iostream>#include<string>#include<cmath>usingnamespacestd;intmain(){stringx,y;//转化前,转化后charkey;cin>>key;getchar();//读取回车getline(cin,x);//判断要压缩还是解压if(key=......
  • yolov8 分割任务切块推理库 patched_yolo_infer
    这个Python库简化了类似SAHI的推理,例如分割任务,从而能够检测图像中的小对象。它同时满足对象检测和实例分割任务,支持广泛的Ultralytics模型。该库还为所有模型的推理结果可视化提供了流畅的定制,包括标准方法(直接网络运行)和独特的基于补丁的变体。模型支持:该库提供对多个超解析深......
  • The following instances are in the device manifest but not specified in framewor
    android 编译hal报错:ERROR:filesareincompatible:Thefollowinginstancesareinthedevicemanifestbutnotspecifiedinframeworkcompatibilitymatrix:android.hardware.hongxi.IHongxi/default(@1)Suggestedfix:1.UpdatedeprecatedHALstothelatestve......
  • url-pattern 一个不错的url 模式解析包
    url-pattern是一个很不错的url模式解析包,可以方便的进行url解析(类似我们web框架的路由处理)可以用来实现方便的url解析处理因为很多时候我们需要获取url的部分信息,基于正则是可以的,但是url-pattern提供了比较灵活的模式匹配是一个很不错的工具包参考使用示例......
  • [Paper Reading] BEVFormer: Learning Bird’s-Eye-View Representation from Multi-C
    BEVFormer:LearningBird’s-Eye-ViewRepresentationfromMulti-CameraImagesviaSpatiotemporalTransformerslink时间:22.07机构:NanjingUniversity&&ShanghaiAILaboratoryTL;DR利用Transformer的Attention机制融合时空特征信息,在nuScenes测试集上达到SOTA精度,同时......
  • 论文阅读:Reasoning with Latent Structure Refinement for Document-Level Relation E
    NanG,GuoZ,SekulićI,etal.Reasoningwithlatentstructurerefinementfordocument-levelrelationextraction[J].arXivpreprintarXiv:2005.06312,2020.代码和预训练模型的github链接LSR模型本文提出了用于文档级关系提取任务的LatentStructureRefinement(L......
  • Python内置库:pathlib(文件路径操作)
    官方文档:pathlib—Object-orientedfilesystempaths一、基础使用遍历子目录使用通配符遍历文件拼接路径获取标准化后的绝对路径查询路径常规属性打开文件frompathlibimportPathprint('1.1查询指定目录的子目录')p=Path('D:/Envs')print([sub_pforsub_p......
  • Xpath使用教程
    一、安装Xpath解析库-scrapy中的selectorwin+r打开cmd,输入pipinstallwheel,先安装wheel库了才能安装.whl文件。安装lxml库到https://pypi.org/project/lxml/#files下载对应python版本的lxml库 切到lxml下载位置,安装lxml安装Twisted库到https://pypi.org/project/Twis......
  • 寻路算法 Pathfinding
    目录我该使用哪种算法?BreadthFirstSearch(BFS)Dijkstra’sAlgorithmGreedyBestFirstSearchA*Algorithm学UGUI的一般使用方法,然后在画grid,除了画热力图之外,还开始了解用于处理寻路的算法A*寻路算法是图搜索算法,所以我打算不用Unity自带的寻路组件,自己简单的实现一......