目录
一、A-骰子魔术_牛客小白月赛98 (nowcoder.com)
二、B-最少剩几个?_牛客小白月赛98 (nowcoder.com)
三、C-两个函数_牛客小白月赛98 (nowcoder.com)
- 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')
参考他人代码(代码查看 (nowcoder.com))
print(input().split()[1] in input().split() and 'YES' or 'NO')
偶数加奇数为奇数,奇数乘奇数为奇数,优先选择加法,取决于奇数的个数。分为奇数多和偶数多两种情况。奇数多,则选择完加法后剩余 2 * cnt - n 个奇数,两两配对(乘法)则取余;当偶数多时,使用加法消耗完所有奇数偶数对即可,剩余 n - 2 * cnt。而两者一正一负(或0),取最大值即可。
- 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))
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))
- 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))
(未完待续)