Description
Overpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sky. Suddenly, one of Overpower’s classmates ask him: “How many acute triangles whose inner angles are less than 90 degrees
(regarding stars as points) can be found? Assuming all the stars are in the same plane”. Please help him to solve this problem.
Input
The first line of the input contains an integer T (T≤10), indicating the number of test cases.
For each test case:
The first line contains one integer n (1≤n≤100), the number of stars.
The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicate the points, all the points are distinct.
Output
For each test case, output an integer indicating the total number of different acute triangles.
Sample Input
130 010 05 1000
Sample Output
1
找出几个锐角三角形;
符合条件的是c^2 < a ^2 + b ^2;
其中c是最长边的;
另外在long long int 要改变__int64,不然会过不去;
#include <iostream>
#include <cstdio>
#include <cmath>
#define N 1005
using namespace std;
struct node{
int x;
int y;
};
long long int fun(node a,node b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) *(a.y - b.y);
}
bool judge(node a,node b,node c) {
long long int k = fun (a, b);
long long int m = fun ( a, c);
long long int t = fun ( b, c);
long long int Max = max(max(k,m),t);
if (Max + Max - k - m- t > 0) // 这样就可以直接找出符合条件,不需要循环判断
return false;
else
return true;
}
int main() {
int n;
int m;
node a[N];
scanf("%d",&n);
int kase = 0;
while (n--) {
scanf("%d",&m);
for (int i= 0; i < m; i++)
scanf("%d%d",&a[i].x,&a[i].y);
for (int i = 0; i < m; i++)
for (int j = i+1; j < m; j++)
for (int k = j +1; k < m; k++) {
if (judge(a[i],a[j],a[k]))
++kase;
}
printf("%d\n",kase);
}
}
本文介绍了一种算法,用于解决给定平面上的星星坐标后,如何计算能构成的不同锐角三角形的数量。该算法通过三次循环遍历所有可能的组合,并利用点间距离平方的比较来判断三角形是否为锐角。

1247

被折叠的 条评论
为什么被折叠?



