Skip to content

Commit 0fa88cc

Browse files
committed
update: 添加问题“2643.一最多的行”的代码和题解(#830)
docs: en&jp words(2 days) codes: 美团笔试 - WA版本 美团笔试最后思路想出来了但是没实现出来 docs: 美团笔试 - 题解(Half版) backup: 防止脚本清除此行 |牛客-美团暑期2025-20250322-前两题和第三题的思路|<a href="https://blog.letmefly.xyz/2025/03/22/Nowcoder-MeiTuan-Summer2025-20250322/">本平台题解</a>|<a href="https://letmefly.blog.csdn.net/article/details/146448313">CSDN题解</a>| close: #829 Signed-off-by: LetMeFly666 <[email protected]>
1 parent fdf2e9a commit 0fa88cc

17 files changed

+1098
-6
lines changed

.commitmsg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
docs: en&jp words(2 days)
2+
3+
codes: 美团笔试 - WA版本
4+
美团笔试最后思路想出来了但是没实现出来
5+
6+
docs: 美团笔试 - 题解(Half版)
7+
8+
backup: 防止脚本清除此行
9+
|牛客-美团暑期2025-20250322-前两题和第三题的思路|<a href="https://blog.letmefly.xyz/2025/03/22/Nowcoder-MeiTuan-Summer2025-20250322/">本平台题解</a>|<a href="https://letmefly.blog.csdn.net/article/details/146448313">CSDN题解</a>|
10+
11+
close: #829
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-22 22:42:28
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-22 22:43:30
6+
*/
7+
#ifdef _WIN32
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
vector<int> rowAndMaximumOnes(vector<vector<int>>& mat) {
14+
int mx = 0, ans = 0;
15+
for (int i = 0; i < mat.size(); i++) {
16+
int cnt = 0;
17+
for (int j = 0; j < mat[i].size(); j++) {
18+
cnt += mat[i][j];
19+
}
20+
if (cnt > mx) {
21+
mx = cnt;
22+
ans = i;
23+
}
24+
}
25+
return {ans, mx};
26+
}
27+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-22 22:51:01
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-22 22:52:04
6+
*/
7+
package main
8+
9+
func rowAndMaximumOnes(mat [][]int) []int {
10+
ans, mx := 0, 0
11+
for i := range mat {
12+
cnt := 0
13+
for _, t := range mat[i] {
14+
cnt += t
15+
}
16+
if cnt > mx {
17+
ans, mx = i, cnt
18+
}
19+
}
20+
return []int{ans, mx}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-22 22:49:36
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-22 22:50:36
6+
*/
7+
class Solution {
8+
public int[] rowAndMaximumOnes(int[][] mat) {
9+
int ans = 0, mx = 0;
10+
for (int i = 0; i < mat.length; i++) {
11+
int cnt = 0;
12+
for (int j = 0; j < mat[i].length; j++) {
13+
cnt += mat[i][j];
14+
}
15+
if (cnt > mx) {
16+
mx = cnt;
17+
ans = i;
18+
}
19+
}
20+
return new int[]{ans, mx};
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-03-22 22:44:18
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-03-22 22:44:32
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]:
11+
mx, ans = 0, 0
12+
for i in range(len(mat)):
13+
cnt = sum(mat[i])
14+
if cnt > mx:
15+
mx, ans = cnt, i
16+
return [ans, mx]

Codes/MeiTuan-Summer2025-01.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-22 19:14:07
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-22 19:25:02
6+
*/
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
10+
inline bool isOk(char c) {
11+
static const string okList = "AHIMOTUVWXY";
12+
for (char ok : okList) {
13+
if (c == ok) {
14+
return true;
15+
}
16+
}
17+
return false;
18+
}
19+
20+
bool isOk(string s) {
21+
for (char c : s) {
22+
if (!isOk(c)) {
23+
return false;
24+
}
25+
}
26+
for (int i = 0; i < s.size() / 2; i++) {
27+
if (s[i] != s[s.size() - i - 1]) {
28+
return false;
29+
}
30+
}
31+
return true;
32+
}
33+
34+
int solve(string s) {
35+
int ans = 0;
36+
for (int i = 0; i < s.size(); i++) {
37+
for (int j = i + 1; j < s.size(); j++) { // 长度大于1
38+
bool thisIsOk = isOk(s.substr(i, j - i + 1));
39+
ans += thisIsOk;
40+
#ifdef _WIN32
41+
if (thisIsOk) {
42+
printf("i = %d, j = %d, s.substr(%d, %d) = %s : OK\n", i, j, i, j, s.substr(i, j).c_str());
43+
}
44+
#endif
45+
}
46+
}
47+
return ans;
48+
}
49+
50+
int main() {
51+
#ifdef _WIN32
52+
vector<string> S = {"AHHAMTT"};
53+
vector<int> ANS = {3};
54+
for (int i = 0; i < S.size(); i++) {
55+
int ans = solve(S[i]);
56+
cout << S[i] << ": " << ans << endl;
57+
assert(ans == ANS[i]);
58+
}
59+
#else
60+
string s;
61+
cin >> s;
62+
cout << solve(s) << endl;
63+
#endif
64+
return 0;
65+
}

Codes/MeiTuan-Summer2025-02.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-22 19:30:14
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-22 19:36:56
6+
*/
7+
// 诶,不是哥们,还没利用“排列中数各不相同的性质”呢,咋就84ms然后AC了
8+
#include <bits/stdc++.h>
9+
using namespace std;
10+
11+
int a[10010];
12+
13+
int solve(int n) {
14+
int ans = 0;
15+
for (int start = 0; start < n; start++) {
16+
int lt = 0, gt = 0;
17+
ans++;
18+
for (int i = 1; start - i >= 0 && start + i < n; i++) {
19+
if (a[start - i] > a[start]) {
20+
gt++;
21+
} else {
22+
lt++;
23+
}
24+
if (a[start + i] > a[start]) {
25+
gt++;
26+
} else {
27+
lt++;
28+
}
29+
ans += lt == gt;
30+
}
31+
}
32+
return ans;
33+
}
34+
35+
int main() {
36+
int T;
37+
scanf("%d", &T);
38+
while (T--) {
39+
int n;
40+
scanf("%d", &n);
41+
for (int i = 0; i < n; i++) {
42+
scanf("%d", &a[i]);
43+
}
44+
int ans = solve(n);
45+
printf("%d\n", ans);
46+
}
47+
return 0;
48+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-22 19:40:10
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-22 19:44:01
6+
*/
7+
#include <bits/stdc++.h>
8+
9+
using namespace std;
10+
11+
int n, k;
12+
13+
inline int update(int now) {
14+
if (now < 1) {
15+
return 1;
16+
}
17+
if (now > n) {
18+
return n;
19+
}
20+
return now;
21+
}
22+
23+
int main() {
24+
cin >> n >> k;
25+
string s;
26+
cin >> s;
27+
int l = k, r = k;
28+
// int ans = 0;
29+
for (char c : s) {
30+
if (c == 'L') {
31+
l = update(l - 1);
32+
r = update(r - 1);
33+
} else if (c == 'R') {
34+
l = update(l + 1);
35+
r = update(r + 1);
36+
} else {
37+
l = update(l - 1);
38+
r = update(r + 1);
39+
}
40+
// ans += l == 1 || r == n;
41+
if (l == 1 || r == n) {
42+
putchar('1');
43+
} else {
44+
putchar('0');
45+
}
46+
}
47+
// cout << ans << endl;
48+
puts("");
49+
return 0;
50+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-22 19:46:01
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-22 20:04:16
6+
*/
7+
#include <bits/stdc++.h>
8+
9+
using namespace std;
10+
11+
int n, k;
12+
13+
bool a[1000010], b[1000010];
14+
15+
int main() {
16+
cin >> n >> k;
17+
string s;
18+
cin >> s;
19+
a[k] = true;
20+
for (char c : s) {
21+
if (c == 'L' || c == '?') {
22+
for (int i = 2; i <= n; i++) {
23+
if (a[i]) {
24+
b[i - 1] = true;
25+
}
26+
}
27+
if (a[1]) {
28+
b[1] = true;
29+
}
30+
}
31+
if (c == 'R' || c == '?') {
32+
for (int i = 1; i < n; i++) {
33+
if (a[i]) {
34+
b[i + 1] = true;
35+
}
36+
}
37+
if (a[n]) {
38+
b[n] = true;
39+
}
40+
}
41+
swap(a, b);
42+
}
43+
for (int i = 1; i <= n; i++) {
44+
putchar(a[i] ? '1' : '0');
45+
}
46+
return 0;
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-03-22 20:05:24
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-03-22 20:05:24
6+
*/
7+
#include <bits/stdc++.h>
8+
9+
using namespace std;
10+
11+
int n, k;
12+
13+
bool a[1000010], b[1000010];
14+
15+
int main() {
16+
cin >> n >> k;
17+
string s;
18+
cin >> s;
19+
// a[k] = true;
20+
// for (char c : s) {
21+
// if (c == 'L' || c == '?') {
22+
// for (int i = 2; i <= n; i++) {
23+
// if (a[i]) {
24+
// b[i - 1] = true;
25+
// }
26+
// }
27+
// if (a[1]) {
28+
// b[1] = true;
29+
// }
30+
// }
31+
// if (c == 'R' || c == '?') {
32+
// for (int i = 1; i < n; i++) {
33+
// if (a[i]) {
34+
// b[i + 1] = true;
35+
// }
36+
// }
37+
// if (a[n]) {
38+
// b[n] = true;
39+
// }
40+
// }
41+
// swap(a, b);
42+
// }
43+
for (int i = 1; i <= n; i++) {
44+
putchar('1');
45+
}
46+
return 0;
47+
}

0 commit comments

Comments
 (0)