Skip to content

Commit 6cb55b4

Browse files
authored
Merge pull request #635 from LetMeFly666/3238
添加问题“3238.求出胜利玩家的数目”的代码和题解
2 parents 9e41c94 + afe1156 commit 6cb55b4

24 files changed

+1381
-158
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2024-11-22 20:51:14
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2024-11-22 21:22:17
6+
*/
7+
#ifdef _WIN32
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
#ifdef FirstTry // 在搞什么
12+
class Solution {
13+
public:
14+
int nonSpecialCount(int l, int r) {
15+
int ans = 0;
16+
for (int i = l; i <= r; i++) {
17+
int x = sqrt(i), y = sqrt(x);
18+
if (x * x == i && y * y != x) {
19+
ans++;
20+
}
21+
}
22+
return ans;
23+
}
24+
};
25+
#else // FirstTry
26+
#ifdef SecondTry // WA,3是质数但不是平方数
27+
class Solution {
28+
public:
29+
int nonSpecialCount(int l, int r) {
30+
int ans = r - l + 1;
31+
int from = sqrt(l), to = sqrt(r);
32+
if (from * from != l) {
33+
from++;
34+
}
35+
if (to * to != r) {
36+
to--;
37+
}
38+
for (int i = from; i <= to; i++) {
39+
int t = sqrt(i);
40+
ans -= t * t == i;
41+
// printf("i = %d, sqrt(%d) * sqrt(%d) = %d\n", i, i, i, sqrt(i) * sqrt(i)); //*****
42+
printf("i = %d, t = %d, %d * %d = %d\n", i, t, t, t, t * t); //*****
43+
}
44+
return ans;
45+
}
46+
};
47+
/*
48+
i = 2, t = 1, 1 * 1 = 1
49+
i = 3, t = 1, 1 * 1 = 1
50+
i = 4, t = 2, 2 * 2 = 4
51+
*/
52+
#else // SecondTry
53+
#ifdef ThirdTry // WHAT!!! 有点不在状态今天
54+
class Solution {
55+
private:
56+
int isPrime(int n) {
57+
// if (n == 1) {
58+
// return false;
59+
// }
60+
for (int i = 2; i <= sqrt(n); i++) {
61+
if (n % i == 0) {
62+
return false;
63+
}
64+
}
65+
return true;
66+
}
67+
public:
68+
int nonSpecialCount(int l, int r) {
69+
int ans = r - l + 1;
70+
int from = sqrt(l), to = sqrt(r);
71+
if (from * from != l) {
72+
from++;
73+
}
74+
for (int i = from; i < to; i++) {
75+
ans -= isPrime(i);
76+
// printf("isPrime(%d) = %d\n", i, isPrime(i));
77+
}
78+
return ans;
79+
}
80+
};
81+
#else // ThirdTry
82+
// FourthTry // Copy
83+
class Solution {
84+
public:
85+
int nonSpecialCount(int l, int r) {
86+
int n = sqrt(r);
87+
vector<int> v(n + 1);
88+
int res = r - l + 1;
89+
for (int i = 2; i <= n; i++) {
90+
if (v[i] == 0) {
91+
if (i * i >= l && i * i <= r) {
92+
res--;
93+
}
94+
for (int j = i * 2; j <= n; j += i) {
95+
v[j] = 1;
96+
}
97+
}
98+
}
99+
return res;
100+
}
101+
};
102+
#endif // ThirdTry
103+
#endif // SecondTry
104+
#endif // FirstTry
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2024-11-23 09:54:19
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2024-11-23 10:14:02
6+
*/
7+
#ifdef _WIN32
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
#ifdef FirstTry // WA - new出来的值是随机值
12+
class Solution {
13+
public:
14+
int winningPlayerCount(int n, vector<vector<int>>& pick) {
15+
// int* cnt = new int[n];
16+
// for (vector<int>& p : pick) {
17+
// cnt[p[0]]
18+
// }
19+
int (*cnt)[11] = new int[n][11];
20+
for (vector<int>& p : pick) {
21+
cnt[p[0]][p[1]]++;
22+
}
23+
int ans = 0;
24+
for (int i = 0; i < n; i++) {
25+
for (int j = 0; j <= 10; j++) {
26+
printf("cnt[%d][%d] = %d\n", i, j, cnt[i][j]); //**************
27+
if (cnt[i][j] > i) {
28+
ans++;
29+
break;
30+
}
31+
}
32+
}
33+
// delete []cnt;
34+
return ans;
35+
}
36+
};
37+
#else // FirstTry
38+
// SecondTry
39+
class Solution {
40+
public:
41+
int winningPlayerCount(int n, vector<vector<int>>& pick) {
42+
int cnt[10][11] = {0};
43+
for (vector<int>& p : pick) {
44+
cnt[p[0]][p[1]]++;
45+
}
46+
int ans = 0;
47+
for (int i = 0; i < n; i++) {
48+
for (int j = 0; j < 11; j++) {
49+
if (cnt[i][j] > i) {
50+
ans++;
51+
break;
52+
}
53+
}
54+
}
55+
return ans;
56+
}
57+
};
58+
#endif // FirstTry
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2024-11-23 10:18:49
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2024-11-23 10:22:10
6+
*/
7+
package main
8+
9+
func winningPlayerCount(n int, pick [][]int) (ans int) {
10+
cnt := make([][]int, n)
11+
for th := range cnt {
12+
cnt[th] = make([]int, 11)
13+
}
14+
for _, p := range pick {
15+
cnt[p[0]][p[1]]++
16+
}
17+
for i, row := range cnt {
18+
for _, val := range row {
19+
if val > i {
20+
ans++
21+
break
22+
}
23+
}
24+
}
25+
return
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2024-11-23 10:17:04
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2024-11-23 10:18:25
6+
*/
7+
class Solution {
8+
public int winningPlayerCount(int n, int[][] pick) {
9+
int cnt[][] = new int[n][11];
10+
for (int[] p : pick) {
11+
cnt[p[0]][p[1]]++;
12+
}
13+
int ans = 0;
14+
for (int i = 0; i < n; i++) {
15+
for (int j = 0; j < 11; j++) {
16+
if (cnt[i][j] > i) {
17+
ans++;
18+
break;
19+
}
20+
}
21+
}
22+
return ans;
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2024-11-23 10:14:35
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2024-11-23 10:16:22
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def winningPlayerCount(self, n: int, pick: List[List[int]]) -> int:
11+
cnt = [[0] * 11 for _ in range(n)]
12+
for a, b in pick:
13+
cnt[a][b] += 1
14+
return sum(any(cnt[i][j] > i for j in range(11)) for i in range(n))

KongMingQi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11

22
///////////////////////////////////////////////////
33
// 程序名称:黑神话 孔明棋
4-
// 编译环境:Mictosoft Visual Studio 2022, EasyX_20200315(beta)
4+
// 编译环境:MinGW, EasyX_20200315(beta)
55
// 作  者:luoyh <[email protected]>
66
// 公 众 号:C语言研究
77
// 版 本 号:Version 1.0.0
88
// 最后修改:2024-11-18
9+
// Modified By: LetMeFly.xyz
910
//
1011
#include<Let/graphics.h>
1112
#include<conio.h>

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: LetMeFly
33
* @Date: 2022-05-19 18:48:53
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2024-11-03 15:34:15
5+
* @LastEditTime: 2024-11-22 23:06:07
66
-->
77
# LetLeet Blog
88

@@ -720,6 +720,7 @@
720720
|3216.交换后字典序最小的字符串|简单|<a href="https://leetcode.cn/problems/lexicographically-smallest-string-after-a-swap/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/30/LeetCode%203216.%E4%BA%A4%E6%8D%A2%E5%90%8E%E5%AD%97%E5%85%B8%E5%BA%8F%E6%9C%80%E5%B0%8F%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/143362223" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/lexicographically-smallest-string-after-a-swap/solutions/2971048/letmefly-3216jiao-huan-hou-zi-dian-xu-zu-nxp9/" target="_blank">LeetCode题解</a>|
721721
|3222.求出硬币游戏的赢家|简单|<a href="https://leetcode.cn/problems/find-the-winning-player-in-coin-game/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/11/05/LeetCode%203222.%E6%B1%82%E5%87%BA%E7%A1%AC%E5%B8%81%E6%B8%B8%E6%88%8F%E7%9A%84%E8%B5%A2%E5%AE%B6/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/143501415" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-winning-player-in-coin-game/solutions/2977629/letmefly-3222qiu-chu-ying-bi-you-xi-de-y-08j3/" target="_blank">LeetCode题解</a>|
722722
|3226.使两个整数相等的位更改次数|简单|<a href="https://leetcode.cn/problems/number-of-bit-changes-to-make-two-integers-equal/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/11/02/LeetCode%203226.%E4%BD%BF%E4%B8%A4%E4%B8%AA%E6%95%B4%E6%95%B0%E7%9B%B8%E7%AD%89%E7%9A%84%E4%BD%8D%E6%9B%B4%E6%94%B9%E6%AC%A1%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/143448117" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/number-of-bit-changes-to-make-two-integers-equal/solutions/2974558/letmefly-3226shi-liang-ge-zheng-shu-xian-j01h/" target="_blank">LeetCode题解</a>|
723+
|3238.求出胜利玩家的数目|简单|<a href="https://leetcode.cn/problems/find-the-number-of-winning-players/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/11/23/LeetCode%203238.%E6%B1%82%E5%87%BA%E8%83%9C%E5%88%A9%E7%8E%A9%E5%AE%B6%E7%9A%84%E6%95%B0%E7%9B%AE/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/143995245" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-number-of-winning-players/solutions/2998145/letmefly-3238qiu-chu-sheng-li-wan-jia-de-izbg/" target="_blank">LeetCode题解</a>|
723724
|3239.最少翻转次数使二进制矩阵回文I|中等|<a href="https://leetcode.cn/problems/minimum-number-of-flips-to-make-binary-grid-palindromic-i/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/11/15/LeetCode%203239.%E6%9C%80%E5%B0%91%E7%BF%BB%E8%BD%AC%E6%AC%A1%E6%95%B0%E4%BD%BF%E4%BA%8C%E8%BF%9B%E5%88%B6%E7%9F%A9%E9%98%B5%E5%9B%9E%E6%96%87I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/143796015" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-number-of-flips-to-make-binary-grid-palindromic-i/solutions/2989430/letmefly-3239zui-shao-fan-zhuan-ci-shu-s-nf03/" target="_blank">LeetCode题解</a>|
724725
|3240.最少翻转次数使二进制矩阵回文II|中等|<a href="https://leetcode.cn/problems/minimum-number-of-flips-to-make-binary-grid-palindromic-ii/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/11/16/LeetCode%203240.%E6%9C%80%E5%B0%91%E7%BF%BB%E8%BD%AC%E6%AC%A1%E6%95%B0%E4%BD%BF%E4%BA%8C%E8%BF%9B%E5%88%B6%E7%9F%A9%E9%98%B5%E5%9B%9E%E6%96%87II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/143816332" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-number-of-flips-to-make-binary-grid-palindromic-ii/solutions/2990374/letmefly-3240zui-shao-fan-zhuan-ci-shu-s-qbh3/" target="_blank">LeetCode题解</a>|
725726
|3242.设计相邻元素求和服务|简单|<a href="https://leetcode.cn/problems/design-neighbor-sum-service/solutions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/11/11/LeetCode%203242.%E8%AE%BE%E8%AE%A1%E7%9B%B8%E9%82%BB%E5%85%83%E7%B4%A0%E6%B1%82%E5%92%8C%E6%9C%8D%E5%8A%A1/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/143698347" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/design-neighbor-sum-service/solutions/2985408/letmefly-3242she-ji-xiang-lin-yuan-su-qi-mc7m/" target="_blank">LeetCode题解</a>|
@@ -851,6 +852,7 @@
851852
|Python - Django - 合并两个django项目,将一个项目作为另一个项目的子项目|<a href="https://blog.letmefly.xyz/2023/04/19/Other-Python-Django-Merge2DjangoProject/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/130248202">CSDN博客</a>|
852853
|Python生成列表的简洁代码|<a href="https://blog.letmefly.xyz/2022/11/19/Other-Python-GenerateListWithShortCode/">本平台博客</a>||
853854
|Python - Jupyter - 远程连接Jupyter内核|<a href="https://blog.letmefly.xyz/2023/04/22/Other-Python-Jupyter-RemoteKoreConnection/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/130303588">CSDN博客</a>|
855+
|Python - 从0开始学Python|<a href="https://blog.letmefly.xyz/2024/11/22/Other-Python-LearnPythonFrom0/">本平台博客</a>||
854856
|不能函数重载的Python如何实现“伪重载”|<a href="https://blog.letmefly.xyz/2023/03/23/Other-Python-Overload/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/129738983">CSDN博客</a>|
855857
|Python - 记录一下pydebugger的BUG|<a href="https://blog.letmefly.xyz/2023/04/05/Other-Python-PydebuggerBUG">本平台博客</a>||
856858
|python - 下载自百度网盘的远古の - 知识点备忘录|<a href="https://blog.letmefly.xyz/2023/09/25/Other-Python-PythonNotesFromBaiduDisk-beiwanglu/">本平台博客</a>||

0 commit comments

Comments
 (0)