Codeforces Round 925 (Div. 3)(A~E)python

A. Recovering a Small String

Problem - A - Codeforces

暴力,字符串

每个位置至少分配1,剩余的优先向后分配

t = int(input())
for _ in range(t):
    n = int(input())
    res = [1, 1, 1]
    n -= 3
    i = 2
    while n > 0 and i >= 0:
        now = min(n, 25)
        res[i] += now
        n -= now
        i -= 1
    for i in res:
        print(chr(i-1+ord("a")), end="")
    print()

B. Make Equal

Problem - B - Codeforces

贪心

遍历一遍,每个位置留平均值的水量,不够则不可能

def check():
    avg = sum(a)//n
    now = 0
    for ai in a:
        if ai + now < avg:
            return False
        now += ai-avg
    return True


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    if check():
        print("YES")
    else:
        print("NO")

C. Make Equal Again

Problem - C - Codeforces

贪心

最后剩的一定是开头或者是末尾的一种,将其他的变成开头或者结尾取最大即可

开头结尾有可能是相同数字,这时只需改变中间的元素

t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    now, i = a[0], 0
    while i < n and a[i] == now:
        i += 1
    now, j = a[-1], n-1
    while j >= 0 and a[j] == now:
        j -= 1
    if a[0] == a[-1]:
        res = max(0, n-i-(n-j-1))
    else:
        res = n - max(i, n-j-1)
    print(res)

D. Divisible Pairs

Problem - D - Codeforces

数学,模拟,数论

可以发现,一对符合条件时,ai%x + aj%x = x或0,ai%y - aj%y = 0

那么只要找对x取模和为x或0,对y取模值相等的ai,aj即可(当时脑抽了没想到。。。)

将数组分别对x和y取模,存储在mx和my内,因为ai%y和aj%y相等,将my存一下元素的索引然后排序,那么%y相等的就会在相邻的位置,

分别对每种对y模数看其中有多少对%x和为x或为0就能包含所有情况,

用计数器存一下%x各数值数目,符合条件取一次答案

from collections import Counter
t = int(input())
for _ in range(t):
    n, x, y = map(int, input().split())
    a = list(map(int, input().split()))
    mx = [a[i] % x for i in range(n)]
    my = [(a[i] % y, i) for i in range(n)]
    my.sort()
    res = 0
    i = 0
    while i < n:
        now = my[i][0]
        c = Counter()
        c[mx[my[i][1]]] += 1
        while i+1 < n and my[i+1][0] == now:
            i += 1
            mxi = mx[my[i][1]]
            if mxi == 0:
                res += c[0]
            res += c[x-mxi]
            c[mxi] += 1
        i += 1
    print(res)

E. Anna and the Valentine's Day Gift

Problem - E - Codeforces

博弈论,贪心

简单的博弈论,anna可以将数字逆转过来,Sasha可以使两数字任意顺序拼接,最后判断最后一个数字是否小于10^m

anna会尽可能使最后的数值更小,Sasha相反,最后只需看剩下数字的长度即可,为了让数字长度更小,anna会优先让当前末尾0最多的数字逆转,而Sasha会优先让末尾0最多的拼在另一数字前面,来保护0,0出现在中间后不会再影响数字长度

将数字按末尾0降序排序,每当到偶数索引数字会减少末尾零个位数,最后判断长度是否大于m

def z_num(s):
    n = len(s)
    i = 0
    while s[-i-1] == "0":
        i += 1
    return i


t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    a = list(input().split())
    a = [[z_num(ai), ai] for ai in a]
    a.sort(reverse=True)
    res = 0
    for i in range(n):
        res += len(a[i][1])
        if i % 2 == 0:
            res -= a[i][0]
    if res > m:
        print("Sasha")
    else:
        print("Anna")

  • 25
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Codeforces Round 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列题目,其中包括题目E. Kolya and Movie Theatre。 根据题目描述,E. Kolya and Movie Theatre问题要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和题目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Codeforces Round 894 (Div. 3)A~E题解](https://blog.csdn.net/gyeolhada/article/details/132491891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值