题目链接:Star
...计算几何水题,直接暴力判断任意三个点是不是能组成三角形就可以了。
判断是锐角三角形的条件是 a^2+b^2>c^2(c=max(a, b, c)).
坑点在,说好的integer,如果不是double 型,就WA了哦~~~
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <math.h> #define eps 1e-9 using namespace std; struct Point{ int x, y; }p[210000]; double dis(Point a, Point b) { double disx = (a.x-b.x)*(a.x-b.x); double disy = (a.y-b.y)*(a.y-b.y); double ans = disx + disy; return ans; } int main() { int t; cin >> t; while(t--) { int n; cin >> n; for (int i=0; i<n; ++i) { cin >> p[i].x >> p[i].y; } int ans = 0; for (int i=0; i<n; ++i) { for (int j=i+1; j<n; ++j) { for (int k=j+1; k<n; ++k) { double num[3]; num[0] = dis(p[i], p[j]); num[1] = dis(p[i], p[k]); num[2] = dis(p[j], p[k]); sort(num, num+3); if (num[0] + num[1] + eps > num[2]) { ans++; } } } } cout << ans << endl; } return 0; }