Skip to content

Commit ceb6160

Browse files
committed
update(doc): 添加问题“812.最大三角形面积”的代码和题解+文章“MacOS clang使用bits/stdc++.h” (#1148)
cpp - AC,33.52%,100.00% py - AC,62.32%,81.16% py - AC,py-oneline,86.23%,45.65% Signed-off-by: LetMeFly666 <[email protected]>
1 parent 024fb42 commit ceb6160

12 files changed

+295
-4
lines changed

#include <iostream>.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include <iostream>

.commitmsg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
cpp - AC,76.25%,44.45%
1+
cpp - AC,33.52%,100.00%
2+
py - AC,62.32%,81.16%
3+
py - AC,py-oneline,86.23%,45.65%
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-09-27 12:53:08
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-09-27 15:17:57
6+
'''
7+
from typing import List
8+
from itertools import combinations
9+
10+
class Solution:
11+
def largestTriangleArea(self, points: List[List[int]]) -> float:
12+
return max(abs((p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0])) for p1, p2, p3 in combinations(points, 3)) / 2
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-27 12:53:08
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-09-27 15:10:05
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
private:
13+
inline int calc(vector<vector<int>>& points, int i, int j, int k) {
14+
int x1 = points[i][0], y1 = points[i][1];
15+
int x2 = points[j][0], y2 = points[j][1];
16+
int x3 = points[k][0], y3 = points[k][1];
17+
return abs((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1));
18+
}
19+
public:
20+
double largestTriangleArea(vector<vector<int>>& points) {
21+
int ans = 0;
22+
for (int i = 0; i < points.size(); i++) {
23+
for (int j = i + 1; j < points.size(); j++) {
24+
for (int k = j + 1; k < points.size(); k++) {
25+
ans = max(ans, calc(points, i, j, k));
26+
}
27+
}
28+
}
29+
return double(ans) / 2;
30+
}
31+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-09-27 12:53:08
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-09-27 15:15:55
6+
'''
7+
from typing import List
8+
from itertools import combinations
9+
10+
class Solution:
11+
def largestTriangleArea(self, points: List[List[int]]) -> float:
12+
ans = 0
13+
for p1, p2, p3 in combinations(points, 3):
14+
x1, y1 = p2[0] - p1[0], p2[1] - p1[1]
15+
x2, y2 = p3[0] - p1[0], p3[1] - p1[1]
16+
ans = max(ans, abs(x1 * y2 - y1 * x2)) # 记得abs
17+
return ans / 2

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: 2025-09-14 16:20:27
5+
* @LastEditTime: 2025-09-27 13:24:44
66
-->
77
# LetLeet Blog
88

@@ -89,6 +89,7 @@
8989
|Linux - 内存相关 - 减小Mysql的内存占用 or 查看内存使用情况|<a href="https://blog.letmefly.xyz/2023/02/20/Other-Linux-MysqlMemReduce/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/129120029">CSDN博客</a>|
9090
|Linux - SSH - SSH免密登录(假设已生成过rsa key pair)|<a href="https://blog.letmefly.xyz/2023/04/22/Other-Linux-SSHLoginWithoutPassword/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/130302379">CSDN博客</a>|
9191
|MacOS - 记录MacOS发烫的好几天 - 幕后黑手竟然是|<a href="https://blog.letmefly.xyz/2025/09/01/Other-MacOS-Logging_several_days_of_macOS_overheating/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/151087541">CSDN博客</a>|
92+
|MacOS - Clang使用bits/stdc++.h - 非官方(竞赛用) - 通用方法|<a href="https://blog.letmefly.xyz/2025/09/27/Other-MacOS-ClangUsingBits_stdcpp_h/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/152164818">CSDN博客</a>|
9293
|图论笔记 - 极简极入门级|<a href="https://blog.letmefly.xyz/2023/10/27/Other-Math-GraphTheory-Notes/">本平台博客</a>|无|
9394
|码蹄集需要频繁登录?如何做到“一劳永逸”——码蹄集只登录一次久久不掉线的教程|<a href="https://blog.letmefly.xyz/2022/08/30/Other-MatijiAutoLogin/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/126610331">CSDN博客</a>|
9495
|内网穿透:如何借助Cloudflare连接没有公网的电脑的远程桌面(RDP)-含详细原理配置说明介绍|<a href="https://blog.letmefly.xyz/2024/10/21/Other-Net_Traversal-How2UseCloudflareConnectingRDP(RemoteDesktopProtocol)WithoutPublicIP/">本平台博客</a>|<a href="https://letmefly.blog.csdn.net/article/details/143114828">CSDN博客</a>|
@@ -408,6 +409,7 @@
408409
|0808.分汤|中等|<a href="https://leetcode.cn/problems/soup-servings/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/11/21/LeetCode%200808.%E5%88%86%E6%B1%A4/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/127973526" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/soup-servings/solutions/1984305/letmefly-808fen-tang-hao-ti-by-tisfy-97in/" target="_blank">LeetCode题解</a>|
409410
|0809.情感丰富的文字|中等|<a href="https://leetcode.cn/problems/expressive-words/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/11/25/LeetCode%200809.%E6%83%85%E6%84%9F%E4%B8%B0%E5%AF%8C%E7%9A%84%E6%96%87%E5%AD%97/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/128035958" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/expressive-words/solutions/1990314/letmefly-809qing-gan-feng-fu-de-wen-zi-b-vjf5/" target="_blank">LeetCode题解</a>|
410411
|0811.子域名访问计数|中等|<a href="https://leetcode.cn/problems/subdomain-visit-count/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/10/05/LeetCode%200811.%E5%AD%90%E5%9F%9F%E5%90%8D%E8%AE%BF%E9%97%AE%E8%AE%A1%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/127176602" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/subdomain-visit-count/solution/letmefly-811zi-yu-ming-fang-wen-ji-shu-b-lwwq/" target="_blank">LeetCode题解</a>|
412+
|0812.最大三角形面积|简单|<a href="https://leetcode.cn/problems/largest-triangle-area/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/09/27/LeetCode%200812.%E6%9C%80%E5%A4%A7%E4%B8%89%E8%A7%92%E5%BD%A2%E9%9D%A2%E7%A7%AF/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/152167745" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/largest-triangle-area/solutions/3793427/letmefly-812zui-da-san-jiao-xing-mian-ji-t3xo/" target="_blank">LeetCode题解</a>|
411413
|0813.最大平均值和的分组|中等|<a href="https://leetcode.cn/problems/largest-sum-of-averages/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/11/28/LeetCode%200813.%E6%9C%80%E5%A4%A7%E5%B9%B3%E5%9D%87%E5%80%BC%E5%92%8C%E7%9A%84%E5%88%86%E7%BB%84/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/128087654" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/largest-sum-of-averages/solutions/1996296/letmefly-813zui-da-ping-jun-zhi-he-de-fe-2acr/" target="_blank">LeetCode题解</a>|
412414
|0814.二叉树剪枝|中等|<a href="https://leetcode.cn/problems/binary-tree-pruning/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/07/21/LeetCode%200814.%E4%BA%8C%E5%8F%89%E6%A0%91%E5%89%AA%E6%9E%9D/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/125918905" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/binary-tree-pruning/solution/letmefly-814er-cha-shu-jian-zhi-by-tisfy-jh8a/" target="_blank">LeetCode题解</a>|
413415
|0816.模糊坐标|中等|<a href="https://leetcode.cn/problems/ambiguous-coordinates/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/11/07/LeetCode%200816.%E6%A8%A1%E7%B3%8A%E5%9D%90%E6%A0%87/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/127727007" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/ambiguous-coordinates/solutions/1954035/letmefly-816mo-hu-zuo-biao-by-tisfy-s794/" target="_blank">LeetCode题解</a>|
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
title: 812.最大三角形面积:三角形面积公式考察(附三种公式)
3+
date: 2025-09-27 15:19:16
4+
tags: [题解, LeetCode, 简单, 几何, 数组, 数学]
5+
categories: [题解, LeetCode]
6+
---
7+
8+
# 【LetMeFly】812.最大三角形面积:三角形面积公式考察(附三种公式)
9+
10+
力扣题目链接:[https://leetcode.cn/problems/largest-triangle-area/](https://leetcode.cn/problems/largest-triangle-area/)
11+
12+
<p>给你一个由 <strong>X-Y</strong> 平面上的点组成的数组 <code>points</code> ,其中 <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> 。从其中取任意三个不同的点组成三角形,返回能组成的最大三角形的面积。与真实值误差在 <code>10<sup>-5</sup></code> 内的答案将会视为正确答案<strong>。</strong></p>
13+
14+
<p>&nbsp;</p>
15+
16+
<p><strong class="example">示例 1:</strong></p>
17+
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/04/04/1027.png" style="height: 369px; width: 450px;" />
18+
<pre>
19+
<strong>输入:</strong>points = [[0,0],[0,1],[1,0],[0,2],[2,0]]
20+
<strong>输出:</strong>2.00000
21+
<strong>解释:</strong>输入中的 5 个点如上图所示,红色的三角形面积最大。
22+
</pre>
23+
24+
<p><strong class="example">示例 2:</strong></p>
25+
26+
<pre>
27+
<strong>输入:</strong>points = [[1,0],[0,0],[0,1]]
28+
<strong>输出:</strong>0.50000
29+
</pre>
30+
31+
<p>&nbsp;</p>
32+
33+
<p><strong>提示:</strong></p>
34+
35+
<ul>
36+
<li><code>3 &lt;= points.length &lt;= 50</code></li>
37+
<li><code>-50 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 50</code></li>
38+
<li>给出的所有点 <strong>互不相同</strong></li>
39+
</ul>
40+
41+
42+
43+
## 解题方法:暴力
44+
45+
三角形面积公式怎么算,有这些方法:
46+
47+
假设二维平面三角形三个顶点的坐标 $A(x_1, y_1), B(x_2, y_2), C(x_3, y_3)$,
48+
49+
1. 行列式公式(Shoelace公式):$S = \frac{1}{2} | x_1(y_2 - y_3) + x_2(y_3 - y_1) + x_3(y_1 - y_2) |$
50+
51+
2. 向量叉积公式:设 $\vec{AB} = (x_2-x_1, y_2-y_1), \vec{AC} = (x_3-x_1, y_3-y_1)$,则
52+
$S = \frac{1}{2} | \vec{AB} \times \vec{AC} | = \frac{1}{2} | (x_2-x_1)(y_3-y_1) - (x_3-x_1)(y_2-y_1) |$
53+
54+
3. 海伦公式(已知三边长 $a,b,c$):$a = \sqrt{(x_2-x_3)^2 + (y_2-y_3)^2},\ b = \sqrt{(x_1-x_3)^2 + (y_1-y_3)^2},\ c = \sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}$
55+
$s = \frac{a+b+c}{2},\ S = \sqrt{s(s-a)(s-b)(s-c)}$
56+
57+
58+
+ 时间复杂度$O(len(points)^3)$
59+
+ 空间复杂度$O(1)$
60+
61+
### AC代码
62+
63+
#### C++
64+
65+
```cpp
66+
/*
67+
* @Author: LetMeFly
68+
* @Date: 2025-09-27 12:53:08
69+
* @LastEditors: LetMeFly.xyz
70+
* @LastEditTime: 2025-09-27 15:10:05
71+
*/
72+
class Solution {
73+
private:
74+
inline int calc(vector<vector<int>>& points, int i, int j, int k) {
75+
int x1 = points[i][0], y1 = points[i][1];
76+
int x2 = points[j][0], y2 = points[j][1];
77+
int x3 = points[k][0], y3 = points[k][1];
78+
return abs((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1));
79+
}
80+
public:
81+
double largestTriangleArea(vector<vector<int>>& points) {
82+
int ans = 0;
83+
for (int i = 0; i < points.size(); i++) {
84+
for (int j = i + 1; j < points.size(); j++) {
85+
for (int k = j + 1; k < points.size(); k++) {
86+
ans = max(ans, calc(points, i, j, k));
87+
}
88+
}
89+
}
90+
return double(ans) / 2;
91+
}
92+
};
93+
```
94+
95+
#### Python
96+
97+
```python
98+
'''
99+
Author: LetMeFly
100+
Date: 2025-09-27 12:53:08
101+
LastEditors: LetMeFly.xyz
102+
LastEditTime: 2025-09-27 15:15:55
103+
'''
104+
from typing import List
105+
from itertools import combinations
106+
107+
class Solution:
108+
def largestTriangleArea(self, points: List[List[int]]) -> float:
109+
ans = 0
110+
for p1, p2, p3 in combinations(points, 3):
111+
x1, y1 = p2[0] - p1[0], p2[1] - p1[1]
112+
x2, y2 = p3[0] - p1[0], p3[1] - p1[1]
113+
ans = max(ans, abs(x1 * y2 - y1 * x2)) # 记得abs
114+
return ans / 2
115+
```
116+
117+
#### Python一行版
118+
119+
```python
120+
'''
121+
Author: LetMeFly
122+
Date: 2025-09-27 12:53:08
123+
LastEditors: LetMeFly.xyz
124+
LastEditTime: 2025-09-27 15:17:57
125+
'''
126+
from typing import List
127+
from itertools import combinations
128+
129+
class Solution:
130+
def largestTriangleArea(self, points: List[List[int]]) -> float:
131+
return max(abs((p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0])) for p1, p2, p3 in combinations(points, 3)) / 2
132+
```
133+
134+
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/152167745)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2025/09/27/LeetCode%200812.%E6%9C%80%E5%A4%A7%E4%B8%89%E8%A7%92%E5%BD%A2%E9%9D%A2%E7%A7%AF/)哦~
135+
>
136+
> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode)

