1 条题解
-
0
题意很简单,计算三角形的面积,以及判断点是否在三角形内,初高中数学计算题。 在题目已经给定三角形面积计算公式时,我们可以直接求出三角形的面积,很容易想到,只有当需要判断的点p在三角形内(或在三角形上),p于三角形三点进行链接所切割的新的三个三角形面积总和才和原三角形相同,若p在三角形外,则所得的新的三个三角形面积总和是大于原先三角形的。由此可判断该点p是否在三角形内(上)。
#include<bits/stdc++.h> //#pragma GCC optimize(2) #define int long long #define pii pair<int,int> #define endl '\n' using namespace std; const int mod1 = 1e9 + 7, mod2 = 998244353, inf = 1e18, N = 2e5 + 5; double tx[3], ty[3]; double sb(double x, double y) { double s1 = abs((x * (ty[1] - ty[2]) + tx[1] * (ty[2] - y) + tx[2] * (y - ty[1])) / 2.0); double s2 = abs((tx[0] * (y - ty[2]) + x * (ty[2] - ty[0]) + tx[2] * (ty[0] - y)) / 2.0); double s3 = abs((tx[0] * (ty[1] - y) + tx[1] * (y - ty[0]) + x * (ty[0] - ty[1])) / 2.0); return s1 + s2 + s3; } void solve() { for (int i = 0; i < 3; i++) { cin >> tx[i] >> ty[i]; } double S = abs((tx[0] * (ty[1] - ty[2]) + tx[1] * (ty[2] - ty[0]) + tx[2] * (ty[0] - ty[1])) / 2.0); int n; cin >> n; int ans = 0; for (int i = 0; i < n; i++) { double x, y; cin >> x >> y; double tag_s = abs(sb(x, y)); if (tag_s == S) { ans++; } } cout << S << endl << ans << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr),cout.tie(nullptr); int T = 1; // cin >> T; cout << fixed << setprecision(1); while(T--) { solve(); } return 0; }
- 1
信息
- ID
- 1076
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- 递交数
- 29
- 已通过
- 13
- 上传者