2024.7.13刷题记录-牛客小白月赛98(未完)

目录

一、A-骰子魔术_牛客小白月赛98 (nowcoder.com)

1.模拟

2.简洁写法

二、B-最少剩几个?_牛客小白月赛98 (nowcoder.com)

贪心-数学

三、C-两个函数_牛客小白月赛98 (nowcoder.com)

1.模拟

2.逆元


一、A-骰子魔术_牛客小白月赛98 (nowcoder.com)

1.模拟

python 复制代码
R = lambda: map(int, input().split())
n, tar = R()
nums = list(R())
flag = 0
for x in nums:
    if x == tar:
        flag = 1
print('YES' if flag else 'NO')

2.简洁写法

参考他人代码(代码查看 (nowcoder.com))

python 复制代码
print(input().split()[1] in input().split() and 'YES' or 'NO')

二、B-最少剩几个?_牛客小白月赛98 (nowcoder.com)

贪心-数学

偶数加奇数为奇数,奇数乘奇数为奇数,优先选择加法,取决于奇数的个数。分为奇数多和偶数多两种情况。奇数多,则选择完加法后剩余 2 * cnt - n 个奇数,两两配对(乘法)则取余;当偶数多时,使用加法消耗完所有奇数偶数对即可,剩余 n - 2 * cnt。而两者一正一负(或0),取最大值即可。

python 复制代码
n = int(input())
nums = list(map(int, input().split()))
odd_cnt = 0
for x in nums:
    if x & 1: odd_cnt += 1
print(max(n - 2 * odd_cnt, (2 * odd_cnt - n) % 2))

三、C-两个函数_牛客小白月赛98 (nowcoder.com)

1.模拟

python无精度影响

python 复制代码
mod = 998244353
def f(a, x):
    if x == 1:
        return a * x % mod
    else:
        return a * a * x * (x - 1) // 2 % mod
t = int(input())
for _ in range(t):
    a, x = map(int, input().split())
    print(f(a, x))

2.逆元

python 复制代码
mod = 998244353
def f(a, x):
    if x == 1:
        return a % mod * x % mod
    else:
        return a % mod * a % mod * x % mod * (x - 1) % mod * qmi(2, mod - 2) % mod
    
def qmi(n, k):
    ans = 1
    while k > 0:
        if k & 1:
            ans = ans * n % mod
        n = n * n % mod
        k >>= 1
    return ans

t = int(input())
for _ in range(t):
    a, x = map(int, input().split())
    print(f(a, x))

(未完待续)

相关推荐
timeDifference₇5 小时前
Python Vibe Coding实操实验报告
开发语言·jvm·python
geovindu6 小时前
python:DecisionTree
开发语言·后端·python·算法
怒放的生命19917 小时前
代码知识库 RAG 问答系统 —— 从 0 到 1 实现教程
python·状态模式·fastapi·全栈开发·ai agent应用开发
geovindu8 小时前
python: Decision Tree Regressor
开发语言·后端·python·算法·决策树
IT空门:门主8 小时前
LangChain4j 1.24.0 深度解读:新特性、版本对比与学习路线
java·学习
Shadow(⊙o⊙)9 小时前
一年间学习的总结与成长记录——记录自己的18岁
学习
fengkai45459 小时前
Python运维
运维·python·监控·psutil·ipy
Fancy.7619 小时前
:Python条件与循环语句学习总结
python
AllData公司负责人10 小时前
实战二:AllData大模型与AI数据底座-数据传输平台-DBSyncer,搭建 Http 接口同步至 Doris,API 业务数据自动拉取入数仓
大数据·数据库·数据仓库·人工智能·算法·http·doris