Skip to content

Add 0035 #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions md/0035.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ในข้อนี้ เรื่องจากเรามีจุดทั้งหมด $N \le 100$ จุด เราสามารถสร้างสามเหลี่ยมได้ทั้งหมด $\binom{N}{3}$ วิธี และการลองสร้างสามเหลี่ยมทุกวิธีนั้นใช้เวลาไม่นานเกินไป (ใช้เวลา $\mathcal O (N^3)$)

เราสร้างฟังก์ชั่นหาพื้นที่สามเหลี่ยมจากจุดสามจุดได้ โดยใช้สูตรที่ให้มาในโจทย์ และวนหาจุดสามจุดทุกรูปแบบโดยการใช้ for-loop สามชั้น สังเกตว่าเราสามารถวน index $i, j, k$ เฉพาะ $i < j < k$ ได้เนื่องจากการสลับที่ของ $i, j, k$ ไม่ส่งผลต่อพื้นที่

```cpp
#include<bits/stdc++.h>
using namespace std;

struct Point {
int x, y;
} points[100];

double triangle_area (Point a, Point b, Point c) {
return abs(a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x) / 2.0;
}

int main () {
int n; cin >> n;
for (int i = 0; i < n; i++) {
cin >> points[i].x >> points[i].y;
}

double max_area = 0;

for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
for (int k = j+1; k < n; k++) {
max_area = max(max_area, triangle_area(points[i], points[j], points[k]));
}
}
}

cout << fixed << setprecision(3) << max_area;

return 0;
}
```