2188. 钟表

摘要
Title: 2188. 钟表
Tag: 时分秒、时间、钟表
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

2188. 钟表

  • 题意

    在线钟表:https://www.geogebra.org/m/auuvawgj

    求分针和时针的夹角,是,分针和秒针的夹角两倍的时间是多少,要求小时小于等于6

  • 思路

    因为每当秒数增加,三个针的位置都会发生移动,所以,可以采取枚举秒数的方式

    • 先算出每一秒,三个针各移动多少度
    • 之后根据题目要求相减,并看是否有二倍关系
    • 另外,就是总秒数求时、分、秒
      • 时 i // 3600
      • 分 i % 3600 // 60
      • 秒 i % 60
  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    '''
    Author: NEFU AB-IN
    Date: 2023-05-25 16:55:03
    FilePath: \LanQiao\2188\2188.py
    LastEditTime: 2023-05-25 17:49:30
    '''
    # import
    from sys import setrecursionlimit, stdin, stdout, exit
    from collections import Counter, deque
    from heapq import heapify, heappop, heappush, nlargest, nsmallest
    from bisect import bisect_left, bisect_right
    from datetime import datetime, timedelta
    from string import ascii_lowercase, ascii_uppercase
    from math import log, gcd, sqrt, fabs, ceil, floor


    class sa:
    def __init__(self, x, y):
    self.x = x
    self.y = y

    def __lt__(self, a):
    return self.x < a.x


    # Final
    N = int(1e5 + 10)
    M = 20
    INF = int(2e9)

    # Define
    setrecursionlimit(INF)
    input = lambda: stdin.readline().rstrip("\r\n") # Remove when Mutiple data
    read = lambda: map(int, input().split())
    LTN = lambda x: ord(x.upper()) - 65 # A -> 0
    NTL = lambda x: ascii_uppercase[x] # 0 -> A

    # —————————————————————Division line ——————————————————————
    cnt = 12 * 60 * 60 # 360度走多少秒

    s_j = 360 / cnt
    f_j = 360 * 24 / cnt
    m_j = 360 * 24 * 60 / cnt

    for i in range(cnt * 2): # 由于24小时,时钟要跑两遍,所以乘2
    s, f, m = s_j * i % 360, f_j * i % 360, m_j * i % 360
    sf = fabs(s - f)
    fm = fabs(f - m)

    if sf > 180:
    sf -= 180
    if fm > 180:
    fm -= 180

    if fabs(sf - 2 * fm) < 1e-8:
    s, f, m = i // 3600, i % 3600 // 60, i % 60
    if s <= 6 and not (s == 0 and f == 0 and m == 0):
    print(s, f, m)

使用搜索:谷歌必应百度