• A. Everyone Loves to Sleep


    time limit per test

    2 seconds

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Vlad, like everyone else, loves to sleep very much.

    Every day Vlad has to do nn things, each at a certain time. For each of these things, he has an alarm clock set, the ii-th of them is triggered on hihi hours mimi minutes every day (0≤hi<24,0≤mi<600≤hi<24,0≤mi<60). Vlad uses the 2424-hour time format, so after h=12,m=59h=12,m=59 comes h=13,m=0h=13,m=0 and after h=23,m=59h=23,m=59 comes h=0,m=0h=0,m=0.

    This time Vlad went to bed at HH hours MM minutes (0≤H<24,0≤M<600≤H<24,0≤M<60) and asks you to answer: how much he will be able to sleep until the next alarm clock.

    If any alarm clock rings at the time when he went to bed, then he will sleep for a period of time of length 00.

    Input

    The first line of input data contains an integer tt (1≤t≤1001≤t≤100) — the number of test cases in the test.

    The first line of the case contains three integers nn, HH and MM (1≤n≤10,0≤H<24,0≤M<601≤n≤10,0≤H<24,0≤M<60) — the number of alarms and the time Vlad went to bed.

    The following nn lines contain two numbers each hihi and mimi (0≤hi<24,0≤mi<600≤hi<24,0≤mi<60) — the time of the ii alarm. It is acceptable that two or more alarms will trigger at the same time.

    Numbers describing time do not contain leading zeros.

    Output

    Output tt lines, each containing the answer to the corresponding test case. As an answer, output two numbers  — the number of hours and minutes that Vlad will sleep, respectively. If any alarm clock rings at the time when he went to bed, the answer will be 0 0.

    Example

    input

    Copy

     
    

    3

    1 6 13

    8 0

    3 6 0

    12 30

    14 45

    6 0

    2 23 35

    20 15

    10 30

    output

    Copy

    1 47
    0 0
    10 55

    解题说明:此题是一道模拟题,可以先换算成按分钟来统计时间,一天总共1440分钟,然后计算出每一个闹钟在一天中的分钟。同时记录睡觉所在的分钟,进行比较,得到一个最小的差值即可。

    1. #include
    2. int main()
    3. {
    4. int t;
    5. scanf("%d", &t);
    6. while (t--)
    7. {
    8. int n, H, M;
    9. scanf("%d%d%d", &n, &H, &M);
    10. int i, h, m, T, td = 0, k = 1440;
    11. T = H * 60 + M;
    12. for (i = 0; i < n; i++)
    13. {
    14. scanf("%d%d", &h, &m);
    15. td = h * 60 + m;
    16. if (td >= T)
    17. {
    18. td -= T;
    19. }
    20. else
    21. {
    22. td += 1440 - T;
    23. }
    24. if (td < k)
    25. {
    26. k = td;
    27. }
    28. }
    29. printf("%d %d\n", k / 60, k % 60);
    30. }
    31. return 0;
    32. }

  • 相关阅读:
    11、voc转yolo数据集、训练集验证集划分、修改xml文件
    如何使用内网穿透实现远程公网访问windows node.js的服务端
    java 多线程笔记二 线程安全问题
    java ssm基于springboot的校园店铺系统
    Reggie外卖项目 —— 小程序开发之短信发送
    怎样用一台手机做自媒体?
    Android重置APN时提示弹窗不消失问题
    养老院管理系统设计与实现-计算机毕业设计源码+LW文档
    计算机组成原理 学习笔记(持续学习中)
    matlab-day04
  • 原文地址:https://blog.csdn.net/jj12345jj198999/article/details/127973903