A1095 Cars on Campus (30)

打印 上一主题 下一主题

主题 1035|帖子 1035|积分 3105

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Powered by:NEFU AB-IN
Link

  
A1095 Cars on Campus (30)

题意

Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you are supposed to tell, at any specific time point, the number of cars parking on campus, and at the end of the day find the cars that have parked for the longest time period.
思绪

给出每个人的车的收支情况,求一个时间内里有多少车,最长的累加停车时间是多少?
会有进出的噪音数据,取最晚进,最早出的时间,这就是一次的停车时间,然后利用差分,统计车的数目
此题也涉及到时间的转换,以及打印
代码

  1. # 3.8.19 import
  2. import random
  3. from collections import Counter, defaultdict, deque
  4. from datetime import datetime, timedelta
  5. from functools import lru_cache, reduce
  6. from heapq import heapify, heappop, heappush, nlargest, nsmallest
  7. from itertools import combinations, compress, permutations, starmap, tee
  8. from math import ceil, comb, fabs, floor, gcd, hypot, log, perm, sqrt
  9. from string import ascii_lowercase, ascii_uppercase
  10. from sys import exit, setrecursionlimit, stdin
  11. from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union
  12. # Constants
  13. TYPE = TypeVar('TYPE')
  14. N = int(2e5 + 10)
  15. M = int(20)
  16. INF = int(1e12)
  17. OFFSET = int(100)
  18. MOD = int(1e9 + 7)
  19. # Set recursion limit
  20. setrecursionlimit(int(2e9))
  21. class Arr:
  22.     array = staticmethod(lambda x=0, size=N: [x() if callable(x) else x for _ in range(size)])
  23.     array2d = staticmethod(lambda x=0, rows=N, cols=M: [Arr.array(x, cols) for _ in range(rows)])
  24.     graph = staticmethod(lambda size=N: [[] for _ in range(size)])
  25. class Math:
  26.     max = staticmethod(lambda a, b: a if a > b else b)
  27.     min = staticmethod(lambda a, b: a if a < b else b)
  28. class IO:
  29.     input = staticmethod(lambda: stdin.readline().strip())
  30.     read = staticmethod(lambda: map(int, IO.input().split()))
  31.     read_list = staticmethod(lambda: list(IO.read()))
  32.     read_mixed = staticmethod(lambda *types: [t(v) for t, v in zip(types, IO.input().split())])
  33. class Std:
  34.     pass
  35. # ————————————————————— Division line ——————————————————————
  36. def convert_time(time: str) -> int:
  37.     h, m, s = map(int, time.split(":"))
  38.     return h * 3600 + m * 60 + s
  39. def convert_index(x: int) -> str:
  40.     return f"{x // 3600:02}:{x % 3600 // 60:02}:{x % 60:02}"
  41. n, k = IO.read()
  42. diff_ = Arr.array(0, convert_time("24:00:01"))
  43. map_ = defaultdict(lambda: {
  44.     "in": [],
  45.     "out": []
  46. })
  47. for _ in range(n):
  48.     string, time, status = IO.read_mixed(str, str, str)
  49.     map_[string][status].append(time)
  50. max_ = Counter()
  51. max_val = 0
  52. for user, dict_ in map_.items():
  53.     in_ = dict_["in"]
  54.     out_ = dict_["out"]
  55.     res = []
  56.     res.extend([(convert_time(item), "in") for item in in_])
  57.     res.extend([(convert_time(item), "out") for item in out_])
  58.     res.sort(key=lambda x: x[0])
  59.     pre_in, pre_out = -1, -1
  60.     for index, st in res:
  61.         if st == "in":
  62.             pre_in = index
  63.         if st == "out":
  64.             pre_out = index
  65.         if pre_in != -1 and pre_out != -1 and st == "out" and index > pre_in:
  66.             diff_[pre_in] += 1
  67.             diff_[index] -= 1
  68.             val = index - pre_in
  69.             max_[user] += val
  70.             max_val = Math.max(max_val, max_[user])
  71.             pre_in, pre_out = -1, -1
  72. for i in range(1, len(diff_)):
  73.     diff_[i] += diff_[i - 1]
  74. for _ in range(k):
  75.     time = IO.input()
  76.     print(diff_[convert_time(time)])
  77. users_ = [user for user in max_.keys() if max_[user] == max_val]
  78. users_.sort()
  79. print(" ".join(users_), convert_index(max_val))
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

三尺非寒

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表