1775. 丢失的牛

摘要
Title: 1775. 丢失的牛
Tag: 模拟
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

1775. 丢失的牛

  • 题意

    见原题

  • 思路

    按照题意模拟即可

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    '''
    Author: NEFU AB-IN
    Date: 2022-04-07 17:54:31
    FilePath: \ACM\Acwing\1775.py
    LastEditTime: 2022-04-07 18:03:11
    '''
    x, y = map(int, input().split())
    xx, last = x, x
    cnt = 1
    flag = 0
    ans = 0
    while True:
    x = xx + (-1)**flag * (cnt)
    cnt *= 2
    flag ^= 1
    if min(x, last) <= y <= max(x, last): #如果经过了就退
    ans += abs(y - last)
    break
    ans += abs(x - last)
    last = x
    print(ans)
使用搜索:谷歌必应百度