Problem Description
InputThe 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
Sample Input
Sample Output
Source#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef struct Point
{
double x,y;
}Point;
Point point[160];
int main()
{
int ans, t, i, j, k, n;
double a,b,c;
cin >> t;
while (t--)
{
cin >> n;
for (i=0; i<n; i++)
{
cin >> point[i].x >> point[i].y;
}
ans = 0;
for (i=0; i<n-2; i++)//利用三重循环每次计算三个点之间的关系
{
for (j=i+1; j<n-1; j++)
{
for (k=j+1; k<n; k++)
{
a = (point[i].x-point[j].x)*(point[i].x-point[j].x) + (point[i].y-point[j].y)*(point[i].y-point[j].y);//计算两点之间的距离
b = (point[i].x-point[k].x)*(point[i].x-point[k].x) + (point[i].y-point[k].y)*(point[i].y-point[k].y);
c = (point[k].x-point[j].x)*(point[k].x-point[j].x) + (point[k].y-point[j].y)*(point[k].y-point[j].y);
if (a+b>c && a+c>b && c+b>a) //三点都满足才是锐角三角形
{
ans++;
}
}
}
}
cout << ans << endl;
}
return 0;
}
原文:http://blog.csdn.net/whjkm/article/details/45897521