Solutions/Other-English-LearningNotes-SomeWords.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,11 @@ categories: [自用]
14671467
|waive|v. 放弃|
14681468
|porcelain|n. 瓷器|
14691469
|ventilate|v. 通风,使透气,公开表达|
1470+
|||
1471+
|mistress(对应master)|n. 主妇,女主人,女教师,情妇|
1472+
|industrialization|n. 工业化|
1473+
|panorama|n. 全景|
1474+
|axial|adj. 轴的|
14701475

14711476
+ 这个web要是能设计得可以闭眼(完全不睁眼)键盘控制背单词就好了。
14721477
+ 也许可以加个AI用最近词编故事功能(返回接口中支持标注所使用单词高亮?)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: MacOS - Clang使用bits/stdc++.h - 非官方(竞赛用) - 通用方法
3+
date: 2025-09-27 12:54:53
4+
tags: [其他, MacOS, C++]
5+
categories: [技术思考]
6+
---
7+
8+
# MacOS - Clang使用bits/stdc++.h - 非官方(竞赛用) - 通用方法
9+
10+
## 前言
11+
12+
Windows和MacOS双用户,Windows上cpp**打竞赛/刷题**时使用`bits/stdc++.h`确实方便,毕竟不是实际项目的开发。
13+
14+
但MacOS的默认clang不包含`bits/stdc++.h`头文件,检索、github多星仓库的方法都**不通用**,故写此文已记之。
15+
16+
并且每次mac更新了developer kit之后,之前手动添加的`bits/stdc++.h`头文件都会失效,需要重新添加。
17+
18+
## 原理
19+
20+
不论是编译过程中还是在IDE的语法检测过程中,(若无指定特殊参数)都是会去默认库文件路径下查找目标头文件。
21+
22+
而clang默认没有`bits/stdc++.h`这个头文件,所以没办法`#include <bits/stdc++.h>`
23+
24+
所以直接新建个这个文件,放到库文件目录下就好了。
25+
26+
## 方法
27+
28+
网上clang库文件的位置都是一个固定路径,不同版本的MacOS(如最近新出的MacOS26)路径也不同。
29+
30+
如何确定clang默认库文件的位置?两个方法吧
31+
32+
### 方法一:IDE中获取
33+
34+
如果你使用IDE(大概率),如VsCode,直接随便创建个cpp文件,如:
35+
36+
```cpp
37+
#include <iostream>
38+
```
39+
40+
然后鼠标在`iostream``Command+单击鼠标左键`就好。
41+
42+
这样VsCode就会打开`iostream`这个文件,这个文件所在路径就是clang库文件的默认路径。(如:`/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/`
43+
44+
### 方法二:使用clang命令
45+
46+
MacOS上打开`终端`,输入命令`clang -E -x c++ - -v < /dev/null`,可以看到输出中包含如下内容:
47+
48+
```
49+
#include "..." search starts here:
50+
#include <...> search starts here:
51+
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1
52+
/Library/Developer/CommandLineTools/usr/lib/clang/17/include
53+
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
54+
/Library/Developer/CommandLineTools/usr/include
55+
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
56+
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/SubFrameworks (framework directory)
57+
End of search list.
58+
```
59+
60+
看到没,`#include <...> search starts here:`,也就是说`#include <xxx>`的时候是从这些路径下开始搜索头文件的。
61+
62+
随便选一个(如第一个的`/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/`即可)。
63+
64+
### 最后的头文件添加
65+
66+
在上一步找到的库文件默认路径下新建文件夹`bits`,并将`stdc++.h`放入这个文件夹下就好了。
67+
68+
至于`stdc++.h`这个文件怎么来?可以在Windows上复制(maybe),也可以使用Github上的[这个](https://raw.githubusercontent.com/khaveesh/macOS-stdc.h/refs/heads/master/stdc%2B%2B.h)
69+
70+
## End
71+
72+
<center><font size="6px" face="Ink Free">The Real End, Thanks!</font></center>
73+
74+
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/152164818)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2025/09/27/Other-MacOS-ClangUsingBits_stdcpp_h/)~
75+
>
76+
> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode)

Solutions/Other-Server-From1Server2Another.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 服务器 - 从一台服务器切换至另一台服务器(损失数十条PV记录)
2+
title: 服务器 - 从一台服务器切换至另一台服务器(损失数十条PV记录为代价)
33
date: 2025-09-14 16:16:17
44
tags: [其他, 服务器, 域名, 运维]
55
categories: [技术思考]

0 commit comments

Comments
 (0)