AtCoder Beginner Contest 433 (A~D)

2025.11.23 星期日 晴

工作之后感觉变成了一个fw了,生活重心逐步向工作靠近,有一种被体制化的感觉。我现在的工作对比大多数人来说算是非常好了,但我依然觉得 工作是一件束缚人自由的工作。什么时候我才可以自由地工作,随心所欲地生活呢?

ABC 433

A

# -*- coding: utf-8 -*-
# !/usr/bin/env python

"""
@Author : Liang2003
@Time   : 2025/11/23 10:48

https://atcoder.jp/contests/abc433/tasks/abc433_a

题意: 是否存在一个W 使得 (X+W) = Z * (Y+W)

X - Z*Y = (Z-1) * W

"""


def main():
    X,Y,Z = map(int,input().split())

    res1 = X - Z*Y
    res2 = Z - 1
    # print(res1)
    # print(res2)

    if X == Y*Z:
        print("Yes")
        return


    if res1 < 0 :
        print("No")
        return
    else:
        if res1 % res2 == 0:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()

B

# -*- coding: utf-8 -*-
# !/usr/bin/env python

"""
@Author : Liang2003
@Time   : 2025/11/23 11:03

https://atcoder.jp/contests/abc433/tasks/abc433_b

题意:给出一个队列,对于位置i,找到左边 比位置i大的第一个数的位置

思路:单调栈,对于位置i,如果栈顶元素 <= 该位置元素就pop,一直找到 大于该位置的元素

"""


def main():
   n = map(int,input())
   num_list = list(map(int,input().split()))

   stack = []
   top = 0
   for (idx,num) in enumerate(num_list):
       while top > 0 and num_list[stack[top-1]] <= num:
               stack.pop()
               top -= 1
       if top > 0 :
           print(stack[top-1]+1)
       else:
           print(-1)
       stack.append(idx)
       top += 1

if __name__ == "__main__":
    main()

C

# -*- coding: utf-8 -*-
# !/usr/bin/env python3

"""
@Author : Liang2003
@Time   : 2025/11/23 11:21

题目:统计字符串中满足条件的子串数量
条件:子串长度为偶数,前一半字符相同,后一半字符相同,且后一半字符 = 前一半字符 + 1
"""


def main():
    # 读取输入
    s = input().strip()
    if not s:  # 处理空字符串
        print(0)
        return

    # 在字符串末尾添加哨兵字符,便于处理边界
    s = s + " "

    # 将连续相同字符分组,存储为 (字符, 连续出现次数)
    char_groups = []
    current_char = s[0]
    current_count = 1

    # 从第二个字符开始遍历(跳过索引0)
    for char in s[1:]:
        if char == current_char:
            current_count += 1
        else:
            char_groups.append((int(current_char), current_count))
            current_char = char
            current_count = 1

    # 统计满足条件的子串数量
    result = 0

    # 遍历相邻的字符组
    for i in range(len(char_groups) - 1):
        current_digit, current_count = char_groups[i]
        next_digit, next_count = char_groups[i + 1]

        # 检查是否满足条件:后一个字符 = 前一个字符 + 1
        if next_digit == current_digit + 1:
            # 取两个连续段的最小长度作为可形成的子串数量
            result += min(current_count, next_count)

    print(result)


if __name__ == "__main__":
    main()

D

# -*- coding: utf-8 -*-
# !/usr/bin/env python

"""
@Author : Liang2003
@Time   : 2025/11/23 11:40

https://atcoder.jp/contests/abc433/tasks/abc433_d

题意: 问一个数组中有多少对数(i,j),使得A[i]和A[j] 拼接起来是M的倍数

思路:
A数组最大的数 是1e9,有十位,那么处理出每个数 A[i]乘上10的 0到10次方 模M的余数。
对于A[i],假设它的长度为d,模M后为X,那么该数的贡献为 数组中的数乘上 10的d次方 后模M 为(M-X) 的数量
"""
from typing import List, Dict


def handle_mod(num:int,M:int,B:List[Dict[int,int]]):
    """
    处理每个数 乘从10的1次方到10次方 模M的余数 ,统计各个数位,各余数的值
    :param num:
    :param M:
    :param B:
    :return:
    """
    x = num % M
    y = 10 % M
    for i in range(1, 11):
        z = x * y % M
        B[i][z] = B[i].get(z, 0) + 1
        # print("B[{}][{}]:{}".format(i,z,B[i][z]))
        y = y * 10 % M



def main():
    n,M = map(int,input().split())
    nums = list(map(int,input().split()))
    B = []
    for i in range(0,11):
        B.append({})

    res = 0
    for num in nums:
       handle_mod(num,M,B)

    for num in nums:
        d = len(str(num))
        m = num % M
        # print(d,m, B[d].get((M - m)%M,0))
        res = res + B[d].get((M-m)%M, 0)

    print(res)


if __name__ == "__main__":
    main()

posted @ 2025-11-23 12:28  Liang2003  阅读(0)  评论(0)    收藏  举报