当前位置:网站首页>Competition question 2022-6-26
Competition question 2022-6-26
2022-07-06 01:40:00 【Yake1965】
6104. Statistical asterisk
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. The number of different die sequences
The first i The result of throwing dice for the first time is affected by (i - 1) Time and number (i - 2) Limit of secondary results . So we maintain f(i, a, b) It means the first one i The result of this dice throw is a, The first (i - 1) The result of this time is b Number of alternatives .
In order to transfer , Let's enumerate the third (i - 2) Results of c. According to the meaning ,a,b,c The following requirements need to be met :
The three numbers are not equal to each other ;
gcd(a, b) = gcd(b, c) = 1.
As long as these two conditions are met at the same time ,f(i - 1, b, c) Can be transferred to f(i, a, b).
The first 300 Weekly match
2325. Decrypt the message
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. Spiral matrix 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. Number of people who know the secret
f[i] It means the first one i Tianxin knows the number of Secrets .
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. The number of incremental paths in the grid graph
边栏推荐
- 什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
- [ssrf-01] principle and utilization examples of server-side Request Forgery vulnerability
- Cadre du Paddle: aperçu du paddlelnp [bibliothèque de développement pour le traitement du langage naturel des rames volantes]
- internship:项目代码所涉及陌生注解及其作用
- NumPy 数组索引 切片
- 2022年广西自治区中职组“网络空间安全”赛题及赛题解析(超详细)
- 【全網最全】 |MySQL EXPLAIN 完全解讀
- Open source | Ctrip ticket BDD UI testing framework flybirds
- 【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
- 【Flask】获取请求信息、重定向、错误处理
猜你喜欢
Leetcode skimming questions_ Invert vowels in a string
2022 PMP project management examination agile knowledge points (8)
Basic operations of database and table ----- set the fields of the table to be automatically added
C web page open WinForm exe
[understanding of opportunity-39]: Guiguzi - Chapter 5 flying clamp - warning 2: there are six types of praise. Be careful to enjoy praise as fish enjoy bait.
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
Threedposetracker project resolution
电气数据|IEEE118(含风能太阳能)
[detailed] several ways to quickly realize object mapping
3D model format summary
随机推荐
[detailed] several ways to quickly realize object mapping
Initialize MySQL database when docker container starts
c#网页打开winform exe
A Cooperative Approach to Particle Swarm Optimization
【Flask】获取请求信息、重定向、错误处理
D22:indeterminate equation (indefinite equation, translation + problem solution)
Internship: unfamiliar annotations involved in the project code and their functions
Thinking about the best practice of dynamics 365 development collaboration
A Cooperative Approach to Particle Swarm Optimization
Bidding promotion process
Leetcode3. Implement strstr()
Remember that a version of @nestjs/typeorm^8.1.4 cannot be obtained Env option problem
2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
SPIR-V初窺
General operation method of spot Silver
Folio. Ink is a free, fast and easy-to-use image sharing tool
Unreal browser plug-in
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
Superfluid_ HQ hacked analysis
Unity VR resource flash surface in scene