4740. 跑圈

摘要
Title: 4740. 跑圈
Tag: 模拟
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

4740. 跑圈

  • 题意

    见原题

  • 思路

    分类讨论

    • 当方向与上次相同时:直接加上总路程,算出加的圈数
    • 当方向与上次不同时:先判断是否经过起点,若经过,则需变方向,那么总路程减去此次路程之后,就需要取绝对值(因为方向变了),然后按照上面的情况处理
  • 代码

    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
    60
    61
    '''
    Author: NEFU AB-IN
    Date: 2023-07-09 00:47:29
    FilePath: \Acwing\4740\4740.py
    LastEditTime: 2023-07-09 01:55:01
    '''
    # 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())
    AR = lambda x=0: [x] * N

    # —————————————————————Division line ——————————————————————

    t, = read()

    for _ in range(t):
    L, cnt, C = 0, 0, 0

    l, n = read()
    for i in range(n):
    d, c = input().split()
    d = int(d)
    if i == 0:
    C = c
    if c == C:
    L += d
    cnt += L // l
    else:
    if L >= 0 and L - d < 0:
    C = c
    L -= d
    if L < 0:
    L = -L
    cnt += L // l
    L %= l
    print(f"Case #{_ + 1}: {cnt}")
使用搜索:谷歌必应百度