Skip to content

Commit 5088eb0

Browse files
authored
update: 添加问题“1925.统计平方和三元组的数目”的代码和题解 (#1209)
* word: 2025.11.15 en+jp * word: 2025.11.16 en(+jp) * word: 2025.11.17 en(+jp) * word: 2025.11.18 en * word: 2025.11.19 en * word: 2025.11.20 en * word: 2025.11.21 en * word: 2025.11.22 en * word: 2025.11.23 en * word: 2025.11.24 (en) * word: 2025.11.25 en * word: 2025.11.26 (en) * word: 2025.11.27 en * word: 2025.11.28 en * word: 2025.11.29 en * word: 2025.11.30 en * word: 2025.12.01 en+jpp * word: 2025.12.02 en+jpp * word: 2025.12.03 (en+)jp * word: 2025.12.04 en * word: 2025.12.05 en * word: 2025.12.06 en * word: 2025.12.07 en * word: 2025.12.08 en * 1925: WA.cpp (#1204) * 1925: AC.cpp+WA.py (#1204) cpp - AC,64.52%,44.35% * 1925: AC.py+go+java (#1204) py - AC,51.53%,59.51% go - AC,55.56%,83.33% java - AC,65.28%,22.22% * 1925: CE.rust (#1204) - 无编译器检查 * 1925: CE.rust (#1204) - 无编译器检查 * 1925: AC.rust (#1204) - AC,37.50%,87.50% * update: 添加问题“1925.统计平方和三元组的数目”的代码和题解 (#1209) Signed-off-by: LetMeFly666 <[email protected]> --------- Signed-off-by: LetMeFly666 <[email protected]>
1 parent 5939cb7 commit 5088eb0

22 files changed

+598
-15
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shortest-way-to-form-string

AllProblems/_genInfoMap.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-12-08 21:36:58
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-12-08 22:10:16
6+
'''
7+
import os
8+
import json
9+
import tqdm
10+
os.chdir(os.path.dirname(os.path.abspath(__file__)))
11+
12+
13+
# titleSlug -> (num, name)
14+
# 如: two-sum -> (1, 1.两数之和)
15+
data = {}
16+
for file in tqdm.tqdm(os.listdir('.')):
17+
if not os.path.isdir(file):
18+
continue
19+
name = file
20+
num = name.split('.')[0]
21+
try:
22+
with open(os.path.join(file, 'titleSlug.txt'), 'r', encoding='utf-8') as f:
23+
titleSlug = f.read().strip()
24+
except:
25+
continue
26+
data[titleSlug] = (num, name)
27+
with open('_map_slug+num+name.json', 'w', encoding='utf-8') as f:
28+
json.dump(data, f, ensure_ascii=False)
29+
"""
30+
Run result:
31+
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4004/4004 [00:00<00:00, 4547.02it/s]
32+
"""

AllProblems/_map_slug+num+name.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-08 18:40:41
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-08 18:47:09
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int countTriples(int n) {
14+
int ans = 0;
15+
for (int a = 1; a <= n; a++) {
16+
for (int b = 1; b <= n; b++) {
17+
int k = a * a + b * b;
18+
int c = sqrt(k);
19+
ans += c * c == k && c <= n;
20+
// if (c * c == k) {
21+
// printf("(%d, %d, %d)\n", a, b, c);
22+
// }
23+
}
24+
}
25+
return ans;
26+
}
27+
};
28+
29+
#if defined(_WIN32) || defined(__APPLE__)
30+
int main() {
31+
Solution sol;
32+
cout << sol.countTriples(5) << endl;
33+
cout << sol.countTriples(12) << endl;
34+
return 0;
35+
}
36+
#endif
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-12-08 18:40:41
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-08 18:57:02
6+
*/
7+
package main
8+
9+
import "math"
10+
11+
func countTriples(n int) (ans int) {
12+
for a := 1; a <= n; a++ {
13+
for b := 1; b <= n; b++ {
14+
k := a * a + b * b
15+
c := int(math.Sqrt(float64(k)))
16+
if c <= n && c * c == k {
17+
ans++
18+
}
19+
}
20+
}
21+
return
22+
}
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-12-08 18:40:41
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-08 18:59:47
6+
*/
7+
class Solution {
8+
public int countTriples(int n) {
9+
int ans = 0;
10+
for (int a = 1; a <= n; a++) {
11+
for (int b = 1; b <= n; b++) {
12+
int k = a * a + b * b;
13+
int c = (int)Math.sqrt(k);
14+
if (c <= n && c * c == k) {
15+
ans++;
16+
}
17+
}
18+
}
19+
return ans;
20+
}
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-12-08 18:40:41
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-12-08 18:53:01
6+
'''
7+
from math import sqrt
8+
9+
class Solution:
10+
def countTriples(self, n: int) -> int:
11+
ans = 0
12+
for a in range(1, n + 1):
13+
for b in range(1, n + 1):
14+
k = a * a + b * b
15+
c = int(sqrt(k))
16+
ans += c <= n and c * c == k
17+
# if c <= n and c * c == k:
18+
# print(f"({a}, {b}, {c})")
19+
return ans
20+
21+
# a = Solution()
22+
# print(a.countTriples(5))
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-12-08 21:36:58
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-08 21:55:06
6+
*/
7+
impl Solution {
8+
pub fn count_triples(n: i32) -> i32 {
9+
let mut ans: i32 = 0;
10+
for a in 1..n+1 {
11+
for b in 1..n+1 {
12+
let k = a * a + b * b;
13+
let c = (k as f64).sqrt() as i32;
14+
if c <= n && c * c == k {
15+
ans += 1;
16+
}
17+
}
18+
}
19+
ans
20+
}
21+
}

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* @LastEditTime: 2025-11-01 22:18:35
66
*/
77
pub struct Solution;
8-
include!("3289-the-two-sneaky-numbers-of-digitville.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("1925-count-square-sum-triples.rs"); // 这个fileName是会被脚本替换掉的

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@
663663
|1911.最大子序列交替和|中等|<a href="https://leetcode.cn/problems/maximum-alternating-subsequence-sum/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/07/11/LeetCode%201911.%E6%9C%80%E5%A4%A7%E5%AD%90%E5%BA%8F%E5%88%97%E4%BA%A4%E6%9B%BF%E5%92%8C/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/131652316" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-alternating-subsequence-sum/solutions/2339029/letmefly-1911zui-da-zi-xu-lie-jiao-ti-he-fyzq/" target="_blank">LeetCode题解</a>|
664664
|1920.基于排列构建数组|简单|<a href="https://leetcode.cn/problems/build-array-from-permutation/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/05/06/LeetCode%201920.%E5%9F%BA%E4%BA%8E%E6%8E%92%E5%88%97%E6%9E%84%E5%BB%BA%E6%95%B0%E7%BB%84/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/147748208" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/build-array-from-permutation/solutions/3670248/letmefly-1920ji-yu-pai-lie-gou-jian-shu-p0pif/" target="_blank">LeetCode题解</a>|
665665
|1922.统计好数字的数目|中等|<a href="https://leetcode.cn/problems/count-good-numbers/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/04/14/LeetCode%201922.%E7%BB%9F%E8%AE%A1%E5%A5%BD%E6%95%B0%E5%AD%97%E7%9A%84%E6%95%B0%E7%9B%AE/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/147200001" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-good-numbers/solutions/3650327/letmefly-1922tong-ji-hao-shu-zi-de-shu-m-ev7k/" target="_blank">LeetCode题解</a>|
666+
|1925.统计平方和三元组的数目|简单|<a href="https://leetcode.cn/problems/count-square-sum-triples/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/12/08/LeetCode%201925.%E7%BB%9F%E8%AE%A1%E5%B9%B3%E6%96%B9%E5%92%8C%E4%B8%89%E5%85%83%E7%BB%84%E7%9A%84%E6%95%B0%E7%9B%AE/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/155717892" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-square-sum-triples/solutions/3852305/letmefly-1925tong-ji-ping-fang-he-san-yu-3int/" target="_blank">LeetCode题解</a>|
666667
|1928.规定时间内到达终点的最小花费|困难|<a href="https://leetcode.cn/problems/minimum-cost-to-reach-destination-in-time/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/03/LeetCode%201928.%E8%A7%84%E5%AE%9A%E6%97%B6%E9%97%B4%E5%86%85%E5%88%B0%E8%BE%BE%E7%BB%88%E7%82%B9%E7%9A%84%E6%9C%80%E5%B0%8F%E8%8A%B1%E8%B4%B9/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/142691241" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-cost-to-reach-destination-in-time/solutions/2937779/letmefly-1928gui-ding-shi-jian-nei-dao-d-h1rk/" target="_blank">LeetCode题解</a>|
667668
|1931.用三种不同颜色为网格涂色|困难|<a href="https://leetcode.cn/problems/painting-a-grid-with-three-different-colors/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/05/20/LeetCode%201931.%E7%94%A8%E4%B8%89%E7%A7%8D%E4%B8%8D%E5%90%8C%E9%A2%9C%E8%89%B2%E4%B8%BA%E7%BD%91%E6%A0%BC%E6%B6%82%E8%89%B2/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/148082436" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/painting-a-grid-with-three-different-colors/solutions/3681550/letmefly-1931yong-san-chong-bu-tong-yan-yenqo/" target="_blank">LeetCode题解</a>|
668669
|1935.可以输入的最大单词数|简单|<a href="https://leetcode.cn/problems/maximum-number-of-words-you-can-type/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/09/15/LeetCode%201935.%E5%8F%AF%E4%BB%A5%E8%BE%93%E5%85%A5%E7%9A%84%E6%9C%80%E5%A4%A7%E5%8D%95%E8%AF%8D%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/151727471" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-number-of-words-you-can-type/solutions/3782947/letmefly-1935ke-yi-shu-ru-de-zui-da-dan-jcu3r/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)