当前位置:网站首页>竞赛题 2022-6-26
竞赛题 2022-6-26
2022-07-06 01:28:00 【Yake1965】
6104. 统计星号
class Solution:
def countAsterisks(self, s: str) -> int:
return "".join(s.split("|")[::2]).count("*")
flag, ans = 1, 0
for c in s:
if c == "*": ans += flag
elif c == "|": flag = 1 - flag
return ans
a = s.split('|')
return sum(a[i].count("*") for i in range(0, len(a), 2))
6107. 不同骰子序列的数目
第 i 次扔骰子的结果受第 (i - 1) 次和第 (i - 2) 次结果的限制。因此我们维护 f(i, a, b) 表示第 i 次扔骰子的结果为 a,第 (i - 1)次的结果为 b 的方案数。
为了转移,我们枚举第 (i - 2) 次的结果 c。根据题意,a,b,c 需要满足以下要求:
三个数互不相等;
gcd(a, b) = gcd(b, c) = 1。
只要同时满足这两个条件,f(i - 1, b, c) 就能转移给 f(i, a, b)。
第 300 场周赛
2325. 解密消息
class Solution {
public String decodeMessage(String key, String message) {
Map<Character, Character> map = new HashMap<>();
int i = 97;
for(char c : key.toCharArray()){
if(c == ' ') continue;
if(!map.containsKey(c)) map.put(c, (char)(i++));
}
map.put(' ', ' ');
StringBuilder sb = new StringBuilder();
for(char c : message.toCharArray()){
sb.append(map.get(c));
}
return sb.toString();
}
}
2326. 螺旋矩阵 IV
class Solution {
public int[][] spiralMatrix(int m, int n, ListNode head) {
int[][] ans = new int[m][n];
for(int[] row : ans) Arrays.fill(row, -1);
int up = 0, down = m - 1, left = 0, right = n - 1;
while(head != null){
for(int j = left; head != null && j <= right; j++){
ans[up][j] = head.val;
head = head.next;
}
up++;
for(int i = up; head != null && i <= down; i++){
ans[i][right] = head.val;
head = head.next;
}
right--;
for(int j = right; head != null && j >= left; j--){
ans[down][j] = head.val;
head = head.next;
}
down--;
for(int i = down; head != null && i >= up; i--){
ans[i][left] = head.val;
head = head.next;
}
left++;
}
return ans;
}
}
2327. 知道秘密的人数
f[i] 表示第 i 天新知道秘密的人数。
class Solution {
public int peopleAwareOfSecret(int n, int delay, int forget) {
int mod = 1000000007;
long s = 0;
long[] f = new long[n + 1];
f[1] = 1;
for(int i = 2; i <= n; i++){
if(i > delay) s += f[i-delay];
if(i > forget) s -= f[i-forget];
f[i] = s % mod;
}
long sum = 0;
for(int i = 0; i < forget; i++){
sum = (sum + f[n - i]) % mod;
}
return (int)sum;
}
}
2328. 网格图中递增路径的数目
边栏推荐
- Cookie concept, basic use, principle, details and Chinese transmission
- 干货!通过软硬件协同设计加速稀疏神经网络
- ctf. Show PHP feature (89~110)
- A picture to understand! Why did the school teach you coding but still not
- Force buckle 1020 Number of enclaves
- ClickOnce 不支持请求执行级别“requireAdministrator”
- ORA-00030
- 普通人下场全球贸易,新一轮结构性机会浮出水面
- leetcode刷题_平方数之和
- Paging of a scratch (page turning processing)
猜你喜欢
[pat (basic level) practice] - [simple mathematics] 1062 simplest fraction
Maya hollowed out modeling
Threedposetracker project resolution
Dede collection plug-in free collection release push plug-in
[technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry
A Cooperative Approach to Particle Swarm Optimization
File upload vulnerability test based on DVWA
WordPress collection plug-in automatically collects fake original free plug-ins
电气数据|IEEE118(含风能太阳能)
leetcode刷题_验证回文字符串 Ⅱ
随机推荐
Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
[solved] how to generate a beautiful static document description page
Blue Bridge Cup embedded stm32g431 - the real topic and code of the eighth provincial competition
基於DVWA的文件上傳漏洞測試
How to get all sequences in Oracle database- How can I get all sequences in an Oracle database?
【Flask】静态文件与模板渲染
Leetcode study - day 35
Paging of a scratch (page turning processing)
c#网页打开winform exe
[detailed] several ways to quickly realize object mapping
网易智企逆势进场,游戏工业化有了新可能
【Flask】官方教程(Tutorial)-part2:蓝图-视图、模板、静态文件
Electrical data | IEEE118 (including wind and solar energy)
DOM introduction
【全網最全】 |MySQL EXPLAIN 完全解讀
How does the crystal oscillator vibrate?
[the most complete in the whole network] |mysql explain full interpretation
servlet(1)
Code Review关注点
【全网最全】 |MySQL EXPLAIN 完全解读